Options
All
  • Public
  • Public/Protected
  • All
Menu

A class which represents a Date with a few added features.

  • Has extra properties around days and weeks of the year and weeks of the year and month.
  • Inherits global locale and responds to changes.
  • Can have a custom locale for any given instance.
  • Comparison functions between days.
  • Difference calculations between days.
  • Start of unit calculations.
  • End of unit calculations.
  • Add and subtract unit calculations.
  • Date formatting.

Hierarchy

Implements

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new Day(date: Date): Day
  • Creates a new Day instance based on the given date.

    Parameters

    • date: Date

    Returns Day

Properties

_dayIdentifier

_dayIdentifier: IdentifierInput = null

_dayOfWeek

_dayOfWeek: number = null

_dayOfYear

_dayOfYear: number = null

_fullWeekOfMonth

_fullWeekOfMonth: number = null

_fullWeekOfYear

_fullWeekOfYear: number = null

_lastDayOfMonth

_lastDayOfMonth: number = null

_lastFullWeekOfMonth

_lastFullWeekOfMonth: number = null

_lastFullWeekOfYear

_lastFullWeekOfYear: number = null

_lastWeekspanOfMonth

_lastWeekspanOfMonth: number = null

_lastWeekspanOfYear

_lastWeekspanOfYear: number = null

_monthIdentifier

_monthIdentifier: IdentifierInput = null

_quarter

_quarter: number = null

_quarterIdentifier

_quarterIdentifier: IdentifierInput = null

_timeIdentifier

_timeIdentifier: IdentifierInput = null

_week

_week: number = null

_weekIdentifier

_weekIdentifier: IdentifierInput = null

_weekOfMonth

_weekOfMonth: number = null

_weekOfYear

_weekOfYear: number = null

_weekspanOfMonth

_weekspanOfMonth: number = null

_weekspanOfYear

_weekspanOfYear: number = null

date

date: Date

The date that initialize the day. This should not be modified, and if it is it will result in unpredictable and incorrect behavior.

day

day: number

The day of the week, starting at 0 for Sunday.

dayOfMonth

dayOfMonth: number

The day of the month, starting at 1 for the 1st.

hour

hour: number

The hour of this timestamp (0 to 23).

millis

millis: number

The milliseconds of this timestamp (0 to 999).

minute

minute: number

The minutes of this timestamp (0 to 59).

month

month: number

The month of this timestamp, zero based (January).

seconds

seconds: number

The seconds of this timestamp (0 to 59).

time

time: number

The time since the unix epoch in milliseconds in UTC.

year

year: number

The year of this timestamp.

Accessors

dayIdentifier

dayIdentifier:

The identifier which stores in a simple form the date of this Day.

dayOfWeek

dayOfWeek:

The day of the week relative to the first day of the week specified by Locale.weekStartsOn. So if the week starts on Monday, then this will be 0 for Monday, 1 for Tuesday, etc.

This is dependent on the locale of the instance (or global locale).

dayOfYear

dayOfYear:

The day of the year, starting at 1 for the 1st of January.

fullWeekOfMonth

fullWeekOfMonth:

The full week of the month, starting at 0 for a partial week (if one exists) and 1 for the first full week.

This is dependent on the locale of the instance (or global locale).

fullWeekOfYear

fullWeekOfYear:

The full week of the year, starting at 0 for a partial week (if one exists) and 1 for the first full week.

This is dependent on the locale of the instance (or global locale).

lastDayOfMonth

lastDayOfMonth:

The last day of the month, starting at 1 for the last day, 2 for the 2nd to last, etc.

lastFullWeekOfMonth

lastFullWeekOfMonth:

The last full week of the month, starting at 0 for the last week ending before Thursday and 1 for the last week with a Thursday.

This is dependent on the locale of the instance (or global locale).

lastFullWeekOfYear

lastFullWeekOfYear:

The last full week of the year, starting at 0 for the last week ending before Thursday and 1 for the last week with a Thursday.

This is dependent on the locale of the instance (or global locale).

lastWeekspanOfMonth

lastWeekspanOfMonth:

The last weekspan of the month, starting at 0 representing 31st to 25th for a month with 31 days. Weekspans allow you to create schedules for things like "the last saturday of the month".

lastWeekspanOfYear

lastWeekspanOfYear:

The last weekspan of the year, starting at 0 representing December 31st to December 25th. Weekspans allow you to create schedules for things like "the last saturday of the year".

