@gobrand/tiempo 2.4.0 → 2.4.1
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/browserTimezone.d.ts +22 -0
- package/dist/browserTimezone.d.ts.map +1 -0
- package/dist/browserTimezone.js +7 -0
- package/dist/browserTimezone.js.map +1 -0
- package/dist/browserTimezone.test.d.ts +2 -0
- package/dist/browserTimezone.test.d.ts.map +1 -0
- package/dist/{chunk-2MP3ESL7.js → chunk-DCJUK6EE.js} +1 -1
- package/dist/chunk-DCJUK6EE.js.map +1 -0
- package/dist/chunk-RQUZG65U.js +9 -0
- package/dist/chunk-RQUZG65U.js.map +1 -0
- package/dist/{chunk-XEDXPI5G.js → chunk-TDQXOSO3.js} +4 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -18
- package/dist/intlFormatDistance.js +2 -2
- package/dist/toZonedTime.d.ts +27 -7
- package/dist/toZonedTime.d.ts.map +1 -1
- package/dist/toZonedTime.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-2MP3ESL7.js.map +0 -1
- /package/dist/{chunk-XEDXPI5G.js.map → chunk-TDQXOSO3.js.map} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the browser/device timezone.
|
|
3
|
+
*
|
|
4
|
+
* Returns the IANA timezone identifier configured on the user's device.
|
|
5
|
+
* This is primarily useful in client-side code (browsers, React Native).
|
|
6
|
+
*
|
|
7
|
+
* **Warning:** On servers, this returns the server's configured timezone
|
|
8
|
+
* (often "UTC"), which is rarely what you want. For user-specific timezones
|
|
9
|
+
* on the server, retrieve the timezone from user preferences or request headers.
|
|
10
|
+
*
|
|
11
|
+
* @returns The IANA timezone identifier (e.g., "America/New_York", "Europe/London")
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { toZonedTime, browserTimezone } from '@gobrand/tiempo';
|
|
16
|
+
*
|
|
17
|
+
* // Convert UTC to the user's local timezone
|
|
18
|
+
* const userTime = toZonedTime("2025-01-20T20:00:00Z", browserTimezone());
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function browserTimezone(): string;
|
|
22
|
+
//# sourceMappingURL=browserTimezone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserTimezone.d.ts","sourceRoot":"","sources":["../src/browserTimezone.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserTimezone.test.d.ts","sourceRoot":"","sources":["../src/browserTimezone.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/toZonedTime.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * IANA timezone identifier or \"UTC\".\n *\n * Common timezones:\n * - \"UTC\" - Coordinated Universal Time\n * - \"America/New_York\" - US Eastern\n * - \"America/Los_Angeles\" - US Pacific\n * - \"Europe/London\" - UK\n * - \"Europe/Paris\" - Central European\n * - \"Asia/Tokyo\" - Japan\n * - \"Asia/Shanghai\" - China\n */\nexport type Timezone = 'UTC' | (string & {});\n\n/**\n * Convert a UTC ISO string, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.\n *\n * @param input - A UTC ISO 8601 string, Date object, Temporal.Instant, or Temporal.ZonedDateTime\n * @param timezone - IANA timezone identifier (e.g., \"America/New_York\", \"Europe/London\") or \"UTC\"\n * @returns A Temporal.ZonedDateTime in the specified timezone\n *\n * @example\n * ```typescript\n * import { toZonedTime, browserTimezone } from '@gobrand/tiempo';\n *\n * // Server-side: Convert to UTC\n * const utcTime = toZonedTime(\"2025-01-20T20:00:00Z\", \"UTC\");\n *\n * // Server-side: Convert to user's timezone (from DB/preferences)\n * const userTime = toZonedTime(\"2025-01-20T20:00:00Z\", user.timezone);\n *\n * // Client-side: Convert to browser's timezone\n * const localTime = toZonedTime(\"2025-01-20T20:00:00Z\", browserTimezone());\n *\n * // From Date (e.g., from Drizzle ORM)\n * const date = new Date(\"2025-01-20T20:00:00.000Z\");\n * const zoned = toZonedTime(date, \"America/New_York\");\n *\n * // From Instant\n * const instant = Temporal.Instant.from(\"2025-01-20T20:00:00Z\");\n * const zoned = toZonedTime(instant, \"Asia/Tokyo\");\n *\n * // From ZonedDateTime (convert to different timezone)\n * const nyTime = Temporal.ZonedDateTime.from(\"2025-01-20T15:00:00-05:00[America/New_York]\");\n * const tokyoTime = toZonedTime(nyTime, \"Asia/Tokyo\");\n * ```\n */\nexport function toZonedTime(\n input: string | Date | Temporal.Instant | Temporal.ZonedDateTime,\n timezone: Timezone\n): Temporal.ZonedDateTime {\n if (typeof input === 'string') {\n return Temporal.Instant.from(input).toZonedDateTimeISO(timezone);\n }\n\n if (input instanceof Date) {\n return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone);\n }\n\n if (input instanceof Temporal.Instant) {\n return input.toZonedDateTimeISO(timezone);\n }\n\n return input.toInstant().toZonedDateTimeISO(timezone);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAiDlB,SAAS,YACd,OACA,UACwB;AACxB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK,EAAE,mBAAmB,QAAQ;AAAA,EACjE;AAEA,MAAI,iBAAiB,MAAM;AACzB,WAAO,SAAS,QAAQ,KAAK,MAAM,YAAY,CAAC,EAAE,mBAAmB,QAAQ;AAAA,EAC/E;AAEA,MAAI,iBAAiB,SAAS,SAAS;AACrC,WAAO,MAAM,mBAAmB,QAAQ;AAAA,EAC1C;AAEA,SAAO,MAAM,UAAU,EAAE,mBAAmB,QAAQ;AACtD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/browserTimezone.ts"],"sourcesContent":["/**\n * Get the browser/device timezone.\n *\n * Returns the IANA timezone identifier configured on the user's device.\n * This is primarily useful in client-side code (browsers, React Native).\n *\n * **Warning:** On servers, this returns the server's configured timezone\n * (often \"UTC\"), which is rarely what you want. For user-specific timezones\n * on the server, retrieve the timezone from user preferences or request headers.\n *\n * @returns The IANA timezone identifier (e.g., \"America/New_York\", \"Europe/London\")\n *\n * @example\n * ```typescript\n * import { toZonedTime, browserTimezone } from '@gobrand/tiempo';\n *\n * // Convert UTC to the user's local timezone\n * const userTime = toZonedTime(\"2025-01-20T20:00:00Z\", browserTimezone());\n * ```\n */\nexport function browserTimezone(): string {\n return Intl.DateTimeFormat().resolvedOptions().timeZone;\n}\n"],"mappings":";AAoBO,SAAS,kBAA0B;AACxC,SAAO,KAAK,eAAe,EAAE,gBAAgB,EAAE;AACjD;","names":[]}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
differenceInMonths
|
|
3
|
+
} from "./chunk-BIAPE4MR.js";
|
|
1
4
|
import {
|
|
2
5
|
differenceInSeconds
|
|
3
6
|
} from "./chunk-ZHRMURYP.js";
|
|
@@ -16,9 +19,6 @@ import {
|
|
|
16
19
|
import {
|
|
17
20
|
differenceInMinutes
|
|
18
21
|
} from "./chunk-RJY62CDU.js";
|
|
19
|
-
import {
|
|
20
|
-
differenceInMonths
|
|
21
|
-
} from "./chunk-BIAPE4MR.js";
|
|
22
22
|
import {
|
|
23
23
|
normalizeTemporalInput
|
|
24
24
|
} from "./chunk-MJSZNWCV.js";
|
|
@@ -91,4 +91,4 @@ function intlFormatDistance(laterDate, earlierDate, options) {
|
|
|
91
91
|
export {
|
|
92
92
|
intlFormatDistance
|
|
93
93
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-TDQXOSO3.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { toZonedTime } from './toZonedTime';
|
|
1
|
+
export { toZonedTime, type Timezone } from './toZonedTime';
|
|
2
|
+
export { browserTimezone } from './browserTimezone';
|
|
2
3
|
export { toUtc } from './toUtc';
|
|
3
4
|
export { toIso, type IsoMode, type ToIsoOptions } from './toIso';
|
|
4
5
|
export { toIso9075, type ToIso9075Options, type Iso9075Representation, type Iso9075Mode, } from './toIso9075';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,KAAK,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,OA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CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toIso
|
|
3
|
+
} from "./chunk-BSV32PSO.js";
|
|
1
4
|
import {
|
|
2
5
|
toIso9075
|
|
3
6
|
} from "./chunk-DFLGGK4F.js";
|
|
@@ -6,10 +9,13 @@ import {
|
|
|
6
9
|
} from "./chunk-BW5SFCKS.js";
|
|
7
10
|
import {
|
|
8
11
|
toZonedTime
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-DCJUK6EE.js";
|
|
10
13
|
import {
|
|
11
14
|
today
|
|
12
15
|
} from "./chunk-67QHALIG.js";
|
|
16
|
+
import {
|
|
17
|
+
subMinutes
|
|
18
|
+
} from "./chunk-J6G2I2TU.js";
|
|
13
19
|
import {
|
|
14
20
|
subMonths
|
|
15
21
|
} from "./chunk-52NEOY34.js";
|
|
@@ -29,8 +35,8 @@ import {
|
|
|
29
35
|
toDate
|
|
30
36
|
} from "./chunk-TGKWBQ7L.js";
|
|
31
37
|
import {
|
|
32
|
-
|
|
33
|
-
} from "./chunk-
|
|
38
|
+
startOfDay
|
|
39
|
+
} from "./chunk-TW5EV3DH.js";
|
|
34
40
|
import {
|
|
35
41
|
startOfMonth
|
|
36
42
|
} from "./chunk-TU2UNOOW.js";
|
|
@@ -53,8 +59,8 @@ import {
|
|
|
53
59
|
subMilliseconds
|
|
54
60
|
} from "./chunk-HDBH7RTY.js";
|
|
55
61
|
import {
|
|
56
|
-
|
|
57
|
-
} from "./chunk-
|
|
62
|
+
isSameMinute
|
|
63
|
+
} from "./chunk-LDO6PRNJ.js";
|
|
58
64
|
import {
|
|
59
65
|
isSameMonth
|
|
60
66
|
} from "./chunk-ADQTZVMH.js";
|
|
@@ -77,8 +83,8 @@ import {
|
|
|
77
83
|
simpleFormat
|
|
78
84
|
} from "./chunk-GQBO2UXH.js";
|
|
79
85
|
import {
|
|
80
|
-
|
|
81
|
-
} from "./chunk-
|
|
86
|
+
isPast
|
|
87
|
+
} from "./chunk-2H4KLXGL.js";
|
|
82
88
|
import {
|
|
83
89
|
isPlainDateAfter
|
|
84
90
|
} from "./chunk-BPZ7BRJW.js";
|
|
@@ -101,8 +107,8 @@ import {
|
|
|
101
107
|
isSameMillisecond
|
|
102
108
|
} from "./chunk-ISHZRFVN.js";
|
|
103
109
|
import {
|
|
104
|
-
|
|
105
|
-
} from "./chunk-
|
|
110
|
+
endOfYear
|
|
111
|
+
} from "./chunk-XDVUGTUV.js";
|
|
106
112
|
import {
|
|
107
113
|
format
|
|
108
114
|
} from "./chunk-2G5RJGPR.js";
|
|
@@ -111,7 +117,7 @@ import {
|
|
|
111
117
|
} from "./chunk-3A6X6WV5.js";
|
|
112
118
|
import {
|
|
113
119
|
intlFormatDistance
|
|
114
|
-
} from "./chunk-
|
|
120
|
+
} from "./chunk-TDQXOSO3.js";
|
|
115
121
|
import {
|
|
116
122
|
isAfter
|
|
117
123
|
} from "./chunk-BBNNR2QH.js";
|
|
@@ -122,8 +128,8 @@ import {
|
|
|
122
128
|
isFuture
|
|
123
129
|
} from "./chunk-R5XN76EV.js";
|
|
124
130
|
import {
|
|
125
|
-
|
|
126
|
-
} from "./chunk-
|
|
131
|
+
differenceInMonths
|
|
132
|
+
} from "./chunk-BIAPE4MR.js";
|
|
127
133
|
import {
|
|
128
134
|
differenceInNanoseconds
|
|
129
135
|
} from "./chunk-OABS374T.js";
|
|
@@ -145,9 +151,6 @@ import {
|
|
|
145
151
|
import {
|
|
146
152
|
endOfWeek
|
|
147
153
|
} from "./chunk-XVJJR7H6.js";
|
|
148
|
-
import {
|
|
149
|
-
endOfYear
|
|
150
|
-
} from "./chunk-XDVUGTUV.js";
|
|
151
154
|
import "./chunk-AVGNRINZ.js";
|
|
152
155
|
import {
|
|
153
156
|
addWeeks
|
|
@@ -155,6 +158,9 @@ import {
|
|
|
155
158
|
import {
|
|
156
159
|
addYears
|
|
157
160
|
} from "./chunk-Q2F3HEXB.js";
|
|
161
|
+
import {
|
|
162
|
+
browserTimezone
|
|
163
|
+
} from "./chunk-RQUZG65U.js";
|
|
158
164
|
import {
|
|
159
165
|
differenceInDays
|
|
160
166
|
} from "./chunk-6IP245MS.js";
|
|
@@ -170,9 +176,6 @@ import {
|
|
|
170
176
|
import {
|
|
171
177
|
differenceInMinutes
|
|
172
178
|
} from "./chunk-RJY62CDU.js";
|
|
173
|
-
import {
|
|
174
|
-
differenceInMonths
|
|
175
|
-
} from "./chunk-BIAPE4MR.js";
|
|
176
179
|
import {
|
|
177
180
|
addDays
|
|
178
181
|
} from "./chunk-L4SVABDH.js";
|
|
@@ -209,6 +212,7 @@ export {
|
|
|
209
212
|
addSeconds,
|
|
210
213
|
addWeeks,
|
|
211
214
|
addYears,
|
|
215
|
+
browserTimezone,
|
|
212
216
|
differenceInDays,
|
|
213
217
|
differenceInHours,
|
|
214
218
|
differenceInMicroseconds,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
intlFormatDistance
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TDQXOSO3.js";
|
|
4
|
+
import "./chunk-BIAPE4MR.js";
|
|
4
5
|
import "./chunk-ZHRMURYP.js";
|
|
5
6
|
import "./chunk-PVAOUYXF.js";
|
|
6
7
|
import "./chunk-CHW2EN2O.js";
|
|
7
8
|
import "./chunk-6IP245MS.js";
|
|
8
9
|
import "./chunk-PIDXROVB.js";
|
|
9
10
|
import "./chunk-RJY62CDU.js";
|
|
10
|
-
import "./chunk-BIAPE4MR.js";
|
|
11
11
|
import "./chunk-MJSZNWCV.js";
|
|
12
12
|
export {
|
|
13
13
|
intlFormatDistance
|
package/dist/toZonedTime.d.ts
CHANGED
|
@@ -1,29 +1,49 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* IANA timezone identifier or "UTC".
|
|
4
|
+
*
|
|
5
|
+
* Common timezones:
|
|
6
|
+
* - "UTC" - Coordinated Universal Time
|
|
7
|
+
* - "America/New_York" - US Eastern
|
|
8
|
+
* - "America/Los_Angeles" - US Pacific
|
|
9
|
+
* - "Europe/London" - UK
|
|
10
|
+
* - "Europe/Paris" - Central European
|
|
11
|
+
* - "Asia/Tokyo" - Japan
|
|
12
|
+
* - "Asia/Shanghai" - China
|
|
13
|
+
*/
|
|
14
|
+
export type Timezone = 'UTC' | (string & {});
|
|
2
15
|
/**
|
|
3
16
|
* Convert a UTC ISO string, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
|
|
4
17
|
*
|
|
5
18
|
* @param input - A UTC ISO 8601 string, Date object, Temporal.Instant, or Temporal.ZonedDateTime
|
|
6
|
-
* @param timezone - IANA timezone identifier (e.g., "America/New_York", "Europe/London")
|
|
19
|
+
* @param timezone - IANA timezone identifier (e.g., "America/New_York", "Europe/London") or "UTC"
|
|
7
20
|
* @returns A Temporal.ZonedDateTime in the specified timezone
|
|
8
21
|
*
|
|
9
22
|
* @example
|
|
10
23
|
* ```typescript
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* //
|
|
24
|
+
* import { toZonedTime, browserTimezone } from '@gobrand/tiempo';
|
|
25
|
+
*
|
|
26
|
+
* // Server-side: Convert to UTC
|
|
27
|
+
* const utcTime = toZonedTime("2025-01-20T20:00:00Z", "UTC");
|
|
28
|
+
*
|
|
29
|
+
* // Server-side: Convert to user's timezone (from DB/preferences)
|
|
30
|
+
* const userTime = toZonedTime("2025-01-20T20:00:00Z", user.timezone);
|
|
31
|
+
*
|
|
32
|
+
* // Client-side: Convert to browser's timezone
|
|
33
|
+
* const localTime = toZonedTime("2025-01-20T20:00:00Z", browserTimezone());
|
|
14
34
|
*
|
|
15
35
|
* // From Date (e.g., from Drizzle ORM)
|
|
16
36
|
* const date = new Date("2025-01-20T20:00:00.000Z");
|
|
17
|
-
* const
|
|
37
|
+
* const zoned = toZonedTime(date, "America/New_York");
|
|
18
38
|
*
|
|
19
39
|
* // From Instant
|
|
20
40
|
* const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
|
|
21
|
-
* const
|
|
41
|
+
* const zoned = toZonedTime(instant, "Asia/Tokyo");
|
|
22
42
|
*
|
|
23
43
|
* // From ZonedDateTime (convert to different timezone)
|
|
24
44
|
* const nyTime = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
|
|
25
45
|
* const tokyoTime = toZonedTime(nyTime, "Asia/Tokyo");
|
|
26
46
|
* ```
|
|
27
47
|
*/
|
|
28
|
-
export declare function toZonedTime(input: string | Date | Temporal.Instant | Temporal.ZonedDateTime, timezone:
|
|
48
|
+
export declare function toZonedTime(input: string | Date | Temporal.Instant | Temporal.ZonedDateTime, timezone: Timezone): Temporal.ZonedDateTime;
|
|
29
49
|
//# sourceMappingURL=toZonedTime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toZonedTime.d.ts","sourceRoot":"","sources":["../src/toZonedTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD
|
|
1
|
+
{"version":3,"file":"toZonedTime.d.ts","sourceRoot":"","sources":["../src/toZonedTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChE,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,aAAa,CAcxB"}
|
package/dist/toZonedTime.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/toZonedTime.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * Convert a UTC ISO string, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.\n *\n * @param input - A UTC ISO 8601 string, Date object, Temporal.Instant, or Temporal.ZonedDateTime\n * @param timezone - IANA timezone identifier (e.g., \"America/New_York\", \"Europe/London\")\n * @returns A Temporal.ZonedDateTime in the specified timezone\n *\n * @example\n * ```typescript\n * // From ISO string\n * const zoned = toZonedTime(\"2025-01-20T20:00:00.000Z\", \"America/New_York\");\n * // zoned.hour === 15 (3 PM in New York)\n *\n * // From Date (e.g., from Drizzle ORM)\n * const date = new Date(\"2025-01-20T20:00:00.000Z\");\n * const zoned2 = toZonedTime(date, \"America/New_York\");\n *\n * // From Instant\n * const instant = Temporal.Instant.from(\"2025-01-20T20:00:00Z\");\n * const zoned3 = toZonedTime(instant, \"Asia/Tokyo\");\n *\n * // From ZonedDateTime (convert to different timezone)\n * const nyTime = Temporal.ZonedDateTime.from(\"2025-01-20T15:00:00-05:00[America/New_York]\");\n * const tokyoTime = toZonedTime(nyTime, \"Asia/Tokyo\");\n * ```\n */\nexport function toZonedTime(\n input: string | Date | Temporal.Instant | Temporal.ZonedDateTime,\n timezone: string\n): Temporal.ZonedDateTime {\n if (typeof input === 'string') {\n return Temporal.Instant.from(input).toZonedDateTimeISO(timezone);\n }\n\n if (input instanceof Date) {\n return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone);\n }\n\n if (input instanceof Temporal.Instant) {\n return input.toZonedDateTimeISO(timezone);\n }\n\n return input.toInstant().toZonedDateTimeISO(timezone);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AA4BlB,SAAS,YACd,OACA,UACwB;AACxB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK,EAAE,mBAAmB,QAAQ;AAAA,EACjE;AAEA,MAAI,iBAAiB,MAAM;AACzB,WAAO,SAAS,QAAQ,KAAK,MAAM,YAAY,CAAC,EAAE,mBAAmB,QAAQ;AAAA,EAC/E;AAEA,MAAI,iBAAiB,SAAS,SAAS;AACrC,WAAO,MAAM,mBAAmB,QAAQ;AAAA,EAC1C;AAEA,SAAO,MAAM,UAAU,EAAE,mBAAmB,QAAQ;AACtD;","names":[]}
|
|
File without changes
|