Interface DateRange

package

DateRange

dependency

date

description

Date Ranges define a range of time. They can enumerate over specific points within that range, and be manipulated and compared.

Index

Properties

Methods

Properties

public end: Date

public start: Date

Methods

public contains(d: Date): boolean

Returns true if is contained inside the DateRange. may be a date or another DateRange.

example

Date.range('2003', '2005').contains(Date.create('2004')) -> true

Parameters

  • d: Date

    Date to check if it is contained within this DateRange.

Returns

boolean

True if is contained within the DateRange, false otherwise.

public contains(d: DateRange): boolean

see

contains

Parameters

Returns

boolean

public duration(): number

Return the duration of the DateRange in milliseconds.

example

Date.range('2003', '2005').duration() -> 94694400000

Returns

number

Duration of the DateRange in milliseconds.

public eachDay(fn?: (d: Date) => void): Array<Date>

see

eachMillisecond

Parameters

  • fn?: (d: Date) => void optional

Returns

Array<Date>

public eachHour(fn?: (d: Date) => void): Array<Date>

see

eachMillisecond

Parameters

  • fn?: (d: Date) => void optional

Returns

Array<Date>

public eachMillisecond(fn?: (d: Date) => void): Array<Date>

Increments through the date range for each [unit], calling [fn] if it is passed. Returns an array of each increment visited.

method

eachUnit

set

eachMillisecond eachSecond eachMinute eachHour eachDay eachWeek eachMonth eachYear

example

Date.range('2003-01', '2003-02').eachMonth() -> [...] Date.range('2003-01-15', '2003-01-16').eachDay() -> [...]

Parameters

  • fn?: (d: Date) => void optional

    Callback function for each date in the requested increments.

Returns

Array<Date>

Array of Dates for each increment.

public eachMinute(fn?: (d: Date) => void): Array<Date>

see

eachMillisecond

Parameters

  • fn?: (d: Date) => void optional

Returns

Array<Date>

public eachMonth(fn?: (d: Date) => void): Array<Date>

see

eachMillisecond

Parameters

  • fn?: (d: Date) => void optional

Returns

Array<Date>

public eachSecond(fn?: (d: Date) => void): Array<Date>

see

eachMillisecond

Parameters

  • fn?: (d: Date) => void optional

Returns

Array<Date>

public eachWeek(fn?: (d: Date) => void): Array<Date>

see

eachMillisecond

Parameters

  • fn?: (d: Date) => void optional

Returns

Array<Date>

public eachYear(fn?: (d: Date) => void): Array<Date>

see

eachMillisecond

Parameters

  • fn?: (d: Date) => void optional

Returns

Array<Date>

public every(ms: number, fn?: (d: Date) => void): Array<Date>

Iterates through the DateRange for every , calling [fn] if it is passed. Returns an array of each increment visited.

method

every(, [fn])

extra

When is a number, increments will be to the exact millisecond. can also be a string in the format %{number} {unit}s%, in which case it will increment in the unit specified. Note that a discrepancy exists in the case of months, as %(2).months()% is an approximation. Stepping through the actual months by passing %"2 months"% is usually preferable in this case.

example

Date.range('2003-01', '2003-03').every("2 months") -> [...]

Parameters

  • ms: number

    Time span to increment by.

  • fn?: (d: Date) => void optional

    Callback for each incremented date.

Returns

Array<Date>

An array of each incremented date visited.

public every(increment: string, fn?: (d: Date) => void): Array<Date>

see

every

Parameters

  • increment: string

    Time span to increment by.

  • fn?: (d: Date) => void optional

Returns

Array<Date>

public intersect(range: DateRange): DateRange

Returns a new DateRange with the latest starting point as its start, and the earliest ending point as its end. If the two ranges do not intersect this will effectively produce an invalid range.

example

Date.range('2003-01', '2005-01').intersect(Date.range('2004-01', '2006-01')) -> Jan 1, 2004..Jan 1, 2005

Parameters

  • range: DateRange

    DateRange to intersect with.

Returns

DateRange

DateRange

public isValid(): boolean

Returns true if the DateRange is valid, false otherwise.

example

Date.range('2003', '2005').isValid() -> true Date.range('2005', '2003').isValid() -> false

Returns

boolean

True if the date range is valid, false otherwise.

public toString(): string

Returns a string representation of the DateRange.

example

Date.range('2003', '2005').toString() -> January 1, 2003..January 1, 2005

Returns

string

String representation of the DateRange.

public union(range: DateRange): DateRange

Returns a new DateRange with the earliest starting point as its start, and the latest ending point as its end. If the two ranges do not intersect this will effectively remove the "gap" between them.

example

Date.range('2003=01', '2005-01').union(Date.range('2004-01', '2006-01')) -> Jan 1, 2003..Jan 1, 2006

Parameters

  • range: DateRange

    DateRange to create a union with.

Returns

DateRange

DateRange