Ƭ T: Object
Represents a DateRange.
Example
import { DateRange } from 'tiinvo'
const start = new Date("2022-01-01")
const end = new Date("2022-12-31")
const dr = DateRange.make(start, end, 'month')
for (const month of dr) {
console.log(month.toJSON())
}
Since
4.0.0
| Name | Type |
|---|---|
start |
Date |
end |
Date |
step |
"year" | "month" | "day" |
[iterator] |
() => Iterator<Date, any, undefined> |
▸ make(start, end, step?): T
Creates a DateRange.t between a starting date start and an ending date end (included).
Example
import { DateRange } from 'tiinvo'
const dr = DateRange.make(new Date('2020-01-01'), new Date('2020-01-03'), 'day');
Array.from(dr) // [new Date(2020, 0, 1), new Date(2020, 0, 2), new Date(2020, 0, 3)]
Step
the step to increment. It can be:
"year" (default), increments by year"month", increments by month"day", increments by daySince
4.0.0
| Name | Type | Default value | Description |
|---|---|---|---|
start |
Date |
undefined |
the starting date |
end |
Date |
undefined |
the ending date |
step |
"year" | "month" | "day" |
'year' |
- |
▸ guard(x): x is T
Checks if a parameter x is a DateRange.t.
Start and end are included in check.
Example
import { DateRange, Range } from 'tiinvo'
DateRange.guard(0) // false
DateRange.guard(Range.make(0, 2)) // false
DateRange.guard(DateRange.make(new Date(), new Date())) // true
Since
4.0.0
| Name | Type | Description |
|---|---|---|
x |
unknown |
the value to check |
x is T
returns true if x is DateRange, false otherwise
▸ inRange(a, b): boolean
Checks if a date b is in range of a DateRange.t a
Example
import { DateRange } from 'tiinvo'
const dr = DateRange.make(new Date('2020-01-01'), new Date('2020-01-03'), 'day');
DateRange.inRange(dr, new Date('2020-01-02')) // true
DateRange.inRange(dr, new Date('2020-01-03')) // true
DateRange.inRange(dr, new Date('2020-01-04')) // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
T |
the DateRange |
b |
Date |
the Date |
boolean
true if b is in range of a
▸ inRange(a): Unary<T, boolean>
Returns a Unary<T, boolean> function which checks if a date a is in range of a DateRange.t b
Example
import { DateRange } from 'tiinvo'
const dr = DateRange.make(new Date('2020-01-01'), new Date('2020-01-03'), 'day');
DateRange.inRange(new Date('2020-01-02'))(dr) // true
DateRange.inRange(new Date('2020-01-03'))(dr) // true
DateRange.inRange(new Date('2020-01-04'))(dr) // false
Since
4.0.0
| Name | Type | Description |
|---|---|---|
a |
Date |
the DateRange |
the unary function which accepts a DateRange.T and returns true if a is in DateRage.T
▸ map<a>(t, m): a[]
Maps a DateRange.t to a[] using a Mappable<Date, a>
Example
import { DateRange } from 'tiinvo'
const f = (x: Date) => x.getFullYear();
const dr = DateRange.make(new Date('2020-01-01'), new Date('2023-01-01'), 'year');
DateRange.map(dr, f) // [2020, 2021, 2022, 2023]
Since
4.0.0
| Name |
|---|
a |
| Name | Type | Description |
|---|---|---|
t |
T |
the DateRange |
m |
Mappable<Date, a> |
the mappable functor |
a[]
the mapped value
Returns a Unary<T, a[]> function which maps a DateRange.t
to a[] using a Mappable<Date, a>
Example
import { DateRange } from 'tiinvo'
const f = (x: Date) => x.getFullYear();
const m = DateRange.map(f)
const dr = DateRange.make(new Date('2020-01-01'), new Date('2023-01-01'), 'year');
m(dr) // [2020, 2021, 2022, 2023]
Since
4.0.0
| Name |
|---|
a |
| Name | Type | Description |
|---|---|---|
t |
Mappable<Date, a> |
the DateRange |
the unary function
▸ toArray<T>(arrayLike): T[]
Converts a DateRange.t to a Date[] array
Example
import { DateRange } from 'tiinvo'
const dr = DateRange.make(new Date('2020-01-01'), new Date('2020-01-03'), 'day');
DateRange.toArray(dr) // [new Date(2020, 0, 1), new Date(2020, 0, 2), new Date(2020, 0, 3)]
Since
4.0.0
| Name |
|---|
T |
| Name | Type |
|---|---|
arrayLike |
ArrayLike<T> |
T[]
node_modules/typescript/lib/lib.es2015.core.d.ts:72
▸ toArray<T, U>(arrayLike, mapfn, thisArg?): U[]
Converts a DateRange.t to a Date[] array
Example
import { DateRange } from 'tiinvo'
const dr = DateRange.make(new Date('2020-01-01'), new Date('2020-01-03'), 'day');
DateRange.toArray(dr) // [new Date(2020, 0, 1), new Date(2020, 0, 2), new Date(2020, 0, 3)]
Since
4.0.0
| Name |
|---|
T |
U |
| Name | Type |
|---|---|
arrayLike |
ArrayLike<T> |
mapfn |
(v: T, k: number) => U |
thisArg? |
any |
U[]
node_modules/typescript/lib/lib.es2015.core.d.ts:80
▸ toArray<T>(iterable): T[]
Converts a DateRange.t to a Date[] array
Example
import { DateRange } from 'tiinvo'
const dr = DateRange.make(new Date('2020-01-01'), new Date('2020-01-03'), 'day');
DateRange.toArray(dr) // [new Date(2020, 0, 1), new Date(2020, 0, 2), new Date(2020, 0, 3)]
Since
4.0.0
| Name |
|---|
T |
| Name | Type |
|---|---|
iterable |
Iterable<T> | ArrayLike<T> |
T[]
node_modules/typescript/lib/lib.es2015.iterable.d.ts:83
▸ toArray<T, U>(iterable, mapfn, thisArg?): U[]
Converts a DateRange.t to a Date[] array
Example
import { DateRange } from 'tiinvo'
const dr = DateRange.make(new Date('2020-01-01'), new Date('2020-01-03'), 'day');
DateRange.toArray(dr) // [new Date(2020, 0, 1), new Date(2020, 0, 2), new Date(2020, 0, 3)]
Since
4.0.0
| Name |
|---|
T |
U |
| Name | Type |
|---|---|
iterable |
Iterable<T> | ArrayLike<T> |
mapfn |
(v: T, k: number) => U |
thisArg? |
any |
U[]
node_modules/typescript/lib/lib.es2015.iterable.d.ts:91