A Date that is definitely a Date

... that can be created from either a Date or a string that represents a Date, or a number that represents the time in ms. Every creation that the original JS Date offers is allowed.

Example

const sd        = SafeDate.create(new Date(), { name: 'NewSafeDate' });
const numericSd = SafeDate.create(1666945777309); // ~ 2022-10-28T08:29:37.309Z
const stringSd = SafeDate.create('2022-10-28T08:29:37.309Z');
const rangeSd = SafeDate.create('2022-10-28T08:31:00.914Z', {
min: '2022-10-14T00:00:00.000Z',
max: '2022-11-01T00:00:00.000Z',
});

// extract the Result:
if (sd.isSuccess()) {
console.log(sd.getValue()) // SafeDate { _value: 2022-11-12T19:07:11.939Z }
}

Fails

  • if not parsable to a valid Date
  • if the Date is not inside the interval (between the given intervals' Dates)

Hierarchy

Accessors

Methods

  • compares 2 Lists of ValueObjects / values on equality

    Returns

    true if the lists are equal

    Type Parameters

    • ValueType

    Parameters

    • a: ValueObject<ValueType>[]

      the list of ValueObjects to compare with

    • b: ValueObject<ValueType>[] | ValueType[]

      a list of ValueObjects / values for comparison

    Returns boolean

  • Returns

    the value if the validation was successful

    Fails

    if not parsable to a valid Date

    Fails

    if the Date is not inside the interval (between the given intervals' Dates)

    Fails

    if the given interval Dates are no valid (parsable) Dates

    Parameters

    • value: string | number | Date

      to be validated as a valid Date

    • Optional options: SafeDateOptions

      constraints the value has to fulfill

    Returns Result<Date>

Generated using TypeDoc