@gobrand/tiempo 2.6.2 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-IBO2U23N.js → chunk-5C3TQSWA.js} +4 -4
- package/dist/chunk-BUX26GTD.js +30 -0
- package/dist/chunk-BUX26GTD.js.map +1 -0
- package/dist/chunk-DKYVFYWM.js +25 -0
- package/dist/chunk-DKYVFYWM.js.map +1 -0
- package/dist/chunk-G2JUEBC5.js +26 -0
- package/dist/chunk-G2JUEBC5.js.map +1 -0
- package/dist/{chunk-MGMLT4L6.js → chunk-JA7SVLAF.js} +4 -4
- package/dist/chunk-OLEOU3XE.js +28 -0
- package/dist/chunk-OLEOU3XE.js.map +1 -0
- package/dist/chunk-TNCLJK4Y.js +38 -0
- package/dist/chunk-TNCLJK4Y.js.map +1 -0
- package/dist/chunk-Y7CIJQ67.js +26 -0
- package/dist/chunk-Y7CIJQ67.js.map +1 -0
- package/dist/chunk-YQBM63DC.js +57 -0
- package/dist/chunk-YQBM63DC.js.map +1 -0
- package/dist/eachDayOfInterval.d.ts +69 -0
- package/dist/eachDayOfInterval.d.ts.map +1 -0
- package/dist/eachDayOfInterval.js +8 -0
- package/dist/eachDayOfInterval.js.map +1 -0
- package/dist/eachDayOfInterval.test.d.ts +2 -0
- package/dist/eachDayOfInterval.test.d.ts.map +1 -0
- package/dist/eachHourOfInterval.d.ts +51 -0
- package/dist/eachHourOfInterval.d.ts.map +1 -0
- package/dist/eachHourOfInterval.js +8 -0
- package/dist/eachHourOfInterval.js.map +1 -0
- package/dist/eachHourOfInterval.test.d.ts +2 -0
- package/dist/eachHourOfInterval.test.d.ts.map +1 -0
- package/dist/eachMinuteOfInterval.d.ts +50 -0
- package/dist/eachMinuteOfInterval.d.ts.map +1 -0
- package/dist/eachMinuteOfInterval.js +8 -0
- package/dist/eachMinuteOfInterval.js.map +1 -0
- package/dist/eachMinuteOfInterval.test.d.ts +2 -0
- package/dist/eachMinuteOfInterval.test.d.ts.map +1 -0
- package/dist/eachMonthOfInterval.d.ts +46 -0
- package/dist/eachMonthOfInterval.d.ts.map +1 -0
- package/dist/eachMonthOfInterval.js +8 -0
- package/dist/eachMonthOfInterval.js.map +1 -0
- package/dist/eachMonthOfInterval.test.d.ts +2 -0
- package/dist/eachMonthOfInterval.test.d.ts.map +1 -0
- package/dist/eachWeekOfInterval.d.ts +58 -0
- package/dist/eachWeekOfInterval.d.ts.map +1 -0
- package/dist/eachWeekOfInterval.js +8 -0
- package/dist/eachWeekOfInterval.js.map +1 -0
- package/dist/eachWeekOfInterval.test.d.ts +2 -0
- package/dist/eachWeekOfInterval.test.d.ts.map +1 -0
- package/dist/eachYearOfInterval.d.ts +55 -0
- package/dist/eachYearOfInterval.d.ts.map +1 -0
- package/dist/eachYearOfInterval.js +8 -0
- package/dist/eachYearOfInterval.js.map +1 -0
- package/dist/eachYearOfInterval.test.d.ts +2 -0
- package/dist/eachYearOfInterval.test.d.ts.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -45
- package/dist/isFuture.js +2 -2
- package/dist/isWithinInterval.js +2 -2
- package/dist/simpleFormat.d.ts +48 -37
- package/dist/simpleFormat.d.ts.map +1 -1
- package/dist/simpleFormat.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-TFSZ55L7.js +0 -46
- package/dist/chunk-TFSZ55L7.js.map +0 -1
- /package/dist/{chunk-IBO2U23N.js.map → chunk-5C3TQSWA.js.map} +0 -0
- /package/dist/{chunk-MGMLT4L6.js.map → chunk-JA7SVLAF.js.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isBefore
|
|
3
|
-
} from "./chunk-WUAIUEH7.js";
|
|
4
1
|
import {
|
|
5
2
|
isAfter
|
|
6
3
|
} from "./chunk-WY63VEXE.js";
|
|
4
|
+
import {
|
|
5
|
+
isBefore
|
|
6
|
+
} from "./chunk-WUAIUEH7.js";
|
|
7
7
|
import {
|
|
8
8
|
normalizeTemporalInput
|
|
9
9
|
} from "./chunk-MJSZNWCV.js";
|
|
@@ -20,4 +20,4 @@ function isWithinInterval(date, interval) {
|
|
|
20
20
|
export {
|
|
21
21
|
isWithinInterval
|
|
22
22
|
};
|
|
23
|
-
//# sourceMappingURL=chunk-
|
|
23
|
+
//# sourceMappingURL=chunk-5C3TQSWA.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/eachYearOfInterval.ts
|
|
6
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
7
|
+
function eachYearOfInterval(interval) {
|
|
8
|
+
const startZoned = normalizeTemporalInput(interval.start);
|
|
9
|
+
const endZoned = normalizeTemporalInput(interval.end);
|
|
10
|
+
const timezone = startZoned.timeZoneId;
|
|
11
|
+
const startYear = startZoned.year;
|
|
12
|
+
const endInTimezone = endZoned.withTimeZone(timezone);
|
|
13
|
+
const endYear = endInTimezone.year;
|
|
14
|
+
const years = [];
|
|
15
|
+
for (let year = startYear; year <= endYear; year++) {
|
|
16
|
+
const firstOfYear = Temporal.PlainDate.from({ year, month: 1, day: 1 });
|
|
17
|
+
years.push(
|
|
18
|
+
firstOfYear.toZonedDateTime({
|
|
19
|
+
timeZone: timezone,
|
|
20
|
+
plainTime: new Temporal.PlainTime()
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return years;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
eachYearOfInterval
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=chunk-BUX26GTD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eachYearOfInterval.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Returns an array of ZonedDateTime objects for each year within the interval.\n * Each element represents the first moment of the year (January 1st at midnight).\n * The interval is inclusive of both start and end years.\n *\n * For Instant inputs, UTC is used as the timezone.\n * For ZonedDateTime inputs, the timezone of the start date is preserved.\n *\n * @param interval - The interval with start and end datetimes\n * @returns Array of ZonedDateTime at start of each year in the interval\n *\n * @example\n * ```ts\n * const start = Temporal.ZonedDateTime.from('2022-06-15T10:00:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-03-20T14:00:00Z[UTC]');\n *\n * const years = eachYearOfInterval({ start, end });\n * // [\n * // 2022-01-01T00:00:00Z[UTC],\n * // 2023-01-01T00:00:00Z[UTC],\n * // 2024-01-01T00:00:00Z[UTC],\n * // 2025-01-01T00:00:00Z[UTC]\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // Single year\n * const start = Temporal.ZonedDateTime.from('2025-01-15T00:00:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-12-31T23:59:59Z[UTC]');\n *\n * const years = eachYearOfInterval({ start, end });\n * // [2025-01-01T00:00:00Z[UTC]]\n * ```\n *\n * @example\n * ```ts\n * // With timezone\n * const start = Temporal.ZonedDateTime.from('2024-01-01T00:00:00-05:00[America/New_York]');\n * const end = Temporal.ZonedDateTime.from('2026-06-15T00:00:00-04:00[America/New_York]');\n *\n * const years = eachYearOfInterval({ start, end });\n * // [\n * // 2024-01-01T00:00:00-05:00[America/New_York],\n * // 2025-01-01T00:00:00-05:00[America/New_York],\n * // 2026-01-01T00:00:00-05:00[America/New_York]\n * // ]\n * ```\n */\nexport function eachYearOfInterval(interval: {\n start: Temporal.Instant | Temporal.ZonedDateTime;\n end: Temporal.Instant | Temporal.ZonedDateTime;\n}): Temporal.ZonedDateTime[] {\n const startZoned = normalizeTemporalInput(interval.start);\n const endZoned = normalizeTemporalInput(interval.end);\n\n const timezone = startZoned.timeZoneId;\n const startYear = startZoned.year;\n\n // Get end year in the same timezone\n const endInTimezone = endZoned.withTimeZone(timezone);\n const endYear = endInTimezone.year;\n\n const years: Temporal.ZonedDateTime[] = [];\n\n for (let year = startYear; year <= endYear; year++) {\n const firstOfYear = Temporal.PlainDate.from({ year, month: 1, day: 1 });\n years.push(\n firstOfYear.toZonedDateTime({\n timeZone: timezone,\n plainTime: new Temporal.PlainTime(),\n })\n );\n }\n\n return years;\n}\n"],"mappings":";;;;;AAAA,SAAS,gBAAgB;AAoDlB,SAAS,mBAAmB,UAGN;AAC3B,QAAM,aAAa,uBAAuB,SAAS,KAAK;AACxD,QAAM,WAAW,uBAAuB,SAAS,GAAG;AAEpD,QAAM,WAAW,WAAW;AAC5B,QAAM,YAAY,WAAW;AAG7B,QAAM,gBAAgB,SAAS,aAAa,QAAQ;AACpD,QAAM,UAAU,cAAc;AAE9B,QAAM,QAAkC,CAAC;AAEzC,WAAS,OAAO,WAAW,QAAQ,SAAS,QAAQ;AAClD,UAAM,cAAc,SAAS,UAAU,KAAK,EAAE,MAAM,OAAO,GAAG,KAAK,EAAE,CAAC;AACtE,UAAM;AAAA,MACJ,YAAY,gBAAgB;AAAA,QAC1B,UAAU;AAAA,QACV,WAAW,IAAI,SAAS,UAAU;AAAA,MACpC,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/eachDayOfInterval.ts
|
|
6
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
7
|
+
function eachDayOfInterval(interval) {
|
|
8
|
+
const startZoned = normalizeTemporalInput(interval.start);
|
|
9
|
+
const endZoned = normalizeTemporalInput(interval.end);
|
|
10
|
+
const timezone = startZoned.timeZoneId;
|
|
11
|
+
const startDate = startZoned.toPlainDate();
|
|
12
|
+
const endDate = endZoned.withTimeZone(timezone).toPlainDate();
|
|
13
|
+
const days = [];
|
|
14
|
+
let current = startDate;
|
|
15
|
+
while (Temporal.PlainDate.compare(current, endDate) <= 0) {
|
|
16
|
+
days.push(current.toZonedDateTime({ timeZone: timezone, plainTime: new Temporal.PlainTime() }));
|
|
17
|
+
current = current.add({ days: 1 });
|
|
18
|
+
}
|
|
19
|
+
return days;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
eachDayOfInterval
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-DKYVFYWM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eachDayOfInterval.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Returns an array of ZonedDateTime objects for each calendar day within the interval.\n * Each element represents the start of day (midnight) in the timezone of the interval start.\n * The interval is inclusive of both start and end days.\n *\n * For Instant inputs, UTC is used as the timezone.\n * For ZonedDateTime inputs, the timezone of the start date is preserved.\n *\n * @param interval - The interval with start and end datetimes\n * @returns Array of ZonedDateTime at start of each day in the interval\n *\n * @example\n * ```ts\n * const start = Temporal.ZonedDateTime.from('2025-01-06T10:00:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-01-10T14:00:00Z[UTC]');\n *\n * const days = eachDayOfInterval({ start, end });\n * // [\n * // 2025-01-06T00:00:00Z[UTC],\n * // 2025-01-07T00:00:00Z[UTC],\n * // 2025-01-08T00:00:00Z[UTC],\n * // 2025-01-09T00:00:00Z[UTC],\n * // 2025-01-10T00:00:00Z[UTC]\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // With timezone - preserves the timezone from start\n * const start = Temporal.ZonedDateTime.from('2025-01-06T10:00:00-05:00[America/New_York]');\n * const end = Temporal.ZonedDateTime.from('2025-01-08T14:00:00-05:00[America/New_York]');\n *\n * const days = eachDayOfInterval({ start, end });\n * // [\n * // 2025-01-06T00:00:00-05:00[America/New_York],\n * // 2025-01-07T00:00:00-05:00[America/New_York],\n * // 2025-01-08T00:00:00-05:00[America/New_York]\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // With Instant (uses UTC)\n * const start = Temporal.Instant.from('2025-01-06T00:00:00Z');\n * const end = Temporal.Instant.from('2025-01-08T00:00:00Z');\n *\n * const days = eachDayOfInterval({ start, end });\n * // [\n * // 2025-01-06T00:00:00Z[UTC],\n * // 2025-01-07T00:00:00Z[UTC],\n * // 2025-01-08T00:00:00Z[UTC]\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // Single day interval\n * const date = Temporal.ZonedDateTime.from('2025-01-15T12:00:00Z[UTC]');\n *\n * eachDayOfInterval({ start: date, end: date });\n * // [2025-01-15T00:00:00Z[UTC]]\n * ```\n */\nexport function eachDayOfInterval(interval: {\n start: Temporal.Instant | Temporal.ZonedDateTime;\n end: Temporal.Instant | Temporal.ZonedDateTime;\n}): Temporal.ZonedDateTime[] {\n const startZoned = normalizeTemporalInput(interval.start);\n const endZoned = normalizeTemporalInput(interval.end);\n\n const timezone = startZoned.timeZoneId;\n const startDate = startZoned.toPlainDate();\n const endDate = endZoned.withTimeZone(timezone).toPlainDate();\n\n const days: Temporal.ZonedDateTime[] = [];\n let current = startDate;\n\n while (Temporal.PlainDate.compare(current, endDate) <= 0) {\n days.push(current.toZonedDateTime({ timeZone: timezone, plainTime: new Temporal.PlainTime() }));\n current = current.add({ days: 1 });\n }\n\n return days;\n}\n"],"mappings":";;;;;AAAA,SAAS,gBAAgB;AAkElB,SAAS,kBAAkB,UAGL;AAC3B,QAAM,aAAa,uBAAuB,SAAS,KAAK;AACxD,QAAM,WAAW,uBAAuB,SAAS,GAAG;AAEpD,QAAM,WAAW,WAAW;AAC5B,QAAM,YAAY,WAAW,YAAY;AACzC,QAAM,UAAU,SAAS,aAAa,QAAQ,EAAE,YAAY;AAE5D,QAAM,OAAiC,CAAC;AACxC,MAAI,UAAU;AAEd,SAAO,SAAS,UAAU,QAAQ,SAAS,OAAO,KAAK,GAAG;AACxD,SAAK,KAAK,QAAQ,gBAAgB,EAAE,UAAU,UAAU,WAAW,IAAI,SAAS,UAAU,EAAE,CAAC,CAAC;AAC9F,cAAU,QAAQ,IAAI,EAAE,MAAM,EAAE,CAAC;AAAA,EACnC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/eachMinuteOfInterval.ts
|
|
6
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
7
|
+
function eachMinuteOfInterval(interval) {
|
|
8
|
+
const startZoned = normalizeTemporalInput(interval.start);
|
|
9
|
+
const endZoned = normalizeTemporalInput(interval.end);
|
|
10
|
+
const timezone = startZoned.timeZoneId;
|
|
11
|
+
const startMinute = startZoned.round({ smallestUnit: "minute", roundingMode: "floor" });
|
|
12
|
+
const endInTimezone = endZoned.withTimeZone(timezone);
|
|
13
|
+
const endMinute = endInTimezone.round({ smallestUnit: "minute", roundingMode: "floor" });
|
|
14
|
+
const minutes = [];
|
|
15
|
+
let current = startMinute;
|
|
16
|
+
while (Temporal.ZonedDateTime.compare(current, endMinute) <= 0) {
|
|
17
|
+
minutes.push(current);
|
|
18
|
+
current = current.add({ minutes: 1 });
|
|
19
|
+
}
|
|
20
|
+
return minutes;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
eachMinuteOfInterval
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-G2JUEBC5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eachMinuteOfInterval.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Returns an array of ZonedDateTime objects for each minute within the interval.\n * Each element represents the start of the minute (seconds/etc. set to 0).\n * The interval is inclusive of both start and end minutes.\n *\n * For Instant inputs, UTC is used as the timezone.\n * For ZonedDateTime inputs, the timezone of the start date is preserved.\n *\n * Warning: Large intervals can produce very large arrays. For example, a 24-hour\n * interval produces 1,441 elements. Consider whether this is appropriate for your use case.\n *\n * @param interval - The interval with start and end datetimes\n * @returns Array of ZonedDateTime at start of each minute in the interval\n *\n * @example\n * ```ts\n * const start = Temporal.ZonedDateTime.from('2025-01-06T10:30:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-01-06T10:33:45Z[UTC]');\n *\n * const minutes = eachMinuteOfInterval({ start, end });\n * // [\n * // 2025-01-06T10:30:00Z[UTC],\n * // 2025-01-06T10:31:00Z[UTC],\n * // 2025-01-06T10:32:00Z[UTC],\n * // 2025-01-06T10:33:00Z[UTC]\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // Cross-hour boundary\n * const start = Temporal.ZonedDateTime.from('2025-01-06T10:58:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-01-06T11:02:00Z[UTC]');\n *\n * const minutes = eachMinuteOfInterval({ start, end });\n * // [\n * // 2025-01-06T10:58:00Z[UTC],\n * // 2025-01-06T10:59:00Z[UTC],\n * // 2025-01-06T11:00:00Z[UTC],\n * // 2025-01-06T11:01:00Z[UTC],\n * // 2025-01-06T11:02:00Z[UTC]\n * // ]\n * ```\n */\nexport function eachMinuteOfInterval(interval: {\n start: Temporal.Instant | Temporal.ZonedDateTime;\n end: Temporal.Instant | Temporal.ZonedDateTime;\n}): Temporal.ZonedDateTime[] {\n const startZoned = normalizeTemporalInput(interval.start);\n const endZoned = normalizeTemporalInput(interval.end);\n\n const timezone = startZoned.timeZoneId;\n\n // Get start of the starting minute\n const startMinute = startZoned.round({ smallestUnit: 'minute', roundingMode: 'floor' });\n\n // Get start of the ending minute in the same timezone\n const endInTimezone = endZoned.withTimeZone(timezone);\n const endMinute = endInTimezone.round({ smallestUnit: 'minute', roundingMode: 'floor' });\n\n const minutes: Temporal.ZonedDateTime[] = [];\n let current = startMinute;\n\n while (Temporal.ZonedDateTime.compare(current, endMinute) <= 0) {\n minutes.push(current);\n current = current.add({ minutes: 1 });\n }\n\n return minutes;\n}\n"],"mappings":";;;;;AAAA,SAAS,gBAAgB;AA+ClB,SAAS,qBAAqB,UAGR;AAC3B,QAAM,aAAa,uBAAuB,SAAS,KAAK;AACxD,QAAM,WAAW,uBAAuB,SAAS,GAAG;AAEpD,QAAM,WAAW,WAAW;AAG5B,QAAM,cAAc,WAAW,MAAM,EAAE,cAAc,UAAU,cAAc,QAAQ,CAAC;AAGtF,QAAM,gBAAgB,SAAS,aAAa,QAAQ;AACpD,QAAM,YAAY,cAAc,MAAM,EAAE,cAAc,UAAU,cAAc,QAAQ,CAAC;AAEvF,QAAM,UAAoC,CAAC;AAC3C,MAAI,UAAU;AAEd,SAAO,SAAS,cAAc,QAAQ,SAAS,SAAS,KAAK,GAAG;AAC9D,YAAQ,KAAK,OAAO;AACpB,cAAU,QAAQ,IAAI,EAAE,SAAS,EAAE,CAAC;AAAA,EACtC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
nowZoned
|
|
3
|
-
} from "./chunk-QFNGYTTH.js";
|
|
4
1
|
import {
|
|
5
2
|
isAfter
|
|
6
3
|
} from "./chunk-WY63VEXE.js";
|
|
4
|
+
import {
|
|
5
|
+
nowZoned
|
|
6
|
+
} from "./chunk-QFNGYTTH.js";
|
|
7
7
|
import {
|
|
8
8
|
normalizeTemporalInput
|
|
9
9
|
} from "./chunk-MJSZNWCV.js";
|
|
@@ -17,4 +17,4 @@ function isFuture(date) {
|
|
|
17
17
|
export {
|
|
18
18
|
isFuture
|
|
19
19
|
};
|
|
20
|
-
//# sourceMappingURL=chunk-
|
|
20
|
+
//# sourceMappingURL=chunk-JA7SVLAF.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/eachWeekOfInterval.ts
|
|
6
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
7
|
+
function eachWeekOfInterval(interval) {
|
|
8
|
+
const startZoned = normalizeTemporalInput(interval.start);
|
|
9
|
+
const endZoned = normalizeTemporalInput(interval.end);
|
|
10
|
+
const timezone = startZoned.timeZoneId;
|
|
11
|
+
const daysToSubtractStart = startZoned.dayOfWeek - 1;
|
|
12
|
+
const startMonday = startZoned.subtract({ days: daysToSubtractStart }).startOfDay();
|
|
13
|
+
const endInTimezone = endZoned.withTimeZone(timezone);
|
|
14
|
+
const daysToSubtractEnd = endInTimezone.dayOfWeek - 1;
|
|
15
|
+
const endMonday = endInTimezone.subtract({ days: daysToSubtractEnd }).startOfDay();
|
|
16
|
+
const weeks = [];
|
|
17
|
+
let current = startMonday;
|
|
18
|
+
while (Temporal.ZonedDateTime.compare(current, endMonday) <= 0) {
|
|
19
|
+
weeks.push(current);
|
|
20
|
+
current = current.add({ weeks: 1 });
|
|
21
|
+
}
|
|
22
|
+
return weeks;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
eachWeekOfInterval
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=chunk-OLEOU3XE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eachWeekOfInterval.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Returns an array of ZonedDateTime objects for each week within the interval.\n * Each element represents the first moment of the week (Monday at midnight).\n * Uses ISO 8601 week definition: weeks start on Monday.\n * The interval is inclusive of both start and end weeks.\n *\n * For Instant inputs, UTC is used as the timezone.\n * For ZonedDateTime inputs, the timezone of the start date is preserved.\n *\n * @param interval - The interval with start and end datetimes\n * @returns Array of ZonedDateTime at start of each week (Monday) in the interval\n *\n * @example\n * ```ts\n * const start = Temporal.ZonedDateTime.from('2025-01-06T10:00:00Z[UTC]'); // Monday\n * const end = Temporal.ZonedDateTime.from('2025-01-22T14:00:00Z[UTC]'); // Wednesday\n *\n * const weeks = eachWeekOfInterval({ start, end });\n * // [\n * // 2025-01-06T00:00:00Z[UTC], // Week 2\n * // 2025-01-13T00:00:00Z[UTC], // Week 3\n * // 2025-01-20T00:00:00Z[UTC] // Week 4\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // Mid-week start\n * const start = Temporal.ZonedDateTime.from('2025-01-08T10:00:00Z[UTC]'); // Wednesday\n * const end = Temporal.ZonedDateTime.from('2025-01-15T14:00:00Z[UTC]'); // Wednesday\n *\n * const weeks = eachWeekOfInterval({ start, end });\n * // [\n * // 2025-01-06T00:00:00Z[UTC], // Monday of week containing Jan 8\n * // 2025-01-13T00:00:00Z[UTC] // Monday of week containing Jan 15\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // Cross-year boundary\n * const start = Temporal.ZonedDateTime.from('2024-12-25T00:00:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-01-08T00:00:00Z[UTC]');\n *\n * const weeks = eachWeekOfInterval({ start, end });\n * // [\n * // 2024-12-23T00:00:00Z[UTC], // Monday of week containing Dec 25\n * // 2024-12-30T00:00:00Z[UTC], // Monday of week containing Dec 30\n * // 2025-01-06T00:00:00Z[UTC] // Monday of week containing Jan 8\n * // ]\n * ```\n */\nexport function eachWeekOfInterval(interval: {\n start: Temporal.Instant | Temporal.ZonedDateTime;\n end: Temporal.Instant | Temporal.ZonedDateTime;\n}): Temporal.ZonedDateTime[] {\n const startZoned = normalizeTemporalInput(interval.start);\n const endZoned = normalizeTemporalInput(interval.end);\n\n const timezone = startZoned.timeZoneId;\n\n // Get Monday of the starting week\n // dayOfWeek: 1 = Monday, 7 = Sunday (ISO 8601)\n const daysToSubtractStart = startZoned.dayOfWeek - 1;\n const startMonday = startZoned.subtract({ days: daysToSubtractStart }).startOfDay();\n\n // Get Monday of the ending week\n const endInTimezone = endZoned.withTimeZone(timezone);\n const daysToSubtractEnd = endInTimezone.dayOfWeek - 1;\n const endMonday = endInTimezone.subtract({ days: daysToSubtractEnd }).startOfDay();\n\n const weeks: Temporal.ZonedDateTime[] = [];\n let current = startMonday;\n\n while (Temporal.ZonedDateTime.compare(current, endMonday) <= 0) {\n weeks.push(current);\n current = current.add({ weeks: 1 });\n }\n\n return weeks;\n}\n"],"mappings":";;;;;AAAA,SAAS,gBAAgB;AAuDlB,SAAS,mBAAmB,UAGN;AAC3B,QAAM,aAAa,uBAAuB,SAAS,KAAK;AACxD,QAAM,WAAW,uBAAuB,SAAS,GAAG;AAEpD,QAAM,WAAW,WAAW;AAI5B,QAAM,sBAAsB,WAAW,YAAY;AACnD,QAAM,cAAc,WAAW,SAAS,EAAE,MAAM,oBAAoB,CAAC,EAAE,WAAW;AAGlF,QAAM,gBAAgB,SAAS,aAAa,QAAQ;AACpD,QAAM,oBAAoB,cAAc,YAAY;AACpD,QAAM,YAAY,cAAc,SAAS,EAAE,MAAM,kBAAkB,CAAC,EAAE,WAAW;AAEjF,QAAM,QAAkC,CAAC;AACzC,MAAI,UAAU;AAEd,SAAO,SAAS,cAAc,QAAQ,SAAS,SAAS,KAAK,GAAG;AAC9D,UAAM,KAAK,OAAO;AAClB,cAAU,QAAQ,IAAI,EAAE,OAAO,EAAE,CAAC;AAAA,EACpC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/eachMonthOfInterval.ts
|
|
6
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
7
|
+
function eachMonthOfInterval(interval) {
|
|
8
|
+
const startZoned = normalizeTemporalInput(interval.start);
|
|
9
|
+
const endZoned = normalizeTemporalInput(interval.end);
|
|
10
|
+
const timezone = startZoned.timeZoneId;
|
|
11
|
+
const startYearMonth = Temporal.PlainYearMonth.from({
|
|
12
|
+
year: startZoned.year,
|
|
13
|
+
month: startZoned.month
|
|
14
|
+
});
|
|
15
|
+
const endInTimezone = endZoned.withTimeZone(timezone);
|
|
16
|
+
const endYearMonth = Temporal.PlainYearMonth.from({
|
|
17
|
+
year: endInTimezone.year,
|
|
18
|
+
month: endInTimezone.month
|
|
19
|
+
});
|
|
20
|
+
const months = [];
|
|
21
|
+
let current = startYearMonth;
|
|
22
|
+
while (Temporal.PlainYearMonth.compare(current, endYearMonth) <= 0) {
|
|
23
|
+
const firstOfMonth = current.toPlainDate({ day: 1 });
|
|
24
|
+
months.push(
|
|
25
|
+
firstOfMonth.toZonedDateTime({
|
|
26
|
+
timeZone: timezone,
|
|
27
|
+
plainTime: new Temporal.PlainTime()
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
current = current.add({ months: 1 });
|
|
31
|
+
}
|
|
32
|
+
return months;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
eachMonthOfInterval
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=chunk-TNCLJK4Y.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eachMonthOfInterval.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Returns an array of ZonedDateTime objects for each month within the interval.\n * Each element represents the first moment of the month (day 1 at midnight).\n * The interval is inclusive of both start and end months.\n *\n * For Instant inputs, UTC is used as the timezone.\n * For ZonedDateTime inputs, the timezone of the start date is preserved.\n *\n * @param interval - The interval with start and end datetimes\n * @returns Array of ZonedDateTime at start of each month in the interval\n *\n * @example\n * ```ts\n * const start = Temporal.ZonedDateTime.from('2025-01-15T10:00:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-04-20T14:00:00Z[UTC]');\n *\n * const months = eachMonthOfInterval({ start, end });\n * // [\n * // 2025-01-01T00:00:00Z[UTC],\n * // 2025-02-01T00:00:00Z[UTC],\n * // 2025-03-01T00:00:00Z[UTC],\n * // 2025-04-01T00:00:00Z[UTC]\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // Cross-year boundary\n * const start = Temporal.ZonedDateTime.from('2024-11-15T00:00:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-02-15T00:00:00Z[UTC]');\n *\n * const months = eachMonthOfInterval({ start, end });\n * // [\n * // 2024-11-01T00:00:00Z[UTC],\n * // 2024-12-01T00:00:00Z[UTC],\n * // 2025-01-01T00:00:00Z[UTC],\n * // 2025-02-01T00:00:00Z[UTC]\n * // ]\n * ```\n */\nexport function eachMonthOfInterval(interval: {\n start: Temporal.Instant | Temporal.ZonedDateTime;\n end: Temporal.Instant | Temporal.ZonedDateTime;\n}): Temporal.ZonedDateTime[] {\n const startZoned = normalizeTemporalInput(interval.start);\n const endZoned = normalizeTemporalInput(interval.end);\n\n const timezone = startZoned.timeZoneId;\n\n // Get start of the starting month\n const startYearMonth = Temporal.PlainYearMonth.from({\n year: startZoned.year,\n month: startZoned.month,\n });\n\n // Get end month in the same timezone\n const endInTimezone = endZoned.withTimeZone(timezone);\n const endYearMonth = Temporal.PlainYearMonth.from({\n year: endInTimezone.year,\n month: endInTimezone.month,\n });\n\n const months: Temporal.ZonedDateTime[] = [];\n let current = startYearMonth;\n\n while (Temporal.PlainYearMonth.compare(current, endYearMonth) <= 0) {\n const firstOfMonth = current.toPlainDate({ day: 1 });\n months.push(\n firstOfMonth.toZonedDateTime({\n timeZone: timezone,\n plainTime: new Temporal.PlainTime(),\n })\n );\n current = current.add({ months: 1 });\n }\n\n return months;\n}\n"],"mappings":";;;;;AAAA,SAAS,gBAAgB;AA2ClB,SAAS,oBAAoB,UAGP;AAC3B,QAAM,aAAa,uBAAuB,SAAS,KAAK;AACxD,QAAM,WAAW,uBAAuB,SAAS,GAAG;AAEpD,QAAM,WAAW,WAAW;AAG5B,QAAM,iBAAiB,SAAS,eAAe,KAAK;AAAA,IAClD,MAAM,WAAW;AAAA,IACjB,OAAO,WAAW;AAAA,EACpB,CAAC;AAGD,QAAM,gBAAgB,SAAS,aAAa,QAAQ;AACpD,QAAM,eAAe,SAAS,eAAe,KAAK;AAAA,IAChD,MAAM,cAAc;AAAA,IACpB,OAAO,cAAc;AAAA,EACvB,CAAC;AAED,QAAM,SAAmC,CAAC;AAC1C,MAAI,UAAU;AAEd,SAAO,SAAS,eAAe,QAAQ,SAAS,YAAY,KAAK,GAAG;AAClE,UAAM,eAAe,QAAQ,YAAY,EAAE,KAAK,EAAE,CAAC;AACnD,WAAO;AAAA,MACL,aAAa,gBAAgB;AAAA,QAC3B,UAAU;AAAA,QACV,WAAW,IAAI,SAAS,UAAU;AAAA,MACpC,CAAC;AAAA,IACH;AACA,cAAU,QAAQ,IAAI,EAAE,QAAQ,EAAE,CAAC;AAAA,EACrC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/eachHourOfInterval.ts
|
|
6
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
7
|
+
function eachHourOfInterval(interval) {
|
|
8
|
+
const startZoned = normalizeTemporalInput(interval.start);
|
|
9
|
+
const endZoned = normalizeTemporalInput(interval.end);
|
|
10
|
+
const timezone = startZoned.timeZoneId;
|
|
11
|
+
const startHour = startZoned.round({ smallestUnit: "hour", roundingMode: "floor" });
|
|
12
|
+
const endInTimezone = endZoned.withTimeZone(timezone);
|
|
13
|
+
const endHour = endInTimezone.round({ smallestUnit: "hour", roundingMode: "floor" });
|
|
14
|
+
const hours = [];
|
|
15
|
+
let current = startHour;
|
|
16
|
+
while (Temporal.ZonedDateTime.compare(current, endHour) <= 0) {
|
|
17
|
+
hours.push(current);
|
|
18
|
+
current = current.add({ hours: 1 });
|
|
19
|
+
}
|
|
20
|
+
return hours;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
eachHourOfInterval
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-Y7CIJQ67.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eachHourOfInterval.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Returns an array of ZonedDateTime objects for each hour within the interval.\n * Each element represents the start of the hour (minute/second/etc. set to 0).\n * The interval is inclusive of both start and end hours.\n *\n * For Instant inputs, UTC is used as the timezone.\n * For ZonedDateTime inputs, the timezone of the start date is preserved.\n *\n * Note: During DST transitions, some hours may be skipped (spring forward) or\n * the array may contain fewer/more hours than expected based on wall-clock time.\n *\n * @param interval - The interval with start and end datetimes\n * @returns Array of ZonedDateTime at start of each hour in the interval\n *\n * @example\n * ```ts\n * const start = Temporal.ZonedDateTime.from('2025-01-06T10:30:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-01-06T14:15:00Z[UTC]');\n *\n * const hours = eachHourOfInterval({ start, end });\n * // [\n * // 2025-01-06T10:00:00Z[UTC],\n * // 2025-01-06T11:00:00Z[UTC],\n * // 2025-01-06T12:00:00Z[UTC],\n * // 2025-01-06T13:00:00Z[UTC],\n * // 2025-01-06T14:00:00Z[UTC]\n * // ]\n * ```\n *\n * @example\n * ```ts\n * // Cross-day boundary\n * const start = Temporal.ZonedDateTime.from('2025-01-06T22:00:00Z[UTC]');\n * const end = Temporal.ZonedDateTime.from('2025-01-07T02:00:00Z[UTC]');\n *\n * const hours = eachHourOfInterval({ start, end });\n * // [\n * // 2025-01-06T22:00:00Z[UTC],\n * // 2025-01-06T23:00:00Z[UTC],\n * // 2025-01-07T00:00:00Z[UTC],\n * // 2025-01-07T01:00:00Z[UTC],\n * // 2025-01-07T02:00:00Z[UTC]\n * // ]\n * ```\n */\nexport function eachHourOfInterval(interval: {\n start: Temporal.Instant | Temporal.ZonedDateTime;\n end: Temporal.Instant | Temporal.ZonedDateTime;\n}): Temporal.ZonedDateTime[] {\n const startZoned = normalizeTemporalInput(interval.start);\n const endZoned = normalizeTemporalInput(interval.end);\n\n const timezone = startZoned.timeZoneId;\n\n // Get start of the starting hour\n const startHour = startZoned.round({ smallestUnit: 'hour', roundingMode: 'floor' });\n\n // Get start of the ending hour in the same timezone\n const endInTimezone = endZoned.withTimeZone(timezone);\n const endHour = endInTimezone.round({ smallestUnit: 'hour', roundingMode: 'floor' });\n\n const hours: Temporal.ZonedDateTime[] = [];\n let current = startHour;\n\n while (Temporal.ZonedDateTime.compare(current, endHour) <= 0) {\n hours.push(current);\n current = current.add({ hours: 1 });\n }\n\n return hours;\n}\n"],"mappings":";;;;;AAAA,SAAS,gBAAgB;AAgDlB,SAAS,mBAAmB,UAGN;AAC3B,QAAM,aAAa,uBAAuB,SAAS,KAAK;AACxD,QAAM,WAAW,uBAAuB,SAAS,GAAG;AAEpD,QAAM,WAAW,WAAW;AAG5B,QAAM,YAAY,WAAW,MAAM,EAAE,cAAc,QAAQ,cAAc,QAAQ,CAAC;AAGlF,QAAM,gBAAgB,SAAS,aAAa,QAAQ;AACpD,QAAM,UAAU,cAAc,MAAM,EAAE,cAAc,QAAQ,cAAc,QAAQ,CAAC;AAEnF,QAAM,QAAkC,CAAC;AACzC,MAAI,UAAU;AAEd,SAAO,SAAS,cAAc,QAAQ,SAAS,OAAO,KAAK,GAAG;AAC5D,UAAM,KAAK,OAAO;AAClB,cAAU,QAAQ,IAAI,EAAE,OAAO,EAAE,CAAC;AAAA,EACpC;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/simpleFormat.ts
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
function simpleFormat(input, options) {
|
|
4
|
+
const { locale = "en-US", timeZone } = options;
|
|
5
|
+
const dateFormat = "date" in options ? options.date : void 0;
|
|
6
|
+
const timeFormat = "time" in options ? options.time : void 0;
|
|
7
|
+
let zdt;
|
|
8
|
+
if (input instanceof Temporal.Instant) {
|
|
9
|
+
const tz = timeZone ?? "UTC";
|
|
10
|
+
zdt = input.toZonedDateTimeISO(tz);
|
|
11
|
+
} else if (input instanceof Temporal.ZonedDateTime) {
|
|
12
|
+
if (timeZone) {
|
|
13
|
+
zdt = input.toInstant().toZonedDateTimeISO(timeZone);
|
|
14
|
+
} else {
|
|
15
|
+
zdt = input;
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
zdt = input.toZonedDateTime({ timeZone: timeZone ?? "UTC", plainTime: new Temporal.PlainTime() });
|
|
19
|
+
}
|
|
20
|
+
const parts = [];
|
|
21
|
+
if (dateFormat) {
|
|
22
|
+
const currentYear = Temporal.Now.plainDateISO().year;
|
|
23
|
+
const showYear = dateFormat === "full" ? true : dateFormat === "compact" ? false : zdt.year !== currentYear;
|
|
24
|
+
const dateOptions = {
|
|
25
|
+
day: "numeric",
|
|
26
|
+
month: "short",
|
|
27
|
+
year: showYear ? "numeric" : void 0
|
|
28
|
+
};
|
|
29
|
+
parts.push(zdt.toLocaleString(locale, dateOptions));
|
|
30
|
+
}
|
|
31
|
+
if (timeFormat) {
|
|
32
|
+
if (timeFormat === "compact") {
|
|
33
|
+
parts.push(formatCompactTime(zdt));
|
|
34
|
+
} else {
|
|
35
|
+
const timeOptions = {
|
|
36
|
+
hour: "numeric",
|
|
37
|
+
minute: "2-digit",
|
|
38
|
+
hour12: timeFormat === "12h"
|
|
39
|
+
};
|
|
40
|
+
parts.push(zdt.toLocaleString(locale, timeOptions));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return parts.join(", ");
|
|
44
|
+
}
|
|
45
|
+
function formatCompactTime(zdt) {
|
|
46
|
+
const hour12 = zdt.hour % 12 || 12;
|
|
47
|
+
const ampm = zdt.hour < 12 ? "am" : "pm";
|
|
48
|
+
if (zdt.minute === 0) {
|
|
49
|
+
return `${hour12}${ampm}`;
|
|
50
|
+
}
|
|
51
|
+
return `${hour12}:${zdt.minute.toString().padStart(2, "0")}${ampm}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
simpleFormat
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=chunk-YQBM63DC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/simpleFormat.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\n\ninterface BaseOptions {\n locale?: string;\n timeZone?: Timezone;\n}\n\ninterface DateOnlyOptions extends BaseOptions {\n date: 'compact' | 'auto' | 'full';\n time?: never;\n}\n\ninterface TimeOnlyOptions extends BaseOptions {\n date?: never;\n time: '12h' | '24h' | 'compact';\n}\n\ninterface DateAndTimeOptions extends BaseOptions {\n date: 'compact' | 'auto' | 'full';\n time: '12h' | '24h' | 'compact';\n}\n\nexport type SimpleFormatOptions = DateOnlyOptions | TimeOnlyOptions | DateAndTimeOptions;\n\n/**\n * Format a Temporal date/time in a human-friendly way.\n *\n * Pass `date`, `time`, or both to control what's displayed.\n * At least one of `date` or `time` is required.\n *\n * @param input - A Temporal.Instant, ZonedDateTime, or PlainDate\n * @param options - Format options (at least `date` or `time` required)\n *\n * Date formats:\n * - `'compact'` - \"Dec 23\" (never shows year)\n * - `'auto'` - \"Dec 23\" or \"Dec 23, 2020\" (shows year only if not current year)\n * - `'full'` - \"Dec 23, 2026\" (always shows year)\n *\n * Time formats:\n * - `'12h'` - \"3:30 PM\"\n * - `'24h'` - \"15:30\"\n * - `'compact'` - \"9am\" or \"2:30pm\" (omits minutes when zero, lowercase am/pm)\n *\n * @example\n * ```typescript\n * const zdt = Temporal.ZonedDateTime.from(\"2026-12-23T09:00:00[America/New_York]\");\n * const pastZdt = Temporal.ZonedDateTime.from(\"2020-12-23T14:30:00[America/New_York]\");\n *\n * // Date only\n * simpleFormat(zdt, { date: 'compact' }); // \"Dec 23\"\n * simpleFormat(zdt, { date: 'auto' }); // \"Dec 23\"\n * simpleFormat(pastZdt, { date: 'auto' }); // \"Dec 23, 2020\"\n * simpleFormat(zdt, { date: 'full' }); // \"Dec 23, 2026\"\n *\n * // Time only\n * simpleFormat(zdt, { time: 'compact' }); // \"9am\"\n * simpleFormat(pastZdt, { time: 'compact' }); // \"2:30pm\"\n * simpleFormat(zdt, { time: '12h' }); // \"9:00 AM\"\n * simpleFormat(zdt, { time: '24h' }); // \"09:00\"\n *\n * // Date and time\n * simpleFormat(zdt, { date: 'auto', time: 'compact' }); // \"Dec 23, 9am\"\n * simpleFormat(zdt, { date: 'full', time: '12h' }); // \"Dec 23, 2026, 9:00 AM\"\n *\n * // With Instant (timeZone required)\n * const instant = Temporal.Instant.from(\"2026-12-23T14:00:00Z\");\n * simpleFormat(instant, { date: 'auto', timeZone: 'America/New_York' }); // \"Dec 23\"\n * ```\n */\nexport function simpleFormat(\n input: Temporal.PlainDate | Temporal.ZonedDateTime | Temporal.Instant,\n options: SimpleFormatOptions\n): string {\n const { locale = 'en-US', timeZone } = options;\n const dateFormat = 'date' in options ? options.date : undefined;\n const timeFormat = 'time' in options ? options.time : undefined;\n\n // Convert input to ZonedDateTime for consistent handling\n let zdt: Temporal.ZonedDateTime;\n\n if (input instanceof Temporal.Instant) {\n const tz = timeZone ?? 'UTC';\n zdt = input.toZonedDateTimeISO(tz);\n } else if (input instanceof Temporal.ZonedDateTime) {\n if (timeZone) {\n zdt = input.toInstant().toZonedDateTimeISO(timeZone);\n } else {\n zdt = input;\n }\n } else {\n // PlainDate - convert to ZonedDateTime at midnight UTC for formatting\n zdt = input.toZonedDateTime({ timeZone: timeZone ?? 'UTC', plainTime: new Temporal.PlainTime() });\n }\n\n const parts: string[] = [];\n\n // Format date part\n if (dateFormat) {\n const currentYear = Temporal.Now.plainDateISO().year;\n const showYear =\n dateFormat === 'full' ? true : dateFormat === 'compact' ? false : zdt.year !== currentYear;\n\n const dateOptions: Intl.DateTimeFormatOptions = {\n day: 'numeric',\n month: 'short',\n year: showYear ? 'numeric' : undefined,\n };\n\n parts.push(zdt.toLocaleString(locale, dateOptions));\n }\n\n // Format time part\n if (timeFormat) {\n if (timeFormat === 'compact') {\n parts.push(formatCompactTime(zdt));\n } else {\n const timeOptions: Intl.DateTimeFormatOptions = {\n hour: 'numeric',\n minute: '2-digit',\n hour12: timeFormat === '12h',\n };\n parts.push(zdt.toLocaleString(locale, timeOptions));\n }\n }\n\n return parts.join(', ');\n}\n\n/**\n * Format time in compact style: \"9am\" or \"2:30pm\"\n * Omits minutes when they're zero for cleaner display.\n */\nfunction formatCompactTime(zdt: Temporal.ZonedDateTime): string {\n const hour12 = zdt.hour % 12 || 12;\n const ampm = zdt.hour < 12 ? 'am' : 'pm';\n\n if (zdt.minute === 0) {\n return `${hour12}${ampm}`;\n }\n return `${hour12}:${zdt.minute.toString().padStart(2, '0')}${ampm}`;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAsElB,SAAS,aACd,OACA,SACQ;AACR,QAAM,EAAE,SAAS,SAAS,SAAS,IAAI;AACvC,QAAM,aAAa,UAAU,UAAU,QAAQ,OAAO;AACtD,QAAM,aAAa,UAAU,UAAU,QAAQ,OAAO;AAGtD,MAAI;AAEJ,MAAI,iBAAiB,SAAS,SAAS;AACrC,UAAM,KAAK,YAAY;AACvB,UAAM,MAAM,mBAAmB,EAAE;AAAA,EACnC,WAAW,iBAAiB,SAAS,eAAe;AAClD,QAAI,UAAU;AACZ,YAAM,MAAM,UAAU,EAAE,mBAAmB,QAAQ;AAAA,IACrD,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF,OAAO;AAEL,UAAM,MAAM,gBAAgB,EAAE,UAAU,YAAY,OAAO,WAAW,IAAI,SAAS,UAAU,EAAE,CAAC;AAAA,EAClG;AAEA,QAAM,QAAkB,CAAC;AAGzB,MAAI,YAAY;AACd,UAAM,cAAc,SAAS,IAAI,aAAa,EAAE;AAChD,UAAM,WACJ,eAAe,SAAS,OAAO,eAAe,YAAY,QAAQ,IAAI,SAAS;AAEjF,UAAM,cAA0C;AAAA,MAC9C,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM,WAAW,YAAY;AAAA,IAC/B;AAEA,UAAM,KAAK,IAAI,eAAe,QAAQ,WAAW,CAAC;AAAA,EACpD;AAGA,MAAI,YAAY;AACd,QAAI,eAAe,WAAW;AAC5B,YAAM,KAAK,kBAAkB,GAAG,CAAC;AAAA,IACnC,OAAO;AACL,YAAM,cAA0C;AAAA,QAC9C,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ,eAAe;AAAA,MACzB;AACA,YAAM,KAAK,IAAI,eAAe,QAAQ,WAAW,CAAC;AAAA,IACpD;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAMA,SAAS,kBAAkB,KAAqC;AAC9D,QAAM,SAAS,IAAI,OAAO,MAAM;AAChC,QAAM,OAAO,IAAI,OAAO,KAAK,OAAO;AAEpC,MAAI,IAAI,WAAW,GAAG;AACpB,WAAO,GAAG,MAAM,GAAG,IAAI;AAAA,EACzB;AACA,SAAO,GAAG,MAAM,IAAI,IAAI,OAAO,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,GAAG,IAAI;AACnE;","names":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of ZonedDateTime objects for each calendar day within the interval.
|
|
4
|
+
* Each element represents the start of day (midnight) in the timezone of the interval start.
|
|
5
|
+
* The interval is inclusive of both start and end days.
|
|
6
|
+
*
|
|
7
|
+
* For Instant inputs, UTC is used as the timezone.
|
|
8
|
+
* For ZonedDateTime inputs, the timezone of the start date is preserved.
|
|
9
|
+
*
|
|
10
|
+
* @param interval - The interval with start and end datetimes
|
|
11
|
+
* @returns Array of ZonedDateTime at start of each day in the interval
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const start = Temporal.ZonedDateTime.from('2025-01-06T10:00:00Z[UTC]');
|
|
16
|
+
* const end = Temporal.ZonedDateTime.from('2025-01-10T14:00:00Z[UTC]');
|
|
17
|
+
*
|
|
18
|
+
* const days = eachDayOfInterval({ start, end });
|
|
19
|
+
* // [
|
|
20
|
+
* // 2025-01-06T00:00:00Z[UTC],
|
|
21
|
+
* // 2025-01-07T00:00:00Z[UTC],
|
|
22
|
+
* // 2025-01-08T00:00:00Z[UTC],
|
|
23
|
+
* // 2025-01-09T00:00:00Z[UTC],
|
|
24
|
+
* // 2025-01-10T00:00:00Z[UTC]
|
|
25
|
+
* // ]
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // With timezone - preserves the timezone from start
|
|
31
|
+
* const start = Temporal.ZonedDateTime.from('2025-01-06T10:00:00-05:00[America/New_York]');
|
|
32
|
+
* const end = Temporal.ZonedDateTime.from('2025-01-08T14:00:00-05:00[America/New_York]');
|
|
33
|
+
*
|
|
34
|
+
* const days = eachDayOfInterval({ start, end });
|
|
35
|
+
* // [
|
|
36
|
+
* // 2025-01-06T00:00:00-05:00[America/New_York],
|
|
37
|
+
* // 2025-01-07T00:00:00-05:00[America/New_York],
|
|
38
|
+
* // 2025-01-08T00:00:00-05:00[America/New_York]
|
|
39
|
+
* // ]
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* // With Instant (uses UTC)
|
|
45
|
+
* const start = Temporal.Instant.from('2025-01-06T00:00:00Z');
|
|
46
|
+
* const end = Temporal.Instant.from('2025-01-08T00:00:00Z');
|
|
47
|
+
*
|
|
48
|
+
* const days = eachDayOfInterval({ start, end });
|
|
49
|
+
* // [
|
|
50
|
+
* // 2025-01-06T00:00:00Z[UTC],
|
|
51
|
+
* // 2025-01-07T00:00:00Z[UTC],
|
|
52
|
+
* // 2025-01-08T00:00:00Z[UTC]
|
|
53
|
+
* // ]
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Single day interval
|
|
59
|
+
* const date = Temporal.ZonedDateTime.from('2025-01-15T12:00:00Z[UTC]');
|
|
60
|
+
*
|
|
61
|
+
* eachDayOfInterval({ start: date, end: date });
|
|
62
|
+
* // [2025-01-15T00:00:00Z[UTC]]
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function eachDayOfInterval(interval: {
|
|
66
|
+
start: Temporal.Instant | Temporal.ZonedDateTime;
|
|
67
|
+
end: Temporal.Instant | Temporal.ZonedDateTime;
|
|
68
|
+
}): Temporal.ZonedDateTime[];
|
|
69
|
+
//# sourceMappingURL=eachDayOfInterval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eachDayOfInterval.d.ts","sourceRoot":"","sources":["../src/eachDayOfInterval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE;IAC1C,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;IACjD,GAAG,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;CAChD,GAAG,QAAQ,CAAC,aAAa,EAAE,CAiB3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eachDayOfInterval.test.d.ts","sourceRoot":"","sources":["../src/eachDayOfInterval.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of ZonedDateTime objects for each hour within the interval.
|
|
4
|
+
* Each element represents the start of the hour (minute/second/etc. set to 0).
|
|
5
|
+
* The interval is inclusive of both start and end hours.
|
|
6
|
+
*
|
|
7
|
+
* For Instant inputs, UTC is used as the timezone.
|
|
8
|
+
* For ZonedDateTime inputs, the timezone of the start date is preserved.
|
|
9
|
+
*
|
|
10
|
+
* Note: During DST transitions, some hours may be skipped (spring forward) or
|
|
11
|
+
* the array may contain fewer/more hours than expected based on wall-clock time.
|
|
12
|
+
*
|
|
13
|
+
* @param interval - The interval with start and end datetimes
|
|
14
|
+
* @returns Array of ZonedDateTime at start of each hour in the interval
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const start = Temporal.ZonedDateTime.from('2025-01-06T10:30:00Z[UTC]');
|
|
19
|
+
* const end = Temporal.ZonedDateTime.from('2025-01-06T14:15:00Z[UTC]');
|
|
20
|
+
*
|
|
21
|
+
* const hours = eachHourOfInterval({ start, end });
|
|
22
|
+
* // [
|
|
23
|
+
* // 2025-01-06T10:00:00Z[UTC],
|
|
24
|
+
* // 2025-01-06T11:00:00Z[UTC],
|
|
25
|
+
* // 2025-01-06T12:00:00Z[UTC],
|
|
26
|
+
* // 2025-01-06T13:00:00Z[UTC],
|
|
27
|
+
* // 2025-01-06T14:00:00Z[UTC]
|
|
28
|
+
* // ]
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* // Cross-day boundary
|
|
34
|
+
* const start = Temporal.ZonedDateTime.from('2025-01-06T22:00:00Z[UTC]');
|
|
35
|
+
* const end = Temporal.ZonedDateTime.from('2025-01-07T02:00:00Z[UTC]');
|
|
36
|
+
*
|
|
37
|
+
* const hours = eachHourOfInterval({ start, end });
|
|
38
|
+
* // [
|
|
39
|
+
* // 2025-01-06T22:00:00Z[UTC],
|
|
40
|
+
* // 2025-01-06T23:00:00Z[UTC],
|
|
41
|
+
* // 2025-01-07T00:00:00Z[UTC],
|
|
42
|
+
* // 2025-01-07T01:00:00Z[UTC],
|
|
43
|
+
* // 2025-01-07T02:00:00Z[UTC]
|
|
44
|
+
* // ]
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function eachHourOfInterval(interval: {
|
|
48
|
+
start: Temporal.Instant | Temporal.ZonedDateTime;
|
|
49
|
+
end: Temporal.Instant | Temporal.ZonedDateTime;
|
|
50
|
+
}): Temporal.ZonedDateTime[];
|
|
51
|
+
//# sourceMappingURL=eachHourOfInterval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eachHourOfInterval.d.ts","sourceRoot":"","sources":["../src/eachHourOfInterval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE;IAC3C,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;IACjD,GAAG,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;CAChD,GAAG,QAAQ,CAAC,aAAa,EAAE,CAsB3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eachHourOfInterval.test.d.ts","sourceRoot":"","sources":["../src/eachHourOfInterval.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of ZonedDateTime objects for each minute within the interval.
|
|
4
|
+
* Each element represents the start of the minute (seconds/etc. set to 0).
|
|
5
|
+
* The interval is inclusive of both start and end minutes.
|
|
6
|
+
*
|
|
7
|
+
* For Instant inputs, UTC is used as the timezone.
|
|
8
|
+
* For ZonedDateTime inputs, the timezone of the start date is preserved.
|
|
9
|
+
*
|
|
10
|
+
* Warning: Large intervals can produce very large arrays. For example, a 24-hour
|
|
11
|
+
* interval produces 1,441 elements. Consider whether this is appropriate for your use case.
|
|
12
|
+
*
|
|
13
|
+
* @param interval - The interval with start and end datetimes
|
|
14
|
+
* @returns Array of ZonedDateTime at start of each minute in the interval
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const start = Temporal.ZonedDateTime.from('2025-01-06T10:30:00Z[UTC]');
|
|
19
|
+
* const end = Temporal.ZonedDateTime.from('2025-01-06T10:33:45Z[UTC]');
|
|
20
|
+
*
|
|
21
|
+
* const minutes = eachMinuteOfInterval({ start, end });
|
|
22
|
+
* // [
|
|
23
|
+
* // 2025-01-06T10:30:00Z[UTC],
|
|
24
|
+
* // 2025-01-06T10:31:00Z[UTC],
|
|
25
|
+
* // 2025-01-06T10:32:00Z[UTC],
|
|
26
|
+
* // 2025-01-06T10:33:00Z[UTC]
|
|
27
|
+
* // ]
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // Cross-hour boundary
|
|
33
|
+
* const start = Temporal.ZonedDateTime.from('2025-01-06T10:58:00Z[UTC]');
|
|
34
|
+
* const end = Temporal.ZonedDateTime.from('2025-01-06T11:02:00Z[UTC]');
|
|
35
|
+
*
|
|
36
|
+
* const minutes = eachMinuteOfInterval({ start, end });
|
|
37
|
+
* // [
|
|
38
|
+
* // 2025-01-06T10:58:00Z[UTC],
|
|
39
|
+
* // 2025-01-06T10:59:00Z[UTC],
|
|
40
|
+
* // 2025-01-06T11:00:00Z[UTC],
|
|
41
|
+
* // 2025-01-06T11:01:00Z[UTC],
|
|
42
|
+
* // 2025-01-06T11:02:00Z[UTC]
|
|
43
|
+
* // ]
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function eachMinuteOfInterval(interval: {
|
|
47
|
+
start: Temporal.Instant | Temporal.ZonedDateTime;
|
|
48
|
+
end: Temporal.Instant | Temporal.ZonedDateTime;
|
|
49
|
+
}): Temporal.ZonedDateTime[];
|
|
50
|
+
//# sourceMappingURL=eachMinuteOfInterval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eachMinuteOfInterval.d.ts","sourceRoot":"","sources":["../src/eachMinuteOfInterval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE;IAC7C,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;IACjD,GAAG,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC;CAChD,GAAG,QAAQ,CAAC,aAAa,EAAE,CAsB3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eachMinuteOfInterval.test.d.ts","sourceRoot":"","sources":["../src/eachMinuteOfInterval.test.ts"],"names":[],"mappings":""}
|