@gobrand/tiempo 2.5.3 → 2.6.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-7GEIOKVQ.js +19 -0
- package/dist/chunk-7GEIOKVQ.js.map +1 -0
- package/dist/chunk-EZ7NVTZI.js +21 -0
- package/dist/chunk-EZ7NVTZI.js.map +1 -0
- package/dist/chunk-GFWC7CHD.js +21 -0
- package/dist/chunk-GFWC7CHD.js.map +1 -0
- package/dist/{chunk-XDVUGTUV.js → chunk-GLGAVKGV.js} +7 -3
- package/dist/chunk-GLGAVKGV.js.map +1 -0
- package/dist/chunk-HFQUXON5.js +41 -0
- package/dist/chunk-HFQUXON5.js.map +1 -0
- package/dist/chunk-ID52RFFD.js +19 -0
- package/dist/chunk-ID52RFFD.js.map +1 -0
- package/dist/chunk-JHRXY36W.js +25 -0
- package/dist/chunk-JHRXY36W.js.map +1 -0
- package/dist/chunk-JNA3AFOC.js +13 -0
- package/dist/chunk-JNA3AFOC.js.map +1 -0
- package/dist/chunk-MMI2HHT7.js +25 -0
- package/dist/chunk-MMI2HHT7.js.map +1 -0
- package/dist/chunk-PWISCOZV.js +23 -0
- package/dist/chunk-PWISCOZV.js.map +1 -0
- package/dist/chunk-UJW2FPI4.js +25 -0
- package/dist/chunk-UJW2FPI4.js.map +1 -0
- package/dist/chunk-UJWM2BV2.js +41 -0
- package/dist/chunk-UJWM2BV2.js.map +1 -0
- package/dist/chunk-X26WIJ6L.js +24 -0
- package/dist/chunk-X26WIJ6L.js.map +1 -0
- package/dist/chunk-XPJFOBPW.js +24 -0
- package/dist/chunk-XPJFOBPW.js.map +1 -0
- package/dist/endOfDay.d.ts +5 -4
- package/dist/endOfDay.d.ts.map +1 -1
- package/dist/endOfDay.js +2 -1
- package/dist/endOfMonth.d.ts +7 -6
- package/dist/endOfMonth.d.ts.map +1 -1
- package/dist/endOfMonth.js +2 -1
- package/dist/endOfWeek.d.ts +7 -6
- package/dist/endOfWeek.d.ts.map +1 -1
- package/dist/endOfWeek.js +2 -1
- package/dist/endOfYear.d.ts +6 -5
- package/dist/endOfYear.d.ts.map +1 -1
- package/dist/endOfYear.js +2 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -30
- package/dist/roundToNearestHour.d.ts +77 -0
- package/dist/roundToNearestHour.d.ts.map +1 -0
- package/dist/roundToNearestHour.js +8 -0
- package/dist/roundToNearestHour.js.map +1 -0
- package/dist/roundToNearestHour.test.d.ts +2 -0
- package/dist/roundToNearestHour.test.d.ts.map +1 -0
- package/dist/roundToNearestMinute.d.ts +76 -0
- package/dist/roundToNearestMinute.d.ts.map +1 -0
- package/dist/roundToNearestMinute.js +8 -0
- package/dist/roundToNearestMinute.js.map +1 -0
- package/dist/roundToNearestMinute.test.d.ts +2 -0
- package/dist/roundToNearestMinute.test.d.ts.map +1 -0
- package/dist/roundToNearestSecond.d.ts +75 -0
- package/dist/roundToNearestSecond.d.ts.map +1 -0
- package/dist/roundToNearestSecond.js +8 -0
- package/dist/roundToNearestSecond.js.map +1 -0
- package/dist/roundToNearestSecond.test.d.ts +2 -0
- package/dist/roundToNearestSecond.test.d.ts.map +1 -0
- package/dist/shared/plainDateToZonedDateTime.d.ts +9 -0
- package/dist/shared/plainDateToZonedDateTime.d.ts.map +1 -0
- package/dist/shared/plainDateToZonedDateTime.js +7 -0
- package/dist/shared/plainDateToZonedDateTime.js.map +1 -0
- package/dist/startOfDay.d.ts +6 -5
- package/dist/startOfDay.d.ts.map +1 -1
- package/dist/startOfDay.js +2 -1
- package/dist/startOfMonth.d.ts +6 -5
- package/dist/startOfMonth.d.ts.map +1 -1
- package/dist/startOfMonth.js +2 -1
- package/dist/startOfWeek.d.ts +7 -6
- package/dist/startOfWeek.d.ts.map +1 -1
- package/dist/startOfWeek.js +2 -1
- package/dist/startOfYear.d.ts +6 -5
- package/dist/startOfYear.d.ts.map +1 -1
- package/dist/startOfYear.js +2 -1
- package/dist/toPlainDate.d.ts +14 -7
- package/dist/toPlainDate.d.ts.map +1 -1
- package/dist/toPlainDate.js +1 -1
- package/dist/toPlainTime.d.ts +15 -7
- package/dist/toPlainTime.d.ts.map +1 -1
- package/dist/toPlainTime.js +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-2WMXB7QL.js +0 -17
- package/dist/chunk-2WMXB7QL.js.map +0 -1
- package/dist/chunk-CUMB4776.js +0 -18
- package/dist/chunk-CUMB4776.js.map +0 -1
- package/dist/chunk-G45S5B4O.js +0 -25
- package/dist/chunk-G45S5B4O.js.map +0 -1
- package/dist/chunk-GM6RNAYE.js +0 -19
- package/dist/chunk-GM6RNAYE.js.map +0 -1
- package/dist/chunk-TU2UNOOW.js +0 -15
- package/dist/chunk-TU2UNOOW.js.map +0 -1
- package/dist/chunk-TW5EV3DH.js +0 -14
- package/dist/chunk-TW5EV3DH.js.map +0 -1
- package/dist/chunk-UCCWUJ2K.js +0 -25
- package/dist/chunk-UCCWUJ2K.js.map +0 -1
- package/dist/chunk-XDVUGTUV.js.map +0 -1
- package/dist/chunk-XVJJR7H6.js +0 -20
- package/dist/chunk-XVJJR7H6.js.map +0 -1
- package/dist/chunk-YR2UCUIT.js +0 -15
- package/dist/chunk-YR2UCUIT.js.map +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
plainDateToZonedDateTime
|
|
3
|
+
} from "./chunk-JNA3AFOC.js";
|
|
4
|
+
import {
|
|
5
|
+
normalizeTemporalInput
|
|
6
|
+
} from "./chunk-MJSZNWCV.js";
|
|
7
|
+
|
|
8
|
+
// src/startOfMonth.ts
|
|
9
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
10
|
+
function startOfMonth(input, timezone) {
|
|
11
|
+
const zonedDateTime = input instanceof Temporal.PlainDate ? plainDateToZonedDateTime(input, timezone) : normalizeTemporalInput(input);
|
|
12
|
+
const firstDay = zonedDateTime.with({ day: 1 });
|
|
13
|
+
return firstDay.startOfDay();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
startOfMonth
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-7GEIOKVQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/startOfMonth.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\nimport { plainDateToZonedDateTime } from './shared/plainDateToZonedDateTime';\n\n/**\n * Returns a ZonedDateTime representing the first moment of the month (day 1 at midnight).\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @returns ZonedDateTime at the 1st day of the month at 00:00:00.000000000\n *\n * @example\n * ```ts\n * // From Instant (always UTC)\n * const instant = Temporal.Instant.from('2025-01-15T12:00:00Z');\n * const start = startOfMonth(instant);\n * // 2025-01-01T00:00:00Z[UTC]\n * ```\n *\n * @example\n * ```ts\n * // From ZonedDateTime (uses its timezone)\n * const zoned = Temporal.ZonedDateTime.from('2025-01-15T15:30:00-05:00[America/New_York]');\n * const start = startOfMonth(zoned);\n * // 2025-01-01T00:00:00-05:00[America/New_York]\n * ```\n *\n * @example\n * ```ts\n * // From PlainDate (requires timezone)\n * const date = Temporal.PlainDate.from('2025-01-15');\n * const start = startOfMonth(date, 'America/New_York');\n * // 2025-01-01T00:00:00-05:00[America/New_York]\n * ```\n */\nexport function startOfMonth(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Temporal.ZonedDateTime;\nexport function startOfMonth(\n input: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime;\nexport function startOfMonth(\n input: Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDate,\n timezone?: Timezone\n): Temporal.ZonedDateTime {\n const zonedDateTime =\n input instanceof Temporal.PlainDate\n ? plainDateToZonedDateTime(input, timezone!)\n : normalizeTemporalInput(input);\n\n // Set day to 1, then get start of that day\n const firstDay = zonedDateTime.with({ day: 1 });\n\n return firstDay.startOfDay();\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AA0ClB,SAAS,aACd,OACA,UACwB;AACxB,QAAM,gBACJ,iBAAiB,SAAS,YACtB,yBAAyB,OAAO,QAAS,IACzC,uBAAuB,KAAK;AAGlC,QAAM,WAAW,cAAc,KAAK,EAAE,KAAK,EAAE,CAAC;AAE9C,SAAO,SAAS,WAAW;AAC7B;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
plainDateToZonedDateTime
|
|
3
|
+
} from "./chunk-JNA3AFOC.js";
|
|
4
|
+
import {
|
|
5
|
+
normalizeTemporalInput
|
|
6
|
+
} from "./chunk-MJSZNWCV.js";
|
|
7
|
+
|
|
8
|
+
// src/startOfWeek.ts
|
|
9
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
10
|
+
function startOfWeek(input, timezone) {
|
|
11
|
+
const zonedDateTime = input instanceof Temporal.PlainDate ? plainDateToZonedDateTime(input, timezone) : normalizeTemporalInput(input);
|
|
12
|
+
const dayOfWeek = zonedDateTime.dayOfWeek;
|
|
13
|
+
const daysToSubtract = dayOfWeek - 1;
|
|
14
|
+
const monday = zonedDateTime.subtract({ days: daysToSubtract });
|
|
15
|
+
return monday.startOfDay();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
startOfWeek
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-EZ7NVTZI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/startOfWeek.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\nimport { plainDateToZonedDateTime } from './shared/plainDateToZonedDateTime';\n\n/**\n * Returns a ZonedDateTime representing the first moment of the week (Monday at midnight).\n * Uses ISO 8601 week definition: weeks start on Monday.\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @returns ZonedDateTime at Monday 00:00:00.000000000\n *\n * @example\n * ```ts\n * // From Instant (always UTC)\n * const instant = Temporal.Instant.from('2025-01-20T12:00:00Z'); // Monday\n * const start = startOfWeek(instant);\n * // 2025-01-20T00:00:00Z[UTC] (same day, it's already Monday)\n * ```\n *\n * @example\n * ```ts\n * // From ZonedDateTime (uses its timezone)\n * const zoned = Temporal.ZonedDateTime.from('2025-01-22T15:30:00-05:00[America/New_York]'); // Wednesday\n * const start = startOfWeek(zoned);\n * // 2025-01-20T00:00:00-05:00[America/New_York] (previous Monday)\n * ```\n *\n * @example\n * ```ts\n * // From PlainDate (requires timezone)\n * const date = Temporal.PlainDate.from('2025-01-22'); // Wednesday\n * const start = startOfWeek(date, 'America/New_York');\n * // 2025-01-20T00:00:00-05:00[America/New_York] (previous Monday)\n * ```\n */\nexport function startOfWeek(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Temporal.ZonedDateTime;\nexport function startOfWeek(\n input: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime;\nexport function startOfWeek(\n input: Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDate,\n timezone?: Timezone\n): Temporal.ZonedDateTime {\n const zonedDateTime =\n input instanceof Temporal.PlainDate\n ? plainDateToZonedDateTime(input, timezone!)\n : normalizeTemporalInput(input);\n\n // Get the day of week (1 = Monday, 7 = Sunday in ISO 8601)\n const dayOfWeek = zonedDateTime.dayOfWeek;\n\n // Calculate days to subtract to get to Monday\n const daysToSubtract = dayOfWeek - 1;\n\n // Go to Monday, then get start of that day\n const monday = zonedDateTime.subtract({ days: daysToSubtract });\n\n return monday.startOfDay();\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AA2ClB,SAAS,YACd,OACA,UACwB;AACxB,QAAM,gBACJ,iBAAiB,SAAS,YACtB,yBAAyB,OAAO,QAAS,IACzC,uBAAuB,KAAK;AAGlC,QAAM,YAAY,cAAc;AAGhC,QAAM,iBAAiB,YAAY;AAGnC,QAAM,SAAS,cAAc,SAAS,EAAE,MAAM,eAAe,CAAC;AAE9D,SAAO,OAAO,WAAW;AAC3B;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
plainDateToZonedDateTime
|
|
3
|
+
} from "./chunk-JNA3AFOC.js";
|
|
4
|
+
import {
|
|
5
|
+
normalizeTemporalInput
|
|
6
|
+
} from "./chunk-MJSZNWCV.js";
|
|
7
|
+
|
|
8
|
+
// src/startOfDay.ts
|
|
9
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
10
|
+
function startOfDay(input, timezone) {
|
|
11
|
+
if (input instanceof Temporal.PlainDate) {
|
|
12
|
+
return plainDateToZonedDateTime(input, timezone).startOfDay();
|
|
13
|
+
}
|
|
14
|
+
const zonedDateTime = normalizeTemporalInput(input);
|
|
15
|
+
return zonedDateTime.startOfDay();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
startOfDay
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-GFWC7CHD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/startOfDay.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\nimport { plainDateToZonedDateTime } from './shared/plainDateToZonedDateTime';\n\n/**\n * Returns a ZonedDateTime representing the first moment of the day (midnight).\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @returns ZonedDateTime at 00:00:00.000000000\n *\n * @example\n * ```ts\n * // From Instant (always UTC)\n * const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');\n * const start = startOfDay(instant);\n * // 2025-01-20T00:00:00Z[UTC]\n * ```\n *\n * @example\n * ```ts\n * // From ZonedDateTime (uses its timezone)\n * const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');\n * const start = startOfDay(zoned);\n * // 2025-01-20T00:00:00-05:00[America/New_York]\n * ```\n *\n * @example\n * ```ts\n * // From PlainDate (requires timezone)\n * const date = Temporal.PlainDate.from('2025-01-20');\n * const start = startOfDay(date, 'America/New_York');\n * // 2025-01-20T00:00:00-05:00[America/New_York]\n * ```\n */\nexport function startOfDay(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Temporal.ZonedDateTime;\nexport function startOfDay(\n input: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime;\nexport function startOfDay(\n input: Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDate,\n timezone?: Timezone\n): Temporal.ZonedDateTime {\n if (input instanceof Temporal.PlainDate) {\n return plainDateToZonedDateTime(input, timezone!).startOfDay();\n }\n\n const zonedDateTime = normalizeTemporalInput(input);\n return zonedDateTime.startOfDay();\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AA0ClB,SAAS,WACd,OACA,UACwB;AACxB,MAAI,iBAAiB,SAAS,WAAW;AACvC,WAAO,yBAAyB,OAAO,QAAS,EAAE,WAAW;AAAA,EAC/D;AAEA,QAAM,gBAAgB,uBAAuB,KAAK;AAClD,SAAO,cAAc,WAAW;AAClC;","names":[]}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getEndOfDay
|
|
3
3
|
} from "./chunk-AVGNRINZ.js";
|
|
4
|
+
import {
|
|
5
|
+
plainDateToZonedDateTime
|
|
6
|
+
} from "./chunk-JNA3AFOC.js";
|
|
4
7
|
import {
|
|
5
8
|
normalizeTemporalInput
|
|
6
9
|
} from "./chunk-MJSZNWCV.js";
|
|
7
10
|
|
|
8
11
|
// src/endOfYear.ts
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
13
|
+
function endOfYear(input, timezone) {
|
|
14
|
+
const zonedDateTime = input instanceof Temporal.PlainDate ? plainDateToZonedDateTime(input, timezone) : normalizeTemporalInput(input);
|
|
11
15
|
const monthsInYear = zonedDateTime.monthsInYear;
|
|
12
16
|
const lastMonth = zonedDateTime.with({ month: monthsInYear });
|
|
13
17
|
const lastDay = lastMonth.with({ day: lastMonth.daysInMonth });
|
|
@@ -17,4 +21,4 @@ function endOfYear(input) {
|
|
|
17
21
|
export {
|
|
18
22
|
endOfYear
|
|
19
23
|
};
|
|
20
|
-
//# sourceMappingURL=chunk-
|
|
24
|
+
//# sourceMappingURL=chunk-GLGAVKGV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/endOfYear.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\nimport { getEndOfDay } from './shared/endOfDay';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\nimport { plainDateToZonedDateTime } from './shared/plainDateToZonedDateTime';\n\n/**\n * Returns a ZonedDateTime representing the last moment of the year (last day at 23:59:59.999999999).\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @returns ZonedDateTime at the last day of the year at 23:59:59.999999999\n *\n * @example\n * ```ts\n * // From Instant (always UTC)\n * const instant = Temporal.Instant.from('2025-06-15T12:00:00Z');\n * const end = endOfYear(instant);\n * // 2025-12-31T23:59:59.999999999Z[UTC]\n * ```\n *\n * @example\n * ```ts\n * // From ZonedDateTime (uses its timezone)\n * const zoned = Temporal.ZonedDateTime.from('2025-06-15T15:30:00-05:00[America/New_York]');\n * const end = endOfYear(zoned);\n * // 2025-12-31T23:59:59.999999999-05:00[America/New_York]\n * ```\n *\n * @example\n * ```ts\n * // From PlainDate (requires timezone)\n * const date = Temporal.PlainDate.from('2025-06-15');\n * const end = endOfYear(date, 'America/New_York');\n * // 2025-12-31T23:59:59.999999999-05:00[America/New_York]\n * ```\n */\nexport function endOfYear(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Temporal.ZonedDateTime;\nexport function endOfYear(\n input: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime;\nexport function endOfYear(\n input: Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDate,\n timezone?: Timezone\n): Temporal.ZonedDateTime {\n const zonedDateTime =\n input instanceof Temporal.PlainDate\n ? plainDateToZonedDateTime(input, timezone!)\n : normalizeTemporalInput(input);\n\n // Get the number of months in this year\n const monthsInYear = zonedDateTime.monthsInYear;\n\n // Set to last month, then get last day of that month\n const lastMonth = zonedDateTime.with({ month: monthsInYear });\n const lastDay = lastMonth.with({ day: lastMonth.daysInMonth });\n\n return getEndOfDay(lastDay);\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,gBAAgB;AA2ClB,SAAS,UACd,OACA,UACwB;AACxB,QAAM,gBACJ,iBAAiB,SAAS,YACtB,yBAAyB,OAAO,QAAS,IACzC,uBAAuB,KAAK;AAGlC,QAAM,eAAe,cAAc;AAGnC,QAAM,YAAY,cAAc,KAAK,EAAE,OAAO,aAAa,CAAC;AAC5D,QAAM,UAAU,UAAU,KAAK,EAAE,KAAK,UAAU,YAAY,CAAC;AAE7D,SAAO,YAAY,OAAO;AAC5B;","names":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/toPlainDate.ts
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
var PLAIN_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
4
|
+
function toPlainDate(input, timezone) {
|
|
5
|
+
if (input instanceof Temporal.ZonedDateTime && timezone === void 0) {
|
|
6
|
+
return input.toPlainDate();
|
|
7
|
+
}
|
|
8
|
+
if (input instanceof Date) {
|
|
9
|
+
if (timezone === void 0) {
|
|
10
|
+
throw new Error("Timezone is required unless input is a ZonedDateTime, PlainDateLike, or plain date string");
|
|
11
|
+
}
|
|
12
|
+
return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone).toPlainDate();
|
|
13
|
+
}
|
|
14
|
+
if (input instanceof Temporal.Instant) {
|
|
15
|
+
if (timezone === void 0) {
|
|
16
|
+
throw new Error("Timezone is required unless input is a ZonedDateTime, PlainDateLike, or plain date string");
|
|
17
|
+
}
|
|
18
|
+
return input.toZonedDateTimeISO(timezone).toPlainDate();
|
|
19
|
+
}
|
|
20
|
+
if (input instanceof Temporal.ZonedDateTime) {
|
|
21
|
+
if (timezone === void 0) {
|
|
22
|
+
throw new Error("Timezone is required unless input is a ZonedDateTime, PlainDateLike, or plain date string");
|
|
23
|
+
}
|
|
24
|
+
return input.toInstant().toZonedDateTimeISO(timezone).toPlainDate();
|
|
25
|
+
}
|
|
26
|
+
if (typeof input === "string") {
|
|
27
|
+
if (timezone !== void 0) {
|
|
28
|
+
return Temporal.Instant.from(input).toZonedDateTimeISO(timezone).toPlainDate();
|
|
29
|
+
}
|
|
30
|
+
if (PLAIN_DATE_PATTERN.test(input)) {
|
|
31
|
+
return Temporal.PlainDate.from(input);
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Timezone is required unless input is a ZonedDateTime, PlainDateLike, or plain date string");
|
|
34
|
+
}
|
|
35
|
+
return Temporal.PlainDate.from(input);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
toPlainDate
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-HFQUXON5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/toPlainDate.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\n\n// Pattern to detect plain date strings: YYYY-MM-DD\nconst PLAIN_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}$/;\n\n/**\n * Parse a plain date or extract the calendar date from a datetime.\n *\n * @param input - A PlainDateLike object, plain date string (YYYY-MM-DD), ZonedDateTime, or datetime input requiring timezone\n * @param timezone - IANA timezone identifier. Required for ISO strings, Date, and Instant inputs.\n * @returns A Temporal.PlainDate representing the calendar date\n *\n * @example\n * ```typescript\n * import { toPlainDate, toZonedTime } from '@gobrand/tiempo';\n *\n * // From PlainDateLike object (no timezone needed)\n * const date = toPlainDate({ year: 2025, month: 1, day: 20 }); // 2025-01-20\n *\n * // From plain date string (no timezone needed)\n * const date2 = toPlainDate(\"2025-01-20\"); // 2025-01-20\n *\n * // From ZonedDateTime (no timezone needed)\n * const zdt = toZonedTime(\"2025-01-20T15:30:00Z\", \"America/New_York\");\n * const date3 = toPlainDate(zdt); // 2025-01-20\n *\n * // From UTC string with timezone\n * const date4 = toPlainDate(\"2025-01-20T15:30:00Z\", \"America/New_York\"); // 2025-01-20\n *\n * // From Date with timezone\n * const jsDate = new Date(\"2025-01-20T15:30:00.000Z\");\n * const date5 = toPlainDate(jsDate, \"Europe/London\"); // 2025-01-20\n *\n * // Date boundary crossing: 23:00 UTC on Jan 20 → Jan 21 in Tokyo\n * const date6 = toPlainDate(\"2025-01-20T23:00:00Z\", \"Asia/Tokyo\"); // 2025-01-21\n * ```\n */\nexport function toPlainDate(input: Temporal.ZonedDateTime): Temporal.PlainDate;\nexport function toPlainDate(\n input: string | Date | Temporal.Instant | Temporal.ZonedDateTime,\n timezone: Timezone\n): Temporal.PlainDate;\nexport function toPlainDate(input: Temporal.PlainDateLike | string): Temporal.PlainDate;\nexport function toPlainDate(\n input: string | Date | Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDateLike,\n timezone?: Timezone\n): Temporal.PlainDate {\n // ZonedDateTime without timezone override\n if (input instanceof Temporal.ZonedDateTime && timezone === undefined) {\n return input.toPlainDate();\n }\n\n // Date requires timezone\n if (input instanceof Date) {\n if (timezone === undefined) {\n throw new Error('Timezone is required unless input is a ZonedDateTime, PlainDateLike, or plain date string');\n }\n return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone).toPlainDate();\n }\n\n // Instant requires timezone\n if (input instanceof Temporal.Instant) {\n if (timezone === undefined) {\n throw new Error('Timezone is required unless input is a ZonedDateTime, PlainDateLike, or plain date string');\n }\n return input.toZonedDateTimeISO(timezone).toPlainDate();\n }\n\n // ZonedDateTime with timezone override\n if (input instanceof Temporal.ZonedDateTime) {\n if (timezone === undefined) {\n throw new Error('Timezone is required unless input is a ZonedDateTime, PlainDateLike, or plain date string');\n }\n return input.toInstant().toZonedDateTimeISO(timezone).toPlainDate();\n }\n\n // String: ISO datetime (requires timezone) or plain date (no timezone)\n if (typeof input === 'string') {\n if (timezone !== undefined) {\n return Temporal.Instant.from(input).toZonedDateTimeISO(timezone).toPlainDate();\n }\n if (PLAIN_DATE_PATTERN.test(input)) {\n return Temporal.PlainDate.from(input);\n }\n throw new Error('Timezone is required unless input is a ZonedDateTime, PlainDateLike, or plain date string');\n }\n\n // PlainDateLike object - pass directly to Temporal.PlainDate.from()\n return Temporal.PlainDate.from(input);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAIzB,IAAM,qBAAqB;AAwCpB,SAAS,YACd,OACA,UACoB;AAEpB,MAAI,iBAAiB,SAAS,iBAAiB,aAAa,QAAW;AACrE,WAAO,MAAM,YAAY;AAAA,EAC3B;AAGA,MAAI,iBAAiB,MAAM;AACzB,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI,MAAM,2FAA2F;AAAA,IAC7G;AACA,WAAO,SAAS,QAAQ,KAAK,MAAM,YAAY,CAAC,EAAE,mBAAmB,QAAQ,EAAE,YAAY;AAAA,EAC7F;AAGA,MAAI,iBAAiB,SAAS,SAAS;AACrC,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI,MAAM,2FAA2F;AAAA,IAC7G;AACA,WAAO,MAAM,mBAAmB,QAAQ,EAAE,YAAY;AAAA,EACxD;AAGA,MAAI,iBAAiB,SAAS,eAAe;AAC3C,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI,MAAM,2FAA2F;AAAA,IAC7G;AACA,WAAO,MAAM,UAAU,EAAE,mBAAmB,QAAQ,EAAE,YAAY;AAAA,EACpE;AAGA,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI,aAAa,QAAW;AAC1B,aAAO,SAAS,QAAQ,KAAK,KAAK,EAAE,mBAAmB,QAAQ,EAAE,YAAY;AAAA,IAC/E;AACA,QAAI,mBAAmB,KAAK,KAAK,GAAG;AAClC,aAAO,SAAS,UAAU,KAAK,KAAK;AAAA,IACtC;AACA,UAAM,IAAI,MAAM,2FAA2F;AAAA,EAC7G;AAGA,SAAO,SAAS,UAAU,KAAK,KAAK;AACtC;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
plainDateToZonedDateTime
|
|
3
|
+
} from "./chunk-JNA3AFOC.js";
|
|
4
|
+
import {
|
|
5
|
+
normalizeTemporalInput
|
|
6
|
+
} from "./chunk-MJSZNWCV.js";
|
|
7
|
+
|
|
8
|
+
// src/startOfYear.ts
|
|
9
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
10
|
+
function startOfYear(input, timezone) {
|
|
11
|
+
const zonedDateTime = input instanceof Temporal.PlainDate ? plainDateToZonedDateTime(input, timezone) : normalizeTemporalInput(input);
|
|
12
|
+
const firstDay = zonedDateTime.with({ month: 1, day: 1 });
|
|
13
|
+
return firstDay.startOfDay();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
startOfYear
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-ID52RFFD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/startOfYear.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\nimport { plainDateToZonedDateTime } from './shared/plainDateToZonedDateTime';\n\n/**\n * Returns a ZonedDateTime representing the first moment of the year (January 1 at midnight).\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @returns ZonedDateTime at January 1st at 00:00:00.000000000\n *\n * @example\n * ```ts\n * // From Instant (always UTC)\n * const instant = Temporal.Instant.from('2025-06-15T12:00:00Z');\n * const start = startOfYear(instant);\n * // 2025-01-01T00:00:00Z[UTC]\n * ```\n *\n * @example\n * ```ts\n * // From ZonedDateTime (uses its timezone)\n * const zoned = Temporal.ZonedDateTime.from('2025-06-15T15:30:00-05:00[America/New_York]');\n * const start = startOfYear(zoned);\n * // 2025-01-01T00:00:00-05:00[America/New_York]\n * ```\n *\n * @example\n * ```ts\n * // From PlainDate (requires timezone)\n * const date = Temporal.PlainDate.from('2025-06-15');\n * const start = startOfYear(date, 'America/New_York');\n * // 2025-01-01T00:00:00-05:00[America/New_York]\n * ```\n */\nexport function startOfYear(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Temporal.ZonedDateTime;\nexport function startOfYear(\n input: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime;\nexport function startOfYear(\n input: Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDate,\n timezone?: Timezone\n): Temporal.ZonedDateTime {\n const zonedDateTime =\n input instanceof Temporal.PlainDate\n ? plainDateToZonedDateTime(input, timezone!)\n : normalizeTemporalInput(input);\n\n // Set to January 1st, then get start of that day\n const firstDay = zonedDateTime.with({ month: 1, day: 1 });\n\n return firstDay.startOfDay();\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AA0ClB,SAAS,YACd,OACA,UACwB;AACxB,QAAM,gBACJ,iBAAiB,SAAS,YACtB,yBAAyB,OAAO,QAAS,IACzC,uBAAuB,KAAK;AAGlC,QAAM,WAAW,cAAc,KAAK,EAAE,OAAO,GAAG,KAAK,EAAE,CAAC;AAExD,SAAO,SAAS,WAAW;AAC7B;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/roundToNearestSecond.ts
|
|
6
|
+
var MODE_TO_ROUNDING_MODE = {
|
|
7
|
+
round: "halfExpand",
|
|
8
|
+
ceil: "ceil",
|
|
9
|
+
floor: "floor"
|
|
10
|
+
};
|
|
11
|
+
function roundToNearestSecond(input, options) {
|
|
12
|
+
const zonedDateTime = normalizeTemporalInput(input);
|
|
13
|
+
const mode = options?.mode ?? "round";
|
|
14
|
+
const nearestTo = options?.nearestTo ?? 1;
|
|
15
|
+
return zonedDateTime.round({
|
|
16
|
+
smallestUnit: "second",
|
|
17
|
+
roundingMode: MODE_TO_ROUNDING_MODE[mode],
|
|
18
|
+
roundingIncrement: nearestTo
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
roundToNearestSecond
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-JHRXY36W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/roundToNearestSecond.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Options for rounding to nearest second.\n */\nexport interface RoundToNearestSecondOptions {\n /**\n * The rounding mode to use.\n *\n * Given time 14:37:42.300:\n * - `'round'` → 14:37:42 (300ms < 500, rounds DOWN to nearest)\n * - `'ceil'` → 14:37:43 (always rounds UP to next second)\n * - `'floor'` → 14:37:42 (always rounds DOWN to current second)\n *\n * Given time 14:37:42 with nearestTo: 10:\n * - `'round'` → 14:37:40 (42 is closer to 40 than 50)\n * - `'ceil'` → 14:37:50 (always rounds UP to next 10-sec mark)\n * - `'floor'` → 14:37:40 (always rounds DOWN to current 10-sec mark)\n *\n * @default 'round'\n */\n mode?: 'round' | 'ceil' | 'floor';\n /**\n * Round to the nearest N seconds. Must divide evenly into 60.\n * Valid values: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30\n * @example nearestTo: 10 rounds to 10-second marks (00, 10, 20, 30, 40, 50)\n */\n nearestTo?: 1 | 2 | 3 | 4 | 5 | 6 | 10 | 12 | 15 | 20 | 30;\n}\n\nconst MODE_TO_ROUNDING_MODE = {\n round: 'halfExpand',\n ceil: 'ceil',\n floor: 'floor',\n} as const;\n\n/**\n * Rounds a datetime to the nearest second boundary.\n *\n * ## Mode comparison (given 14:37:42.567)\n *\n * ```\n * :42 ─────────────────●─────────────── :43\n * .567\n *\n * 'round' → :43 (nearest second - 567ms >= 500)\n * 'ceil' → :43 (next second - always up)\n * 'floor' → :42 (current second - always down)\n * ```\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @param options - Rounding options\n * @returns ZonedDateTime rounded to the second boundary\n *\n * @example\n * ```ts\n * const time = Temporal.ZonedDateTime.from('2025-01-20T14:37:42.567[America/New_York]');\n *\n * roundToNearestSecond(time); // → 14:37:43 (567ms >= 500)\n * roundToNearestSecond(time, { mode: 'ceil' }); // → 14:37:43 (always up)\n * roundToNearestSecond(time, { mode: 'floor' }); // → 14:37:42 (always down)\n * ```\n *\n * @example\n * ```ts\n * // 10-second intervals\n * const time = Temporal.ZonedDateTime.from('2025-01-20T14:37:42[America/New_York]');\n *\n * roundToNearestSecond(time, { nearestTo: 10 }); // → 14:37:40 (nearest)\n * roundToNearestSecond(time, { mode: 'ceil', nearestTo: 10 }); // → 14:37:50 (next 10s)\n * roundToNearestSecond(time, { mode: 'floor', nearestTo: 10 }); // → 14:37:40 (current 10s)\n * ```\n *\n * @example\n * ```ts\n * // Remove sub-second precision for logging\n * const logTime = Temporal.ZonedDateTime.from('2025-01-20T14:37:42.123456789[UTC]');\n * roundToNearestSecond(logTime, { mode: 'floor' });\n * // → 14:37:42.000000000 (clean timestamp)\n * ```\n */\nexport function roundToNearestSecond(\n input: Temporal.Instant | Temporal.ZonedDateTime,\n options?: RoundToNearestSecondOptions\n): Temporal.ZonedDateTime {\n const zonedDateTime = normalizeTemporalInput(input);\n const mode = options?.mode ?? 'round';\n const nearestTo = options?.nearestTo ?? 1;\n\n return zonedDateTime.round({\n smallestUnit: 'second',\n roundingMode: MODE_TO_ROUNDING_MODE[mode],\n roundingIncrement: nearestTo,\n });\n}\n"],"mappings":";;;;;AA+BA,IAAM,wBAAwB;AAAA,EAC5B,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AACT;AA+CO,SAAS,qBACd,OACA,SACwB;AACxB,QAAM,gBAAgB,uBAAuB,KAAK;AAClD,QAAM,OAAO,SAAS,QAAQ;AAC9B,QAAM,YAAY,SAAS,aAAa;AAExC,SAAO,cAAc,MAAM;AAAA,IACzB,cAAc;AAAA,IACd,cAAc,sBAAsB,IAAI;AAAA,IACxC,mBAAmB;AAAA,EACrB,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/shared/plainDateToZonedDateTime.ts
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
function plainDateToZonedDateTime(date, timezone) {
|
|
4
|
+
return date.toZonedDateTime({
|
|
5
|
+
timeZone: timezone,
|
|
6
|
+
plainTime: Temporal.PlainTime.from("00:00")
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
plainDateToZonedDateTime
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-JNA3AFOC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/shared/plainDateToZonedDateTime.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from '../types';\n\n/**\n * @internal\n * Converts a PlainDate to a ZonedDateTime at midnight in the specified timezone.\n * This is an internal helper - do not use directly.\n */\nexport function plainDateToZonedDateTime(\n date: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime {\n return date.toZonedDateTime({\n timeZone: timezone,\n plainTime: Temporal.PlainTime.from('00:00'),\n });\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAQlB,SAAS,yBACd,MACA,UACwB;AACxB,SAAO,KAAK,gBAAgB;AAAA,IAC1B,UAAU;AAAA,IACV,WAAW,SAAS,UAAU,KAAK,OAAO;AAAA,EAC5C,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/roundToNearestHour.ts
|
|
6
|
+
var MODE_TO_ROUNDING_MODE = {
|
|
7
|
+
round: "halfExpand",
|
|
8
|
+
ceil: "ceil",
|
|
9
|
+
floor: "floor"
|
|
10
|
+
};
|
|
11
|
+
function roundToNearestHour(input, options) {
|
|
12
|
+
const zonedDateTime = normalizeTemporalInput(input);
|
|
13
|
+
const mode = options?.mode ?? "round";
|
|
14
|
+
const nearestTo = options?.nearestTo ?? 1;
|
|
15
|
+
return zonedDateTime.round({
|
|
16
|
+
smallestUnit: "hour",
|
|
17
|
+
roundingMode: MODE_TO_ROUNDING_MODE[mode],
|
|
18
|
+
roundingIncrement: nearestTo
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
roundToNearestHour
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-MMI2HHT7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/roundToNearestHour.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Options for rounding to nearest hour.\n */\nexport interface RoundToNearestHourOptions {\n /**\n * The rounding mode to use.\n *\n * Given time 14:20:\n * - `'round'` → 14:00 (20 min < 30, rounds DOWN to nearest)\n * - `'ceil'` → 15:00 (always rounds UP to next hour)\n * - `'floor'` → 14:00 (always rounds DOWN to current hour)\n *\n * Given time 14:40:\n * - `'round'` → 15:00 (40 min >= 30, rounds UP to nearest)\n * - `'ceil'` → 15:00 (always rounds UP to next hour)\n * - `'floor'` → 14:00 (always rounds DOWN to current hour)\n *\n * @default 'round'\n */\n mode?: 'round' | 'ceil' | 'floor';\n /**\n * Round to the nearest N hours. Must divide evenly into 24.\n * Valid values: 1, 2, 3, 4, 6, 8, 12\n * @example nearestTo: 6 rounds to 00:00, 06:00, 12:00, or 18:00\n */\n nearestTo?: 1 | 2 | 3 | 4 | 6 | 8 | 12;\n}\n\nconst MODE_TO_ROUNDING_MODE = {\n round: 'halfExpand',\n ceil: 'ceil',\n floor: 'floor',\n} as const;\n\n/**\n * Rounds a datetime to the nearest hour boundary.\n *\n * ## Mode comparison (given 14:20)\n *\n * ```\n * 14:00 ─────────────●───────────────── 15:00\n * 14:20\n *\n * 'round' → 14:00 (nearest hour - 20 min < 30)\n * 'ceil' → 15:00 (next hour - always up)\n * 'floor' → 14:00 (current hour - always down)\n * ```\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @param options - Rounding options\n * @returns ZonedDateTime rounded to the hour boundary\n *\n * @example\n * ```ts\n * const time = Temporal.ZonedDateTime.from('2025-01-20T14:20:00[America/New_York]');\n *\n * roundToNearestHour(time); // → 14:00 (nearest)\n * roundToNearestHour(time, { mode: 'ceil' }); // → 15:00 (always up)\n * roundToNearestHour(time, { mode: 'floor' }); // → 14:00 (always down)\n * ```\n *\n * @example\n * ```ts\n * // With 37 minutes (past the halfway point)\n * const time = Temporal.ZonedDateTime.from('2025-01-20T14:37:00[America/New_York]');\n *\n * roundToNearestHour(time); // → 15:00 (nearest - 37 >= 30)\n * roundToNearestHour(time, { mode: 'ceil' }); // → 15:00 (always up)\n * roundToNearestHour(time, { mode: 'floor' }); // → 14:00 (always down)\n * ```\n *\n * @example\n * ```ts\n * // Round to 6-hour blocks (shift scheduling)\n * const time = Temporal.ZonedDateTime.from('2025-01-20T14:00:00[America/New_York]');\n *\n * roundToNearestHour(time, { nearestTo: 6 }); // → 12:00\n * roundToNearestHour(time, { mode: 'ceil', nearestTo: 6 }); // → 18:00\n * roundToNearestHour(time, { mode: 'floor', nearestTo: 6 }); // → 12:00\n * ```\n */\nexport function roundToNearestHour(\n input: Temporal.Instant | Temporal.ZonedDateTime,\n options?: RoundToNearestHourOptions\n): Temporal.ZonedDateTime {\n const zonedDateTime = normalizeTemporalInput(input);\n const mode = options?.mode ?? 'round';\n const nearestTo = options?.nearestTo ?? 1;\n\n return zonedDateTime.round({\n smallestUnit: 'hour',\n roundingMode: MODE_TO_ROUNDING_MODE[mode],\n roundingIncrement: nearestTo,\n });\n}\n"],"mappings":";;;;;AA+BA,IAAM,wBAAwB;AAAA,EAC5B,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AACT;AAiDO,SAAS,mBACd,OACA,SACwB;AACxB,QAAM,gBAAgB,uBAAuB,KAAK;AAClD,QAAM,OAAO,SAAS,QAAQ;AAC9B,QAAM,YAAY,SAAS,aAAa;AAExC,SAAO,cAAc,MAAM;AAAA,IACzB,cAAc;AAAA,IACd,cAAc,sBAAsB,IAAI;AAAA,IACxC,mBAAmB;AAAA,EACrB,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEndOfDay
|
|
3
|
+
} from "./chunk-AVGNRINZ.js";
|
|
4
|
+
import {
|
|
5
|
+
plainDateToZonedDateTime
|
|
6
|
+
} from "./chunk-JNA3AFOC.js";
|
|
7
|
+
import {
|
|
8
|
+
normalizeTemporalInput
|
|
9
|
+
} from "./chunk-MJSZNWCV.js";
|
|
10
|
+
|
|
11
|
+
// src/endOfMonth.ts
|
|
12
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
13
|
+
function endOfMonth(input, timezone) {
|
|
14
|
+
const zonedDateTime = input instanceof Temporal.PlainDate ? plainDateToZonedDateTime(input, timezone) : normalizeTemporalInput(input);
|
|
15
|
+
const daysInMonth = zonedDateTime.daysInMonth;
|
|
16
|
+
const lastDay = zonedDateTime.with({ day: daysInMonth });
|
|
17
|
+
return getEndOfDay(lastDay);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
endOfMonth
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=chunk-PWISCOZV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/endOfMonth.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\nimport { getEndOfDay } from './shared/endOfDay';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\nimport { plainDateToZonedDateTime } from './shared/plainDateToZonedDateTime';\n\n/**\n * Returns a ZonedDateTime representing the last moment of the month (last day at 23:59:59.999999999).\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @returns ZonedDateTime at the last day of the month at 23:59:59.999999999\n *\n * @example\n * ```ts\n * // From Instant (always UTC)\n * const instant = Temporal.Instant.from('2025-01-15T12:00:00Z');\n * const end = endOfMonth(instant);\n * // 2025-01-31T23:59:59.999999999Z[UTC]\n * ```\n *\n * @example\n * ```ts\n * // From ZonedDateTime (uses its timezone)\n * const zoned = Temporal.ZonedDateTime.from('2025-02-15T15:30:00-05:00[America/New_York]');\n * const end = endOfMonth(zoned);\n * // 2025-02-28T23:59:59.999999999-05:00[America/New_York]\n * ```\n *\n * @example\n * ```ts\n * // From PlainDate (requires timezone)\n * const date = Temporal.PlainDate.from('2025-02-15');\n * const end = endOfMonth(date, 'America/New_York');\n * // 2025-02-28T23:59:59.999999999-05:00[America/New_York]\n * ```\n */\nexport function endOfMonth(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Temporal.ZonedDateTime;\nexport function endOfMonth(\n input: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime;\nexport function endOfMonth(\n input: Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDate,\n timezone?: Timezone\n): Temporal.ZonedDateTime {\n const zonedDateTime =\n input instanceof Temporal.PlainDate\n ? plainDateToZonedDateTime(input, timezone!)\n : normalizeTemporalInput(input);\n\n // Get the number of days in this month\n const daysInMonth = zonedDateTime.daysInMonth;\n\n // Set day to last day of month, then get end of that day\n const lastDay = zonedDateTime.with({ day: daysInMonth });\n\n return getEndOfDay(lastDay);\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,gBAAgB;AA2ClB,SAAS,WACd,OACA,UACwB;AACxB,QAAM,gBACJ,iBAAiB,SAAS,YACtB,yBAAyB,OAAO,QAAS,IACzC,uBAAuB,KAAK;AAGlC,QAAM,cAAc,cAAc;AAGlC,QAAM,UAAU,cAAc,KAAK,EAAE,KAAK,YAAY,CAAC;AAEvD,SAAO,YAAY,OAAO;AAC5B;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeTemporalInput
|
|
3
|
+
} from "./chunk-MJSZNWCV.js";
|
|
4
|
+
|
|
5
|
+
// src/roundToNearestMinute.ts
|
|
6
|
+
var MODE_TO_ROUNDING_MODE = {
|
|
7
|
+
round: "halfExpand",
|
|
8
|
+
ceil: "ceil",
|
|
9
|
+
floor: "floor"
|
|
10
|
+
};
|
|
11
|
+
function roundToNearestMinute(input, options) {
|
|
12
|
+
const zonedDateTime = normalizeTemporalInput(input);
|
|
13
|
+
const mode = options?.mode ?? "round";
|
|
14
|
+
const nearestTo = options?.nearestTo ?? 1;
|
|
15
|
+
return zonedDateTime.round({
|
|
16
|
+
smallestUnit: "minute",
|
|
17
|
+
roundingMode: MODE_TO_ROUNDING_MODE[mode],
|
|
18
|
+
roundingIncrement: nearestTo
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
roundToNearestMinute
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-UJW2FPI4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/roundToNearestMinute.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\n\n/**\n * Options for rounding to nearest minute.\n */\nexport interface RoundToNearestMinuteOptions {\n /**\n * The rounding mode to use.\n *\n * Given time 14:37:20:\n * - `'round'` → 14:37 (20 sec < 30, rounds DOWN to nearest)\n * - `'ceil'` → 14:38 (always rounds UP to next minute)\n * - `'floor'` → 14:37 (always rounds DOWN to current minute)\n *\n * Given time 14:37:00 with nearestTo: 15:\n * - `'round'` → 14:30 (37 is closer to 30 than 45)\n * - `'ceil'` → 14:45 (always rounds UP to next 15-min slot)\n * - `'floor'` → 14:30 (always rounds DOWN to current 15-min slot)\n *\n * @default 'round'\n */\n mode?: 'round' | 'ceil' | 'floor';\n /**\n * Round to the nearest N minutes. Must divide evenly into 60.\n * Valid values: 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30\n * @example nearestTo: 15 rounds to quarter-hour marks (00, 15, 30, 45)\n */\n nearestTo?: 1 | 2 | 3 | 4 | 5 | 6 | 10 | 12 | 15 | 20 | 30;\n}\n\nconst MODE_TO_ROUNDING_MODE = {\n round: 'halfExpand',\n ceil: 'ceil',\n floor: 'floor',\n} as const;\n\n/**\n * Rounds a datetime to the nearest minute boundary.\n *\n * ## Mode comparison (given 14:37 with 15-min slots)\n *\n * ```\n * 14:30 ─────────●───────────────────── 14:45\n * 14:37\n *\n * 'round' → 14:30 (nearest slot - 37 is closer to 30 than 45)\n * 'ceil' → 14:45 (next slot - always up)\n * 'floor' → 14:30 (current slot - always down)\n * ```\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @param options - Rounding options\n * @returns ZonedDateTime rounded to the minute boundary\n *\n * @example\n * ```ts\n * // 15-minute booking slots at 14:37\n * const time = Temporal.ZonedDateTime.from('2025-01-20T14:37:00[America/New_York]');\n *\n * roundToNearestMinute(time, { nearestTo: 15 }); // → 14:30 (nearest)\n * roundToNearestMinute(time, { mode: 'ceil', nearestTo: 15 }); // → 14:45 (next slot)\n * roundToNearestMinute(time, { mode: 'floor', nearestTo: 15 }); // → 14:30 (current slot)\n * ```\n *\n * @example\n * ```ts\n * // Basic minute rounding (no slots)\n * const time = Temporal.ZonedDateTime.from('2025-01-20T14:37:42[America/New_York]');\n *\n * roundToNearestMinute(time); // → 14:38 (42 sec >= 30)\n * roundToNearestMinute(time, { mode: 'ceil' }); // → 14:38 (always up)\n * roundToNearestMinute(time, { mode: 'floor' }); // → 14:37 (always down)\n * ```\n *\n * @example\n * ```ts\n * // Billing: round up to 30-minute increments\n * const sessionEnd = Temporal.ZonedDateTime.from('2025-01-20T11:07:00[America/New_York]');\n * roundToNearestMinute(sessionEnd, { mode: 'ceil', nearestTo: 30 });\n * // → 11:30 (bill for 30 mins even though session was 7 mins)\n * ```\n */\nexport function roundToNearestMinute(\n input: Temporal.Instant | Temporal.ZonedDateTime,\n options?: RoundToNearestMinuteOptions\n): Temporal.ZonedDateTime {\n const zonedDateTime = normalizeTemporalInput(input);\n const mode = options?.mode ?? 'round';\n const nearestTo = options?.nearestTo ?? 1;\n\n return zonedDateTime.round({\n smallestUnit: 'minute',\n roundingMode: MODE_TO_ROUNDING_MODE[mode],\n roundingIncrement: nearestTo,\n });\n}\n"],"mappings":";;;;;AA+BA,IAAM,wBAAwB;AAAA,EAC5B,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AACT;AAgDO,SAAS,qBACd,OACA,SACwB;AACxB,QAAM,gBAAgB,uBAAuB,KAAK;AAClD,QAAM,OAAO,SAAS,QAAQ;AAC9B,QAAM,YAAY,SAAS,aAAa;AAExC,SAAO,cAAc,MAAM;AAAA,IACzB,cAAc;AAAA,IACd,cAAc,sBAAsB,IAAI;AAAA,IACxC,mBAAmB;AAAA,EACrB,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/toPlainTime.ts
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
var PLAIN_TIME_PATTERN = /^\d{2}:\d{2}(:\d{2}(\.\d+)?)?$/;
|
|
4
|
+
function toPlainTime(input, timezone) {
|
|
5
|
+
if (input instanceof Temporal.ZonedDateTime && timezone === void 0) {
|
|
6
|
+
return input.toPlainTime();
|
|
7
|
+
}
|
|
8
|
+
if (input instanceof Date) {
|
|
9
|
+
if (timezone === void 0) {
|
|
10
|
+
throw new Error("Timezone is required unless input is a ZonedDateTime, PlainTimeLike, or plain time string");
|
|
11
|
+
}
|
|
12
|
+
return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone).toPlainTime();
|
|
13
|
+
}
|
|
14
|
+
if (input instanceof Temporal.Instant) {
|
|
15
|
+
if (timezone === void 0) {
|
|
16
|
+
throw new Error("Timezone is required unless input is a ZonedDateTime, PlainTimeLike, or plain time string");
|
|
17
|
+
}
|
|
18
|
+
return input.toZonedDateTimeISO(timezone).toPlainTime();
|
|
19
|
+
}
|
|
20
|
+
if (input instanceof Temporal.ZonedDateTime) {
|
|
21
|
+
if (timezone === void 0) {
|
|
22
|
+
throw new Error("Timezone is required unless input is a ZonedDateTime, PlainTimeLike, or plain time string");
|
|
23
|
+
}
|
|
24
|
+
return input.toInstant().toZonedDateTimeISO(timezone).toPlainTime();
|
|
25
|
+
}
|
|
26
|
+
if (typeof input === "string") {
|
|
27
|
+
if (timezone !== void 0) {
|
|
28
|
+
return Temporal.Instant.from(input).toZonedDateTimeISO(timezone).toPlainTime();
|
|
29
|
+
}
|
|
30
|
+
if (PLAIN_TIME_PATTERN.test(input)) {
|
|
31
|
+
return Temporal.PlainTime.from(input);
|
|
32
|
+
}
|
|
33
|
+
throw new Error("Timezone is required unless input is a ZonedDateTime, PlainTimeLike, or plain time string");
|
|
34
|
+
}
|
|
35
|
+
return Temporal.PlainTime.from(input);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
toPlainTime
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-UJWM2BV2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/toPlainTime.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\n\n// Pattern to detect plain time strings: HH:MM, HH:MM:SS, or HH:MM:SS.fractional\nconst PLAIN_TIME_PATTERN = /^\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?$/;\n\n/**\n * Parse a plain time or extract the wall-clock time from a datetime.\n *\n * @param input - A PlainTimeLike object, plain time string (HH:MM or HH:MM:SS), ZonedDateTime, or datetime input requiring timezone\n * @param timezone - IANA timezone identifier. Required for ISO strings, Date, and Instant inputs.\n * @returns A Temporal.PlainTime representing the wall-clock time\n *\n * @example\n * ```typescript\n * import { toPlainTime, toZonedTime } from '@gobrand/tiempo';\n *\n * // From PlainTimeLike object (no timezone needed)\n * const time = toPlainTime({ hour: 14, minute: 30 }); // 14:30\n *\n * // From plain time string (no timezone needed)\n * const time2 = toPlainTime(\"14:30\"); // 14:30\n * const timeWithSeconds = toPlainTime(\"14:30:45\"); // 14:30:45\n *\n * // From ZonedDateTime (no timezone needed)\n * const zdt = toZonedTime(\"2025-01-20T15:30:00Z\", \"America/New_York\");\n * const time3 = toPlainTime(zdt); // 10:30\n *\n * // From UTC string with timezone\n * const time4 = toPlainTime(\"2025-01-20T15:30:00Z\", \"America/New_York\"); // 10:30\n *\n * // From Date with timezone\n * const date = new Date(\"2025-01-20T15:30:00.000Z\");\n * const time5 = toPlainTime(date, \"Europe/London\"); // 15:30\n *\n * // From Instant with timezone\n * const instant = Temporal.Instant.from(\"2025-01-20T15:30:00Z\");\n * const time6 = toPlainTime(instant, \"Asia/Tokyo\"); // 00:30\n * ```\n */\nexport function toPlainTime(input: Temporal.ZonedDateTime): Temporal.PlainTime;\nexport function toPlainTime(\n input: string | Date | Temporal.Instant | Temporal.ZonedDateTime,\n timezone: Timezone\n): Temporal.PlainTime;\nexport function toPlainTime(input: Temporal.PlainTimeLike | string): Temporal.PlainTime;\nexport function toPlainTime(\n input: string | Date | Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainTimeLike,\n timezone?: Timezone\n): Temporal.PlainTime {\n // ZonedDateTime without timezone override\n if (input instanceof Temporal.ZonedDateTime && timezone === undefined) {\n return input.toPlainTime();\n }\n\n // Date requires timezone\n if (input instanceof Date) {\n if (timezone === undefined) {\n throw new Error('Timezone is required unless input is a ZonedDateTime, PlainTimeLike, or plain time string');\n }\n return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone).toPlainTime();\n }\n\n // Instant requires timezone\n if (input instanceof Temporal.Instant) {\n if (timezone === undefined) {\n throw new Error('Timezone is required unless input is a ZonedDateTime, PlainTimeLike, or plain time string');\n }\n return input.toZonedDateTimeISO(timezone).toPlainTime();\n }\n\n // ZonedDateTime with timezone override\n if (input instanceof Temporal.ZonedDateTime) {\n if (timezone === undefined) {\n throw new Error('Timezone is required unless input is a ZonedDateTime, PlainTimeLike, or plain time string');\n }\n return input.toInstant().toZonedDateTimeISO(timezone).toPlainTime();\n }\n\n // String: ISO datetime (requires timezone) or plain time (no timezone)\n if (typeof input === 'string') {\n if (timezone !== undefined) {\n return Temporal.Instant.from(input).toZonedDateTimeISO(timezone).toPlainTime();\n }\n if (PLAIN_TIME_PATTERN.test(input)) {\n return Temporal.PlainTime.from(input);\n }\n throw new Error('Timezone is required unless input is a ZonedDateTime, PlainTimeLike, or plain time string');\n }\n\n // PlainTimeLike object - pass directly to Temporal.PlainTime.from()\n return Temporal.PlainTime.from(input);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAIzB,IAAM,qBAAqB;AA0CpB,SAAS,YACd,OACA,UACoB;AAEpB,MAAI,iBAAiB,SAAS,iBAAiB,aAAa,QAAW;AACrE,WAAO,MAAM,YAAY;AAAA,EAC3B;AAGA,MAAI,iBAAiB,MAAM;AACzB,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI,MAAM,2FAA2F;AAAA,IAC7G;AACA,WAAO,SAAS,QAAQ,KAAK,MAAM,YAAY,CAAC,EAAE,mBAAmB,QAAQ,EAAE,YAAY;AAAA,EAC7F;AAGA,MAAI,iBAAiB,SAAS,SAAS;AACrC,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI,MAAM,2FAA2F;AAAA,IAC7G;AACA,WAAO,MAAM,mBAAmB,QAAQ,EAAE,YAAY;AAAA,EACxD;AAGA,MAAI,iBAAiB,SAAS,eAAe;AAC3C,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI,MAAM,2FAA2F;AAAA,IAC7G;AACA,WAAO,MAAM,UAAU,EAAE,mBAAmB,QAAQ,EAAE,YAAY;AAAA,EACpE;AAGA,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI,aAAa,QAAW;AAC1B,aAAO,SAAS,QAAQ,KAAK,KAAK,EAAE,mBAAmB,QAAQ,EAAE,YAAY;AAAA,IAC/E;AACA,QAAI,mBAAmB,KAAK,KAAK,GAAG;AAClC,aAAO,SAAS,UAAU,KAAK,KAAK;AAAA,IACtC;AACA,UAAM,IAAI,MAAM,2FAA2F;AAAA,EAC7G;AAGA,SAAO,SAAS,UAAU,KAAK,KAAK;AACtC;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEndOfDay
|
|
3
|
+
} from "./chunk-AVGNRINZ.js";
|
|
4
|
+
import {
|
|
5
|
+
plainDateToZonedDateTime
|
|
6
|
+
} from "./chunk-JNA3AFOC.js";
|
|
7
|
+
import {
|
|
8
|
+
normalizeTemporalInput
|
|
9
|
+
} from "./chunk-MJSZNWCV.js";
|
|
10
|
+
|
|
11
|
+
// src/endOfWeek.ts
|
|
12
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
13
|
+
function endOfWeek(input, timezone) {
|
|
14
|
+
const zonedDateTime = input instanceof Temporal.PlainDate ? plainDateToZonedDateTime(input, timezone) : normalizeTemporalInput(input);
|
|
15
|
+
const dayOfWeek = zonedDateTime.dayOfWeek;
|
|
16
|
+
const daysToAdd = 7 - dayOfWeek;
|
|
17
|
+
const sunday = zonedDateTime.add({ days: daysToAdd });
|
|
18
|
+
return getEndOfDay(sunday);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
endOfWeek
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=chunk-X26WIJ6L.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/endOfWeek.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\nimport { getEndOfDay } from './shared/endOfDay';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\nimport { plainDateToZonedDateTime } from './shared/plainDateToZonedDateTime';\n\n/**\n * Returns a ZonedDateTime representing the last moment of the week (Sunday at 23:59:59.999999999).\n * Uses ISO 8601 week definition: weeks end on Sunday.\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @returns ZonedDateTime at Sunday 23:59:59.999999999\n *\n * @example\n * ```ts\n * // From Instant (always UTC)\n * const instant = Temporal.Instant.from('2025-01-20T12:00:00Z'); // Monday\n * const end = endOfWeek(instant);\n * // 2025-01-26T23:59:59.999999999Z[UTC] (next Sunday)\n * ```\n *\n * @example\n * ```ts\n * // From ZonedDateTime (uses its timezone)\n * const zoned = Temporal.ZonedDateTime.from('2025-01-22T15:30:00-05:00[America/New_York]'); // Wednesday\n * const end = endOfWeek(zoned);\n * // 2025-01-26T23:59:59.999999999-05:00[America/New_York] (next Sunday)\n * ```\n *\n * @example\n * ```ts\n * // From PlainDate (requires timezone)\n * const date = Temporal.PlainDate.from('2025-01-22'); // Wednesday\n * const end = endOfWeek(date, 'America/New_York');\n * // 2025-01-26T23:59:59.999999999-05:00[America/New_York] (next Sunday)\n * ```\n */\nexport function endOfWeek(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Temporal.ZonedDateTime;\nexport function endOfWeek(\n input: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime;\nexport function endOfWeek(\n input: Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDate,\n timezone?: Timezone\n): Temporal.ZonedDateTime {\n const zonedDateTime =\n input instanceof Temporal.PlainDate\n ? plainDateToZonedDateTime(input, timezone!)\n : normalizeTemporalInput(input);\n\n // Get the day of week (1 = Monday, 7 = Sunday in ISO 8601)\n const dayOfWeek = zonedDateTime.dayOfWeek;\n\n // Calculate days to add to get to Sunday\n const daysToAdd = 7 - dayOfWeek;\n\n // Go to Sunday, then get end of that day\n const sunday = zonedDateTime.add({ days: daysToAdd });\n\n return getEndOfDay(sunday);\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,gBAAgB;AA4ClB,SAAS,UACd,OACA,UACwB;AACxB,QAAM,gBACJ,iBAAiB,SAAS,YACtB,yBAAyB,OAAO,QAAS,IACzC,uBAAuB,KAAK;AAGlC,QAAM,YAAY,cAAc;AAGhC,QAAM,YAAY,IAAI;AAGtB,QAAM,SAAS,cAAc,IAAI,EAAE,MAAM,UAAU,CAAC;AAEpD,SAAO,YAAY,MAAM;AAC3B;","names":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getEndOfDay
|
|
3
|
+
} from "./chunk-AVGNRINZ.js";
|
|
4
|
+
import {
|
|
5
|
+
plainDateToZonedDateTime
|
|
6
|
+
} from "./chunk-JNA3AFOC.js";
|
|
7
|
+
import {
|
|
8
|
+
normalizeTemporalInput
|
|
9
|
+
} from "./chunk-MJSZNWCV.js";
|
|
10
|
+
|
|
11
|
+
// src/endOfDay.ts
|
|
12
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
13
|
+
function endOfDay(input, timezone) {
|
|
14
|
+
if (input instanceof Temporal.PlainDate) {
|
|
15
|
+
return getEndOfDay(plainDateToZonedDateTime(input, timezone));
|
|
16
|
+
}
|
|
17
|
+
const zonedDateTime = normalizeTemporalInput(input);
|
|
18
|
+
return getEndOfDay(zonedDateTime);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
endOfDay
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=chunk-XPJFOBPW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/endOfDay.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\nimport { getEndOfDay } from './shared/endOfDay';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput';\nimport { plainDateToZonedDateTime } from './shared/plainDateToZonedDateTime';\n\n/**\n * Returns a ZonedDateTime representing the last nanosecond of the day.\n *\n * @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime\n * @returns ZonedDateTime at 23:59:59.999999999\n *\n * @example\n * ```ts\n * // From Instant (always UTC)\n * const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');\n * const end = endOfDay(instant);\n * // 2025-01-20T23:59:59.999999999Z[UTC]\n * ```\n *\n * @example\n * ```ts\n * // From ZonedDateTime (uses its timezone)\n * const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');\n * const end = endOfDay(zoned);\n * // 2025-01-20T23:59:59.999999999-05:00[America/New_York]\n * ```\n *\n * @example\n * ```ts\n * // From PlainDate (requires timezone)\n * const date = Temporal.PlainDate.from('2025-01-20');\n * const end = endOfDay(date, 'America/New_York');\n * // 2025-01-20T23:59:59.999999999-05:00[America/New_York]\n * ```\n */\nexport function endOfDay(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Temporal.ZonedDateTime;\nexport function endOfDay(\n input: Temporal.PlainDate,\n timezone: Timezone\n): Temporal.ZonedDateTime;\nexport function endOfDay(\n input: Temporal.Instant | Temporal.ZonedDateTime | Temporal.PlainDate,\n timezone?: Timezone\n): Temporal.ZonedDateTime {\n if (input instanceof Temporal.PlainDate) {\n return getEndOfDay(plainDateToZonedDateTime(input, timezone!));\n }\n\n const zonedDateTime = normalizeTemporalInput(input);\n return getEndOfDay(zonedDateTime);\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,gBAAgB;AA2ClB,SAAS,SACd,OACA,UACwB;AACxB,MAAI,iBAAiB,SAAS,WAAW;AACvC,WAAO,YAAY,yBAAyB,OAAO,QAAS,CAAC;AAAA,EAC/D;AAEA,QAAM,gBAAgB,uBAAuB,KAAK;AAClD,SAAO,YAAY,aAAa;AAClC;","names":[]}
|
package/dist/endOfDay.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import type { Timezone } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Returns a ZonedDateTime representing the last nanosecond of the day.
|
|
4
5
|
*
|
|
@@ -23,12 +24,12 @@ import { Temporal } from '@js-temporal/polyfill';
|
|
|
23
24
|
*
|
|
24
25
|
* @example
|
|
25
26
|
* ```ts
|
|
26
|
-
* //
|
|
27
|
-
* const
|
|
28
|
-
* const
|
|
29
|
-
* const end = endOfDay(nyTime);
|
|
27
|
+
* // From PlainDate (requires timezone)
|
|
28
|
+
* const date = Temporal.PlainDate.from('2025-01-20');
|
|
29
|
+
* const end = endOfDay(date, 'America/New_York');
|
|
30
30
|
* // 2025-01-20T23:59:59.999999999-05:00[America/New_York]
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
export declare function endOfDay(input: Temporal.Instant | Temporal.ZonedDateTime): Temporal.ZonedDateTime;
|
|
34
|
+
export declare function endOfDay(input: Temporal.PlainDate, timezone: Timezone): Temporal.ZonedDateTime;
|
|
34
35
|
//# sourceMappingURL=endOfDay.d.ts.map
|
package/dist/endOfDay.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endOfDay.d.ts","sourceRoot":"","sources":["../src/endOfDay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"endOfDay.d.ts","sourceRoot":"","sources":["../src/endOfDay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,GAC/C,QAAQ,CAAC,aAAa,CAAC;AAC1B,wBAAgB,QAAQ,CACtB,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,aAAa,CAAC"}
|
package/dist/endOfDay.js
CHANGED
package/dist/endOfMonth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import type { Timezone } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Returns a ZonedDateTime representing the last moment of the month (last day at 23:59:59.999999999).
|
|
4
5
|
*
|
|
@@ -23,12 +24,12 @@ import type { Temporal } from '@js-temporal/polyfill';
|
|
|
23
24
|
*
|
|
24
25
|
* @example
|
|
25
26
|
* ```ts
|
|
26
|
-
* //
|
|
27
|
-
* const
|
|
28
|
-
* const
|
|
29
|
-
*
|
|
30
|
-
* // 2025-01-31T23:59:59.999999999-05:00[America/New_York]
|
|
27
|
+
* // From PlainDate (requires timezone)
|
|
28
|
+
* const date = Temporal.PlainDate.from('2025-02-15');
|
|
29
|
+
* const end = endOfMonth(date, 'America/New_York');
|
|
30
|
+
* // 2025-02-28T23:59:59.999999999-05:00[America/New_York]
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
export declare function endOfMonth(input: Temporal.Instant | Temporal.ZonedDateTime): Temporal.ZonedDateTime;
|
|
34
|
+
export declare function endOfMonth(input: Temporal.PlainDate, timezone: Timezone): Temporal.ZonedDateTime;
|
|
34
35
|
//# sourceMappingURL=endOfMonth.d.ts.map
|
package/dist/endOfMonth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endOfMonth.d.ts","sourceRoot":"","sources":["../src/endOfMonth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"endOfMonth.d.ts","sourceRoot":"","sources":["../src/endOfMonth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,GAC/C,QAAQ,CAAC,aAAa,CAAC;AAC1B,wBAAgB,UAAU,CACxB,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,aAAa,CAAC"}
|
package/dist/endOfMonth.js
CHANGED
package/dist/endOfWeek.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
import type { Timezone } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Returns a ZonedDateTime representing the last moment of the week (Sunday at 23:59:59.999999999).
|
|
4
5
|
* Uses ISO 8601 week definition: weeks end on Sunday.
|
|
@@ -24,12 +25,12 @@ import type { Temporal } from '@js-temporal/polyfill';
|
|
|
24
25
|
*
|
|
25
26
|
* @example
|
|
26
27
|
* ```ts
|
|
27
|
-
* //
|
|
28
|
-
* const
|
|
29
|
-
* const
|
|
30
|
-
*
|
|
31
|
-
* // 2025-01-26T23:59:59.999999999-05:00[America/New_York]
|
|
28
|
+
* // From PlainDate (requires timezone)
|
|
29
|
+
* const date = Temporal.PlainDate.from('2025-01-22'); // Wednesday
|
|
30
|
+
* const end = endOfWeek(date, 'America/New_York');
|
|
31
|
+
* // 2025-01-26T23:59:59.999999999-05:00[America/New_York] (next Sunday)
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
34
|
export declare function endOfWeek(input: Temporal.Instant | Temporal.ZonedDateTime): Temporal.ZonedDateTime;
|
|
35
|
+
export declare function endOfWeek(input: Temporal.PlainDate, timezone: Timezone): Temporal.ZonedDateTime;
|
|
35
36
|
//# sourceMappingURL=endOfWeek.d.ts.map
|
package/dist/endOfWeek.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endOfWeek.d.ts","sourceRoot":"","sources":["../src/endOfWeek.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"endOfWeek.d.ts","sourceRoot":"","sources":["../src/endOfWeek.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,GAC/C,QAAQ,CAAC,aAAa,CAAC;AAC1B,wBAAgB,SAAS,CACvB,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,aAAa,CAAC"}
|