monthIdentifier

monthIdentifier:

The identifier which stores in a simple form the month and year of this Day.

quarter

quarter:

The quarter of the year this day is in, starting at 0 for January through March.

quarterIdentifier

quarterIdentifier:

The identifier which stores in a simple form the quarter and year of this Day.

timeIdentifier

timeIdentifier:

The identifier which stores in a simple form the date and time of this Day.

week

week:

The week of the year. The first week of the year (1) contains Jan 1st.

This is dependent on the locale of the instance (or global locale).

weekIdentifier

weekIdentifier:

The identifier which stores in a simple form the week of the year of this Day.

weekOfMonth

weekOfMonth:

The week of the month. The first week of the month (1) is the first week which has the date Locale.firstWeekContainsDate. If there is a week before that it will be 0.

This is dependent on the locale of the instance (or global locale).

weekOfYear

weekOfYear:

The week of the year. The first week of the year (1) is the first week which has the date Locale.firstWeekContainsDate. If there is a week before that it will be 0. Frequently referred to as the ISO week.

This is dependent on the locale of the instance (or global locale).

weekspanOfMonth

weekspanOfMonth:

The weekspan of the month, starting at 0 representing the 1st to the 7th. Weekspans allow you to create schedules for things like "the first saturday of the month".

weekspanOfYear

weekspanOfYear:

The weekspan of the year, starting at 0 representing January 1st to the 7th. Weekspans allow you to create schedules for things like "the first saturday of the year".

Methods

add

  • add(unit: Unit, amount?: number): Day
  • Parameters

    • unit: Unit
    • Default value amount: number = 1

    Returns Day

asTime

