@naturalcycles/time-lib
Advanced tools
Comparing version 3.4.1 to 3.5.0
@@ -0,1 +1,2 @@ | ||
import { END, Seq } from '@naturalcycles/js-lib'; | ||
import { dayjs } from './index'; | ||
@@ -17,2 +18,24 @@ /** | ||
} | ||
export function dayjsRangeSeq(minIncl, maxExcl, step = 1, stepUnit = 'd') { | ||
const min = dayjs(minIncl).startOf(stepUnit); | ||
const max = dayjs(maxExcl).startOf(stepUnit); | ||
return Seq.create(min, d => { | ||
const next = d.add(step, stepUnit); | ||
return next.isAfter(max) ? END : next; | ||
}); | ||
} | ||
// todo: this would require Seq.map() implementation | ||
// export function dayjsRangeISODateSeq( | ||
// minIncl: ConfigType, | ||
// maxExcl: ConfigType, | ||
// step = 1, | ||
// stepUnit: OpUnitType = 'd', | ||
// ): Seq<string> { | ||
// const min = dayjs(minIncl).startOf(stepUnit) | ||
// const max = dayjs(maxExcl).startOf(stepUnit) | ||
// return Seq.create(min, d => { | ||
// const next = d.add(step, stepUnit) | ||
// return next.isAfter(max) ? END : next | ||
// }) | ||
// } | ||
export function dayjsRangeISODate(minIncl, maxExcl, step = 1, stepUnit = 'd') { | ||
@@ -31,1 +54,15 @@ return dayjsRange(minIncl, maxExcl, step, stepUnit).map(d => d.toISODate()); | ||
} | ||
/** | ||
* Input must contain at least 1 item. | ||
*/ | ||
export function dayjsEarliest(...days) { | ||
// eslint-disable-next-line unicorn/no-array-reduce | ||
return days.reduce((earliest, d) => (d.isBefore(earliest) ? d : earliest)); | ||
} | ||
/** | ||
* Input must contain at least 1 item. | ||
*/ | ||
export function dayjsLatest(...days) { | ||
// eslint-disable-next-line unicorn/no-array-reduce | ||
return days.reduce((latest, d) => (d.isAfter(latest) ? d : latest)); | ||
} |
import { dayjs } from './dayjs.full'; | ||
import { DAYJS_TIME_HM, DAYJS_TIME_HMS, DAYJS_ISO_DATE, DAYJS_COMPACT_DATE, DAYJS_COMPACT_TIME, DAYJS_COMPACT_TIME_SECONDS, } from './plugin/default'; | ||
import { dayjsRange, dayjsRangeIncl, dayjsRangeInclISODate, dayjsRangeISODate } from './dayjsRange'; | ||
export * from './dayjsRange'; | ||
export { dayjs, // should be imported from dayjs.full, cause it's an extended version | ||
DAYJS_TIME_HM, DAYJS_TIME_HMS, DAYJS_ISO_DATE, DAYJS_COMPACT_DATE, DAYJS_COMPACT_TIME, DAYJS_COMPACT_TIME_SECONDS, dayjsRange, dayjsRangeIncl, dayjsRangeInclISODate, dayjsRangeISODate, | ||
DAYJS_TIME_HM, DAYJS_TIME_HMS, DAYJS_ISO_DATE, DAYJS_COMPACT_DATE, DAYJS_COMPACT_TIME, DAYJS_COMPACT_TIME_SECONDS, | ||
// loadDayjsLocales, | ||
// loadDayjsPlugins, | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { IsoDate } from '@naturalcycles/js-lib'; | ||
import { IsoDate, Seq } from '@naturalcycles/js-lib'; | ||
import { ConfigType, IDayjs, OpUnitType } from './index'; | ||
@@ -9,2 +9,3 @@ /** | ||
export declare function dayjsRange(minIncl: ConfigType, maxExcl: ConfigType, step?: number, stepUnit?: OpUnitType): IDayjs[]; | ||
export declare function dayjsRangeSeq(minIncl: ConfigType, maxExcl: ConfigType, step?: number, stepUnit?: OpUnitType): Seq<IDayjs>; | ||
export declare function dayjsRangeISODate(minIncl: ConfigType, maxExcl: ConfigType, step?: number, stepUnit?: OpUnitType): IsoDate[]; | ||
@@ -17,1 +18,9 @@ /** | ||
export declare function dayjsRangeInclISODate(minIncl: ConfigType, maxIncl: ConfigType, step?: number, stepUnit?: OpUnitType): IsoDate[]; | ||
/** | ||
* Input must contain at least 1 item. | ||
*/ | ||
export declare function dayjsEarliest(...days: IDayjs[]): IDayjs; | ||
/** | ||
* Input must contain at least 1 item. | ||
*/ | ||
export declare function dayjsLatest(...days: IDayjs[]): IDayjs; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.dayjsRangeInclISODate = exports.dayjsRangeIncl = exports.dayjsRangeISODate = exports.dayjsRange = void 0; | ||
exports.dayjsLatest = exports.dayjsEarliest = exports.dayjsRangeInclISODate = exports.dayjsRangeIncl = exports.dayjsRangeISODate = exports.dayjsRangeSeq = exports.dayjsRange = void 0; | ||
const js_lib_1 = require("@naturalcycles/js-lib"); | ||
const index_1 = require("./index"); | ||
@@ -21,2 +22,25 @@ /** | ||
exports.dayjsRange = dayjsRange; | ||
function dayjsRangeSeq(minIncl, maxExcl, step = 1, stepUnit = 'd') { | ||
const min = (0, index_1.dayjs)(minIncl).startOf(stepUnit); | ||
const max = (0, index_1.dayjs)(maxExcl).startOf(stepUnit); | ||
return js_lib_1.Seq.create(min, d => { | ||
const next = d.add(step, stepUnit); | ||
return next.isAfter(max) ? js_lib_1.END : next; | ||
}); | ||
} | ||
exports.dayjsRangeSeq = dayjsRangeSeq; | ||
// todo: this would require Seq.map() implementation | ||
// export function dayjsRangeISODateSeq( | ||
// minIncl: ConfigType, | ||
// maxExcl: ConfigType, | ||
// step = 1, | ||
// stepUnit: OpUnitType = 'd', | ||
// ): Seq<string> { | ||
// const min = dayjs(minIncl).startOf(stepUnit) | ||
// const max = dayjs(maxExcl).startOf(stepUnit) | ||
// return Seq.create(min, d => { | ||
// const next = d.add(step, stepUnit) | ||
// return next.isAfter(max) ? END : next | ||
// }) | ||
// } | ||
function dayjsRangeISODate(minIncl, maxExcl, step = 1, stepUnit = 'd') { | ||
@@ -38,1 +62,17 @@ return dayjsRange(minIncl, maxExcl, step, stepUnit).map(d => d.toISODate()); | ||
exports.dayjsRangeInclISODate = dayjsRangeInclISODate; | ||
/** | ||
* Input must contain at least 1 item. | ||
*/ | ||
function dayjsEarliest(...days) { | ||
// eslint-disable-next-line unicorn/no-array-reduce | ||
return days.reduce((earliest, d) => (d.isBefore(earliest) ? d : earliest)); | ||
} | ||
exports.dayjsEarliest = dayjsEarliest; | ||
/** | ||
* Input must contain at least 1 item. | ||
*/ | ||
function dayjsLatest(...days) { | ||
// eslint-disable-next-line unicorn/no-array-reduce | ||
return days.reduce((latest, d) => (d.isAfter(latest) ? d : latest)); | ||
} | ||
exports.dayjsLatest = dayjsLatest; |
import { dayjs } from './dayjs.full'; | ||
import { DAYJS_TIME_HM, DAYJS_TIME_HMS, DAYJS_ISO_DATE, DAYJS_COMPACT_DATE, DAYJS_COMPACT_TIME, DAYJS_COMPACT_TIME_SECONDS } from './plugin/default'; | ||
import { IDayjs, IDayjsFactory, IDayjsLocale, ConfigType, OpUnitType, GlobalLocaleDataReturn } from './types'; | ||
import { dayjsRange, dayjsRangeIncl, dayjsRangeInclISODate, dayjsRangeISODate } from './dayjsRange'; | ||
export * from './dayjsRange'; | ||
export type { IDayjsFactory, IDayjs, IDayjsLocale, ConfigType, OpUnitType, GlobalLocaleDataReturn }; | ||
export { dayjs, // should be imported from dayjs.full, cause it's an extended version | ||
DAYJS_TIME_HM, DAYJS_TIME_HMS, DAYJS_ISO_DATE, DAYJS_COMPACT_DATE, DAYJS_COMPACT_TIME, DAYJS_COMPACT_TIME_SECONDS, dayjsRange, dayjsRangeIncl, dayjsRangeInclISODate, dayjsRangeISODate, }; | ||
DAYJS_TIME_HM, DAYJS_TIME_HMS, DAYJS_ISO_DATE, DAYJS_COMPACT_DATE, DAYJS_COMPACT_TIME, DAYJS_COMPACT_TIME_SECONDS, }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.dayjsRangeISODate = exports.dayjsRangeInclISODate = exports.dayjsRangeIncl = exports.dayjsRange = exports.DAYJS_COMPACT_TIME_SECONDS = exports.DAYJS_COMPACT_TIME = exports.DAYJS_COMPACT_DATE = exports.DAYJS_ISO_DATE = exports.DAYJS_TIME_HMS = exports.DAYJS_TIME_HM = exports.dayjs = void 0; | ||
exports.DAYJS_COMPACT_TIME_SECONDS = exports.DAYJS_COMPACT_TIME = exports.DAYJS_COMPACT_DATE = exports.DAYJS_ISO_DATE = exports.DAYJS_TIME_HMS = exports.DAYJS_TIME_HM = exports.dayjs = void 0; | ||
const tslib_1 = require("tslib"); | ||
const dayjs_full_1 = require("./dayjs.full"); | ||
@@ -13,6 +14,2 @@ Object.defineProperty(exports, "dayjs", { enumerable: true, get: function () { return dayjs_full_1.dayjs; } }); | ||
Object.defineProperty(exports, "DAYJS_COMPACT_TIME_SECONDS", { enumerable: true, get: function () { return default_1.DAYJS_COMPACT_TIME_SECONDS; } }); | ||
const dayjsRange_1 = require("./dayjsRange"); | ||
Object.defineProperty(exports, "dayjsRange", { enumerable: true, get: function () { return dayjsRange_1.dayjsRange; } }); | ||
Object.defineProperty(exports, "dayjsRangeIncl", { enumerable: true, get: function () { return dayjsRange_1.dayjsRangeIncl; } }); | ||
Object.defineProperty(exports, "dayjsRangeInclISODate", { enumerable: true, get: function () { return dayjsRange_1.dayjsRangeInclISODate; } }); | ||
Object.defineProperty(exports, "dayjsRangeISODate", { enumerable: true, get: function () { return dayjsRange_1.dayjsRangeISODate; } }); | ||
(0, tslib_1.__exportStar)(require("./dayjsRange"), exports); |
@@ -43,3 +43,3 @@ { | ||
}, | ||
"version": "3.4.1", | ||
"version": "3.5.0", | ||
"description": "Date/time related API, based on Day.js", | ||
@@ -46,0 +46,0 @@ "keywords": [ |
@@ -1,3 +0,3 @@ | ||
import { IsoDate } from '@naturalcycles/js-lib' | ||
import { dayjs, ConfigType, IDayjs, OpUnitType } from './index' | ||
import { END, IsoDate, Seq } from '@naturalcycles/js-lib' | ||
import { ConfigType, dayjs, IDayjs, OpUnitType } from './index' | ||
@@ -27,2 +27,31 @@ /** | ||
export function dayjsRangeSeq( | ||
minIncl: ConfigType, | ||
maxExcl: ConfigType, | ||
step = 1, | ||
stepUnit: OpUnitType = 'd', | ||
): Seq<IDayjs> { | ||
const min = dayjs(minIncl).startOf(stepUnit) | ||
const max = dayjs(maxExcl).startOf(stepUnit) | ||
return Seq.create(min, d => { | ||
const next = d.add(step, stepUnit) | ||
return next.isAfter(max) ? END : next | ||
}) | ||
} | ||
// todo: this would require Seq.map() implementation | ||
// export function dayjsRangeISODateSeq( | ||
// minIncl: ConfigType, | ||
// maxExcl: ConfigType, | ||
// step = 1, | ||
// stepUnit: OpUnitType = 'd', | ||
// ): Seq<string> { | ||
// const min = dayjs(minIncl).startOf(stepUnit) | ||
// const max = dayjs(maxExcl).startOf(stepUnit) | ||
// return Seq.create(min, d => { | ||
// const next = d.add(step, stepUnit) | ||
// return next.isAfter(max) ? END : next | ||
// }) | ||
// } | ||
export function dayjsRangeISODate( | ||
@@ -58,1 +87,17 @@ minIncl: ConfigType, | ||
} | ||
/** | ||
* Input must contain at least 1 item. | ||
*/ | ||
export function dayjsEarliest(...days: IDayjs[]): IDayjs { | ||
// eslint-disable-next-line unicorn/no-array-reduce | ||
return days.reduce((earliest, d) => (d.isBefore(earliest) ? d : earliest)) | ||
} | ||
/** | ||
* Input must contain at least 1 item. | ||
*/ | ||
export function dayjsLatest(...days: IDayjs[]): IDayjs { | ||
// eslint-disable-next-line unicorn/no-array-reduce | ||
return days.reduce((latest, d) => (d.isAfter(latest) ? d : latest)) | ||
} |
@@ -18,3 +18,3 @@ import { dayjs } from './dayjs.full' | ||
} from './types' | ||
import { dayjsRange, dayjsRangeIncl, dayjsRangeInclISODate, dayjsRangeISODate } from './dayjsRange' | ||
export * from './dayjsRange' | ||
@@ -31,8 +31,4 @@ export type { IDayjsFactory, IDayjs, IDayjsLocale, ConfigType, OpUnitType, GlobalLocaleDataReturn } | ||
DAYJS_COMPACT_TIME_SECONDS, | ||
dayjsRange, | ||
dayjsRangeIncl, | ||
dayjsRangeInclISODate, | ||
dayjsRangeISODate, | ||
// loadDayjsLocales, | ||
// loadDayjsPlugins, | ||
} |
54861
1415