Options
All
  • Public
  • Public/Protected
  • All
Menu

General calendar utilities. Dates are represented with Date objects constrained to 00:00:00.000 UTC. Consistent use of UTC avoids issues with timezones and possible differing behavior.

Index

Type aliases

CalendarLength

CalendarLength: CalendarInterval & { totalDays: Integer }

Measured length of time. This incorporates a {@link CalenderInterval} and adds a measured {@link CalendarLength.totalDays} that measures the exact number of days.

Variables

Const ANNUAL_PAYMENT_PERIODS

ANNUAL_PAYMENT_PERIODS: {[ k in CalendarUnit]: number } = ...

For each CalendarUnit, the number of occurrances of that unit per year.

Const MONTH_LEMGTH

MONTH_LEMGTH: number[][] = ...

The length of each month, 0-origin, for non-leap and leap years.

Const MONTH_START

MONTH_START: number[][] = ...

The starting day of each month, 0-origin, for non-leap and leap years.

Functions

UTC

asCalendarInterval

asCalendarLength

asCalendarUnit

asDate

  • asDate(a: any): Date

Const day

  • day(date: Date): Date

Const decodeCalendarInterval

Const fmt_date

  • fmt_date(date: string | Date): string

Const fmt_datetime

  • fmt_datetime(date: Date): string

Const fmt_month

  • fmt_month(date: string | Date): string

Const fmt_time

  • fmt_time(date: string | Date): string

incrementDate

Const isCalendarInterval

Const isCalendarLength

Const isCalendarUnit

Const isDate

  • isDate(d: any): d is Date

isLeapYear

  • isLeapYear(year: Relaxed<Year>): boolean
  • isLeapYear(year: Date): boolean

Const parseDate

  • parseDate(date: string): Date
  • Parse a UTC date, in one of the following forms:

    • 2021-08-13
    • 2021-08 // Same as 2021-08-01
    • 2021 // Same as 2021-01-01

    Leading zeros on month and day are optional. Two-year year abbreviations are not allowed.

    Parameters

    • date: string

      A string in the form YYYY-MMM-dd

    Returns Date

    a Date at 00:00:00.000 UTC.

toCalendarInterval

toCalendarLength

toCalendarUnit

toDate

  • toDate(a: any): Date

Const truncateDate

  • Rolls back time to the start of a year, quarter, month, or day. Higher-order function that returns a function for the specific time period to truncate to.

    Parameters

    • unit: CalendarUnit

      Unit of time to truncate to (must not be 'week').

    Returns (date: Date) => Date

    (date: {@link Date}) => {@link Date}

      • (date: Date): Date
      • Parameters

        • date: Date

        Returns Date

Generated using TypeDoc