between

  • between(day: Day, unit: Unit, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • unit: Unit
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

clearLocale

  • clearLocale(): void
  • Sets the locale of this Day instance to the global locale.

    Returns void

compare

  • compare(day: Day, precision?: Unit): number

daysBetween

  • daysBetween(day: Day, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

daysInMonth

  • daysInMonth(): number

daysInYear

  • daysInYear(): number

endOf

  • endOf(unit: Unit, inclusive?: boolean): Day
  • Parameters

    • unit: Unit
    • Default value inclusive: boolean = true

    Returns Day

format

  • format(format: string, cache?: boolean): string
  • Parameters

    • format: string
    • Default value cache: boolean = false

    Returns string

getLocale

  • Returns the current locale of the day instance.

    Returns Locale

hoursBetween

  • hoursBetween(day: Day, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

isAfter

  • isAfter(day: Day, precision?: Unit): boolean

isBefore

  • isBefore(day: Day, precision?: Unit): boolean

isBetween

  • isBetween(start: Day, end: Day, inclusive?: boolean, precision?: Unit): boolean
  • Parameters

    • start: Day
    • end: Day
    • Default value inclusive: boolean = true
    • Optional precision: Unit

    Returns boolean

isDST

  • isDST(): boolean

isEndOf

  • isEndOf(unit: Unit, inclusive?: boolean): boolean
  • Parameters

    • unit: Unit
    • Default value inclusive: boolean = true

    Returns boolean

isLeapYear

  • isLeapYear(): boolean

isSameOrAfter

  • isSameOrAfter(day: Day, precision?: Unit): boolean

isSameOrBefore

  • isSameOrBefore(day: Day, precision?: Unit): boolean

isStartOf

  • isStartOf(unit: Unit): boolean

max

millisBetween

  • millisBetween(day: Day, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

min

minutesBetween

  • minutesBetween(day: Day, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

monthsBetween

  • monthsBetween(day: Day, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

mutate

  • mutate(mutator: function): Day
  • Parameters

    • mutator: function
        • (date: Date): any
        • Parameters

          • date: Date

          Returns any

    Returns Day

next

  • next(days?: number): Day
  • Parameters

    • Default value days: number = 1

    Returns Day

offset

  • offset(): number

prev

  • prev(days?: number): Day
  • Parameters

    • Default value days: number = 1

    Returns Day

relative

  • relative(millis: number): Day

resetLocaleCache

  • resetLocaleCache(): void
  • Resets all locale-based caches on this Day instance.

    Returns void

sameDay

  • sameDay(day: Day): boolean
  • Determines whether this day and the given day lie on the same day.

    Parameters

    Returns boolean

sameHour

  • sameHour(day: Day): boolean
  • Determines whether this week and the given day lie on the same year.

    Parameters

    Returns boolean

sameMinute

  • sameMinute(day: Day): boolean
  • Determines whether

    Parameters

    Returns boolean

sameMonth

  • sameMonth(day: Day): boolean
  • Determines whether this day and the given day lie on the same month.

    Parameters

    Returns boolean

sameQuarter

  • sameQuarter(day: Day): boolean
  • Determines whether this day and the given day lie on the same month.

    Parameters

    Returns boolean

sameTime

  • sameTime(time: Time): boolean

sameWeek

  • sameWeek(day: Day): boolean
  • Determines whether this day and the given day lie on the same week.

    Parameters

    Returns boolean

sameYear

  • sameYear(day: Day): boolean
  • Determines whether this week and the given day lie on the same year.

    Parameters

    Returns boolean

secondsBetween

  • secondsBetween(day: Day, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

setLocale

  • setLocale(key: string): this
  • Sets the locale for this Day and returns this.

    Parameters

    • key: string

      The code to the locale to apply.

    Returns this

startOf

toArray

  • toArray(): number[]

toDate

  • toDate(): Date

toISOString

  • toISOString(keepOffset?: boolean): string
  • Parameters

    • Default value keepOffset: boolean = false

    Returns string

toJSON

  • toJSON(): string

toObject

  • toObject(): object

toString

  • toString(): string

utc

  • utc(keepLocalTime?: boolean): Day
  • Parameters

    • Optional keepLocalTime: boolean

    Returns Day

weeksBetween

  • weeksBetween(day: Day, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

weeksInYear

  • weeksInYear(): number

withDay

  • withDay(day: number): Day

withDayOfMonth

  • withDayOfMonth(day: number): Day

withDayOfWeek

  • withDayOfWeek(dayOfWeek: number): Day

withDayOfYear

  • withDayOfYear(dayOfYear: number): Day

withFullWeekOfMonth

  • withFullWeekOfMonth(week: number): Day

withFullWeekOfYear

  • withFullWeekOfYear(week: number): Day

withHour

  • withHour(hour: number): Day

withMonth

  • withMonth(month: number): Day

withTime

withTimes

  • withTimes(hour?: number, minute?: number, second?: number, millisecond?: number): Day
  • Parameters

    • Default value hour: number = Constants.HOUR_MIN
    • Default value minute: number = Constants.MINUTE_MIN
    • Default value second: number = Constants.SECOND_MIN
    • Default value millisecond: number = Constants.MILLIS_MIN

    Returns Day

Protected withWeek

  • withWeek(week: number, relativeWeek: number): Day
  • Parameters

    • week: number
    • relativeWeek: number

    Returns Day

withWeekOfMonth

  • withWeekOfMonth(week: number): Day

withWeekOfYear

  • withWeekOfYear(week: number): Day

withWeekspanOfMonth

  • withWeekspanOfMonth(week: number): Day

withWeekspanOfYear

  • withWeekspanOfYear(week: number): Day

withYear

  • withYear(year: number): Day

yearsBetween

  • yearsBetween(day: Day, op?: Op, absolute?: boolean): number
  • Parameters

    • day: Day
    • Default value op: Op = Op.DOWN
    • Default value absolute: boolean = true

    Returns number

Static build

  • build(year: number, month: number, date?: number, hour?: number, minute?: number, second?: number, millisecond?: number): Day
  • Parameters

    • year: number
    • month: number
    • Default value date: number = Constants.DAY_MIN
    • Default value hour: number = Constants.HOUR_MIN
    • Default value minute: number = Constants.MINUTE_MIN
    • Default value second: number = Constants.SECOND_MIN
    • Default value millisecond: number = Constants.MILLIS_MIN

    Returns Day

Static fromArray

  • fromArray(input: number[]): Day

Static fromDate

  • fromDate(date: Date): Day | null

Static fromDayIdentifier

  • fromDayIdentifier(id: number): Day

Static fromFormat

  • fromFormat(input: string, formats: string | string[]): Day
  • Parameters

    • input: string
    • formats: string | string[]

    Returns Day

Static fromObject

  • fromObject(input: object): Day

Static fromString

  • fromString(input: string): Day

Static now

Static parse

Static today

Static tomorrow

  • tomorrow(): Day

Static unix

  • unix(millis: number): Day

Static unixSeconds

  • unixSeconds(seconds: number): Day

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc