Options
All
  • Public
  • Public/Protected
  • All
Menu

A CalendarRange is a CalendarPeriod that is divided up by increments of time into a series of CalendarStep segments. These segments can be iterated over in a for loop:

for (const step in calendarRange) {
console.log(step.start, step.end, JSON.stringify(step.length));
}

Hierarchy

Index

Constructors

constructor

  • new CalendarRange(start: string | Date, end: string | Date, unit: CalendarUnit, n?: Integer): CalendarRange
  • new CalendarRange(start: string | Date, end: string | Date, interval: { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }): CalendarRange
  • Parameters

    Returns CalendarRange

  • Parameters

    • start: string | Date
    • end: string | Date
    • interval: { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }
      • biweekly: undefined | number
      • day: undefined | number
      • month: undefined | number
      • quarter: undefined | number
      • semiannually: undefined | number
      • semimonthly: undefined | number
      • week: undefined | number
      • year: undefined | number

    Returns CalendarRange

Properties

Readonly end

end: Date

The end date of the period, exclusive.

Readonly interval

The amount to increment the dates in the range.

Readonly n

The number of units of increment. Duplicates the information in interval for convenience and to avoid recomputing.

Readonly start

start: Date

The starting date of the period.

Readonly unit

The units of increment. Duplicates the information in interval for convenience and to avoid recomputing.

Accessors

length

Methods

[iterator]

asArray

  • Return all of the values from this generator as an array. You do not want to call this on an infinite generator (for obvious reasons); consider using IEnhancements.slice or IEnhancements.limit to limit the size before calling this.

    Returns CalendarStep[]

