1.0.1 • Published 4 years ago

@orioro/expression-date v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

expressionDate

Set of expressions aimed at solving common date-related operations: parse, format, compare, validate, manipulate (e.g. move forward, move back). Most (if not all) operations are based on and built with Luxon DateTime. If not stated otherwise, date operations return a string in ISO 8601 format (2021-01-27T20:38:12.807Z).

npm install @orioro/expression-date
yarn add @orioro/expression-date

API Docs

DateValue

Date input for all $date expressions

DateFormat

Arguments to be forwarded to Luxon corresponding DateTime parser. If a string, will be considered as the name of the format. If an Array, will be considered as a tuple consisting of format, formatOptions. Recognized formats (exported as constants DATE_{FORMAT_IN_CONSTANT_CASE}):

  • ISO
  • ISODate
  • ISOWeekDate
  • ISOTime
  • RFC2822
  • HTTP
  • SQL
  • SQLTime
  • SQLTime
  • UnixEpochMs
  • UnixEpochS
  • JSDate
  • PlainObject
  • LuxonDateTime
ISODate

String in the full ISO 8601 format: 2017-04-20T11:32:00.000-04:00

Duration

Duration represented in an object format:

  • duration {Object}
    • years {Number}
    • quarters {Number}
    • months {Number}
    • weeks {Number}
    • days {Number}
    • hours {Number}
    • minutes {Number}
    • seconds {Number}
    • milliseconds {Number}
$date(parseFmtArgs, serializeFormat, date)

Parses a date from a given input format and serializes it into another format. Use this expression to convert date formats into your requirements. E.g. UnixEpochMs into ISO.

  • parseFmtArgs {DateFormat}
  • serializeFormat {DateFormat}
  • date {String | Number | Object | Date}
  • Returns: date {String | Number | Object | Date} Output will vary according to serializeFormat
$dateNow(serializeFormat)

Generates a ISO date string from Date.now

  • serializeFormat {DateFormat}
  • Returns: date {String | Number | Object | Date}
$dateIsValid()

Verifies whether the given date is valid. From Luxon docs:

The most common way to do that is to over- or underflow some unit:

  • {*}
  • Returns: isValid {Boolean}
$dateStartOf(unitExp, date)

Returns the date at the start of the given unit (e.g. day, month).

$dateEndOf(unitExp, date)

Returns the date at the end of the given unit (e.g. day, month).

$dateSet(valuesExp, dateExp)

Modifies date specific units and returns resulting date. See DateTime#set and DateTime.fromObject

  • valuesExp {Object}
    • year {Number}
    • month {Number}
    • day {Number}
    • ordinal {Number}
    • weekYear {Number}
    • weekNumber {Number}
    • weekday {Number}
    • hour {Number}
    • minute {Number}
    • second {Number}
    • millisecond {Number}
  • dateExp {[ISODate](#isodate)}
  • Returns: date {[ISODate](#isodate)}
$dateSetConfig(configExp, date)

Modifies a configurations of the date.

$dateGt(referenceDateExp, date)

Greater than date > reference

$dateGte(referenceDateExp, date)

Greater than or equal date >= reference

$dateLt(referenceDateExp, date)

Lesser than date < reference

$dateLte(referenceDateExp, date)

Lesser than or equal date <= reference

$dateEq(referenceDateExp, compareUnitExp, date)

date == reference Converts both date and reference and compares their specified compareUnit. By default compares millisecond unit so that checks whether are exactly the same millisecond in time, but could be used to compare other units, such as whether two dates are within the same day, month or year.

$dateMoveForward(duration, date)

Modifies the date by moving it forward the duration specified.

$dateMoveBackward(duration, date)

Modifies the date by moving it backward the duration specified.

ISODate
PlainObject