Class DateInterval

DateInterval class

Represents a date interval.

Commonly created via DateTime.diff

Hierarchy

  • DateInterval

Constructors

Properties

_end?: DateTime
_start?: DateTime
days: number = 0

Number of days

hours: number = 0

Number of hours

invert: boolean = false

True if it represents a negative period

microSeconds: number = 0

Number of microseconds.

minutes: number = 0

Number of minutes

months: number = 0

NUmber of months

seconds: number = 0

Number of seconds

years: number = 0

Number of years

converters: {
    [key: string]: ((dateInterval) => string);
} = ...

Type declaration

  • [key: string]: ((dateInterval) => string)
      • (dateInterval): string
      • Parameters

        Returns string

Methods

  • Compare with given interval

    Returns:

    • -1 if this date is before the given date
    • 0 if dates are equal
    • 1 if this date is after the given date

    Parameters

    Returns number

    number

  • Format the interval to a string.

    You can use the following characters. You can escape a character with a \ to output it as given:

    Y Years, numeric, at least 2 digits with leading 0, eg. 01, 03 y Years, numeric 1, 3 M Months, numeric, at least 2 digits with leading 0, eg. 01, 03, 12 m Months, numeric, eg. 1, 3, 12 D Days, numeric, at least 2 digits with leading 0, eg. 01, 03, 31 d Days, numeric, eg. 1, 3, 31 a Total number of days as a result of a DateTime.diff or (unknown) otherwise, eg. 4, 18, 8123 H Hours, numeric, at least 2 digits with leading 0, eg. 01, 03, 23 h Hours, numeric, eg. 1, 3, 23 I Minutes, numeric, at least 2 digits with leading 0, eg. 01, 03, 59 i Minutes, numeric, eg. 1, 3, 59 j The total number of minutes as a result of a DateTime.diff or (unknown) if this duration holds more than hours and minutes and seconds, eg. 4, 18, 8123 S Seconds, numeric, at least 2 digits with leading 0, eg. 01, 03, 57 s Seconds, numeric, eg. 1, 3, 57 F Microseconds, numeric, at least 6 digits with leading 0, eg. 007701, 052738, 428291 f Microseconds, numeric, eg. 7701, 52738, 428291 R Sign "-" when negative, "+" when positive, eg. -, + r Sign "-" when negative, empty when positive, eg. -,

    Parameters

    • format: string

    Returns string

  • Calculates total number of days that have elapsed between two dates.

    Only available if this diff was created using DateTime.diff

    Returns undefined | number

  • Calculates total number of minutes that have elapsed between two dates.

    Only available if this diff was created using DateTime.diff

    Returns undefined | number

  • Create date by given format. See DateInterval.format.

    Does not support "a". "j" can only be used alone.

    Parameters

    • dateStr: string
    • format: string = "h:I"

    Returns undefined | DateInterval

    Example

    const dateInterval = DateInterval.createFromFormat("21:09", "h:I"));

    const dateInterval = DateInterval.createFromFormat("315", "j"));

Generated using TypeDoc