concat

  • concat<T, TReturn, TNext>(...gens: (Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">)[]): EnhancedGenerator<T, void | TReturn, TNext>
  • Concatenates generators (or iterators or iterables).

    Ensures that any supplied generators are terminated when this is terminated.

    Type parameters

    • T

    • TReturn

    • TNext

    Parameters

    • Rest ...gens: (Generator<T, TReturn, TNext> | Iterator<T, TReturn, TNext> | Iterable<T> | Enhancements<T, TReturn, TNext, "sync">)[]

      zero or more additional Genable to provide values.

    Returns EnhancedGenerator<T, void | TReturn, TNext>

every

  • every(p: (v: CalendarStep, idx: number) => boolean, thisArg?: any): boolean
  • Returns false and terminates this generator if the predicate is false for any of the generator's yielded values.

    If the generator terminates without having failed the predicate, true is returned.

    Parameters

    • p: (v: CalendarStep, idx: number) => boolean

      predicate to apply to each yielded value.

    • Optional thisArg: any

      Optional value to supply as context (this) for the predicate

    Returns boolean

filter

  • Return a new EnhancedGenerator that yields only the values that satisfy the predicate f.

    f receives the value and a sequential index.

    Parameters

    • f: (v: CalendarStep, idx: number) => boolean
    • Optional thisArg: any

      Optional context to be passed as this to the predicate.

    Returns EnhancedGenerator<CalendarStep, any, undefined>

flat

  • flat<D>(depth?: D): any
  • Flatten the values yielded by this generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.

    The return type is currently over-broad

    Type parameters

    • D: number = 1

    Parameters

    • Optional depth: D

      (default = 1)

    Returns any

flatMap

  • flatMap<D>(f: (v: CalendarStep, idx: number) => any, depth?: D): any
  • Flatten the values yielded by applying the function to the values yielded by the generator to level depth. Produces a generator that yields the individual values at each level in depth-first order. Any iterable (including Array) or iterator will be traversed and its values yielded.

    The return type is currently over-broad

    Type parameters

    • D: number = 1

    Parameters

    Returns any

forEach

  • forEach(f: (v: CalendarStep, idx: number) => void, thisArg?: any): void
  • Operate on each value produced by this generator. The function f is called with two values, the value yielded by this generator and a sequential index.

    Parameters

    • f: (v: CalendarStep, idx: number) => void
    • Optional thisArg: any

      Value to be supplied as context this for function f.

    Returns void

join

  • join(sep?: string): string
  • Trivial, but handy, same as Array.prototype.join.

    Parameters

    Returns string

limit

  • Limit the number of values that can be generated. A RangeError is thrown if this limit is exceeded. This is useful when you wish to abort an excessively large computation.

    Use with 0 as the first argument if you want to truncate.

    Parameters

    • max: number

    Returns EnhancedGenerator<CalendarStep, any, undefined>

map

  • Apply the function to each value yielded by this generator. It is called with two arguments, the value yielded, and a sequential index. The return value is a generator that yields the values produced by the function.

    Type parameters

    • V

    Parameters

    • f: (v: CalendarStep, idx: number) => V
    • Optional thisArg: any

      Optional value to be supplied as context this for function f.

    Returns EnhancedGenerator<V, any, undefined>

range

reduce

  • reduce<A, T, TReturn, TNext>(f: (acc: A | T, v: T) => A): A
  • reduce<A, T, TReturn, TNext>(f: (acc: A, v: T) => A, init: A): A
  • reduce<A>(f: (acc: A, v: CalendarStep) => A, init?: A): A
  • Like Array.prototype.reduce, but the 3rd argument to the reducing function ("array") is omitted because there is no array.

    Type parameters

    • A

    • T

    • TReturn

    • TNext

    Parameters

    • f: (acc: A | T, v: T) => A
        • (acc: A | T, v: T): A
        • Parameters

          • acc: A | T
          • v: T

          Returns A

    Returns A

  • Like Array.prototype.reduce, but the 3rd argument to the reducing function ("array") is omitted because there is no array.

    Type parameters

    • A

    • T

    • TReturn = T

    • TNext = T

    Parameters

    • f: (acc: A, v: T) => A
        • (acc: A, v: T): A
        • Parameters

          • acc: A
          • v: T

          Returns A

    • init: A

    Returns A

  • Type parameters

    • A

    Parameters

    Returns A

repeat

  • Returns a new generator that repeats the supplied value after this generator completes.

    Type parameters

    • N

    Parameters

    • value: N

      the value to repeat

    • Optional repetitions: number

      The number repetitions; the default is infinite.

    Returns EnhancedGenerator<CalendarStep | N, void, undefined>

repeatLast

  • Returns a new generator that repeats the last value returned by this (or undefined if this did not return any values).

    Parameters

    • Optional max: number

    Returns EnhancedGenerator<CalendarStep, any, undefined>

slice

  • Return a new EnhancedGenerator that only yields the indicated values, skipping start initial values and continuing until the end.

    Parameters

    • Optional start: number
    • Optional end: number

    Returns EnhancedGenerator<CalendarStep, any, undefined>

some

  • some<T>(p: (v: T, idx: number) => boolean, thisArg?: any): boolean
  • Returns true and terminates the generator if the predicate is true for any of the generator's yielded values.

    If the generator terminates without having satisfied the predicate, false is returned.

    Type parameters

    • T

    Parameters

    • p: (v: T, idx: number) => boolean

      predicate to apply to each yielded value.

        • (v: T, idx: number): boolean
        • Parameters

          • v: T
          • idx: number

          Returns boolean

    • Optional thisArg: any

      Optional value to supply as context (this) for the predicate

    Returns boolean

sort

  • Sorts the supplied values and returns a sorted array.

    Parameters

    Returns CalendarStep[]

toString

  • toString(): string

Static Private #getN

  • #getN(interval: CalendarUnit | { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }, n?: number): Integer
  • Parameters

    • interval: CalendarUnit | { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }
    • Optional n: number

    Returns Integer

Static Private #getUnit

  • #getUnit(interval: CalendarUnit | { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }): CalendarUnit
  • Parameters

    • interval: CalendarUnit | { biweekly: undefined | number; day: undefined | number; month: undefined | number; quarter: undefined | number; semiannually: undefined | number; semimonthly: undefined | number; week: undefined | number; year: undefined | number }

    Returns CalendarUnit

Generated using TypeDoc