@gobrand/tiempo 2.7.0 → 2.8.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-MXQFENCR.js → chunk-4PSMM55Q.js} +4 -1
- package/dist/chunk-4PSMM55Q.js.map +1 -0
- package/dist/{chunk-BW5SFCKS.js → chunk-AE36GX4F.js} +4 -1
- package/dist/chunk-AE36GX4F.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/toUtc.d.ts +8 -5
- package/dist/toUtc.d.ts.map +1 -1
- package/dist/toUtc.js +1 -1
- package/dist/toZonedTime.d.ts +9 -5
- package/dist/toZonedTime.d.ts.map +1 -1
- package/dist/toZonedTime.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-BW5SFCKS.js.map +0 -1
- package/dist/chunk-MXQFENCR.js.map +0 -1
|
@@ -4,6 +4,9 @@ function toZonedTime(input, timezone) {
|
|
|
4
4
|
if (typeof input === "string") {
|
|
5
5
|
return Temporal.Instant.from(input).toZonedDateTimeISO(timezone);
|
|
6
6
|
}
|
|
7
|
+
if (typeof input === "number") {
|
|
8
|
+
return Temporal.Instant.fromEpochMilliseconds(input).toZonedDateTimeISO(timezone);
|
|
9
|
+
}
|
|
7
10
|
if (input instanceof Date) {
|
|
8
11
|
return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone);
|
|
9
12
|
}
|
|
@@ -16,4 +19,4 @@ function toZonedTime(input, timezone) {
|
|
|
16
19
|
export {
|
|
17
20
|
toZonedTime
|
|
18
21
|
};
|
|
19
|
-
//# sourceMappingURL=chunk-
|
|
22
|
+
//# sourceMappingURL=chunk-4PSMM55Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/toZonedTime.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\n\n/**\n * Convert a UTC ISO string, Unix timestamp, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.\n *\n * @param input - A UTC ISO 8601 string, Unix timestamp (milliseconds), 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 Unix timestamp (e.g., from database BIGINT or API response)\n * const timestamp = 1737403200000;\n * const zoned = toZonedTime(timestamp, \"America/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 | number | 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 (typeof input === 'number') {\n return Temporal.Instant.fromEpochMilliseconds(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;AAwClB,SAAS,YACd,OACA,UACwB;AACxB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK,EAAE,mBAAmB,QAAQ;AAAA,EACjE;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,sBAAsB,KAAK,EAAE,mBAAmB,QAAQ;AAAA,EAClF;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":[]}
|
|
@@ -4,6 +4,9 @@ function toUtc(input) {
|
|
|
4
4
|
if (typeof input === "string") {
|
|
5
5
|
return Temporal.Instant.from(input);
|
|
6
6
|
}
|
|
7
|
+
if (typeof input === "number") {
|
|
8
|
+
return Temporal.Instant.fromEpochMilliseconds(input);
|
|
9
|
+
}
|
|
7
10
|
if (input instanceof Date) {
|
|
8
11
|
return Temporal.Instant.from(input.toISOString());
|
|
9
12
|
}
|
|
@@ -13,4 +16,4 @@ function toUtc(input) {
|
|
|
13
16
|
export {
|
|
14
17
|
toUtc
|
|
15
18
|
};
|
|
16
|
-
//# sourceMappingURL=chunk-
|
|
19
|
+
//# sourceMappingURL=chunk-AE36GX4F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/toUtc.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * Convert a UTC ISO string, Unix timestamp, Date, or ZonedDateTime to a Temporal.Instant (UTC).\n *\n * @param input - A UTC ISO 8601 string, Unix timestamp (milliseconds), Date object, or Temporal.ZonedDateTime\n * @returns A Temporal.Instant representing the same moment in UTC\n *\n * @example\n * ```typescript\n * // From ISO string\n * const instant = toUtc(\"2025-01-20T20:00:00.000Z\");\n *\n * // From Unix timestamp (milliseconds since epoch)\n * const instant2 = toUtc(1737403200000);\n *\n * // From Date (e.g., from Drizzle ORM)\n * const date = new Date(\"2025-01-20T20:00:00.000Z\");\n * const instant3 = toUtc(date);\n *\n * // From ZonedDateTime\n * const zoned = Temporal.ZonedDateTime.from(\"2025-01-20T15:00:00-05:00[America/New_York]\");\n * const instant4 = toUtc(zoned);\n * // All represent the same UTC moment: 2025-01-20T20:00:00Z\n * ```\n */\nexport function toUtc(\n input: string | number | Date | Temporal.ZonedDateTime\n): Temporal.Instant {\n if (typeof input === 'string') {\n return Temporal.Instant.from(input);\n }\n\n if (typeof input === 'number') {\n return Temporal.Instant.fromEpochMilliseconds(input);\n }\n\n if (input instanceof Date) {\n return Temporal.Instant.from(input.toISOString());\n }\n\n return input.toInstant();\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AA0BlB,SAAS,MACd,OACkB;AAClB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK;AAAA,EACpC;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,sBAAsB,KAAK;AAAA,EACrD;AAEA,MAAI,iBAAiB,MAAM;AACzB,WAAO,SAAS,QAAQ,KAAK,MAAM,YAAY,CAAC;AAAA,EAClD;AAEA,SAAO,MAAM,UAAU;AACzB;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-UJWM2BV2.js";
|
|
4
4
|
import {
|
|
5
5
|
toUtc
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AE36GX4F.js";
|
|
7
7
|
import {
|
|
8
8
|
toZonedTime
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4PSMM55Q.js";
|
|
10
10
|
import {
|
|
11
11
|
today
|
|
12
12
|
} from "./chunk-KZB6NERH.js";
|
package/dist/toUtc.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
2
|
/**
|
|
3
|
-
* Convert a UTC ISO string, Date, or ZonedDateTime to a Temporal.Instant (UTC).
|
|
3
|
+
* Convert a UTC ISO string, Unix timestamp, Date, or ZonedDateTime to a Temporal.Instant (UTC).
|
|
4
4
|
*
|
|
5
|
-
* @param input - A UTC ISO 8601 string, Date object, or Temporal.ZonedDateTime
|
|
5
|
+
* @param input - A UTC ISO 8601 string, Unix timestamp (milliseconds), Date object, or Temporal.ZonedDateTime
|
|
6
6
|
* @returns A Temporal.Instant representing the same moment in UTC
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
@@ -10,15 +10,18 @@ import { Temporal } from '@js-temporal/polyfill';
|
|
|
10
10
|
* // From ISO string
|
|
11
11
|
* const instant = toUtc("2025-01-20T20:00:00.000Z");
|
|
12
12
|
*
|
|
13
|
+
* // From Unix timestamp (milliseconds since epoch)
|
|
14
|
+
* const instant2 = toUtc(1737403200000);
|
|
15
|
+
*
|
|
13
16
|
* // From Date (e.g., from Drizzle ORM)
|
|
14
17
|
* const date = new Date("2025-01-20T20:00:00.000Z");
|
|
15
|
-
* const
|
|
18
|
+
* const instant3 = toUtc(date);
|
|
16
19
|
*
|
|
17
20
|
* // From ZonedDateTime
|
|
18
21
|
* const zoned = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
|
|
19
|
-
* const
|
|
22
|
+
* const instant4 = toUtc(zoned);
|
|
20
23
|
* // All represent the same UTC moment: 2025-01-20T20:00:00Z
|
|
21
24
|
* ```
|
|
22
25
|
*/
|
|
23
|
-
export declare function toUtc(input: string | Date | Temporal.ZonedDateTime): Temporal.Instant;
|
|
26
|
+
export declare function toUtc(input: string | number | Date | Temporal.ZonedDateTime): Temporal.Instant;
|
|
24
27
|
//# sourceMappingURL=toUtc.d.ts.map
|
package/dist/toUtc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toUtc.d.ts","sourceRoot":"","sources":["../src/toUtc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD
|
|
1
|
+
{"version":3,"file":"toUtc.d.ts","sourceRoot":"","sources":["../src/toUtc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,aAAa,GACrD,QAAQ,CAAC,OAAO,CAclB"}
|
package/dist/toUtc.js
CHANGED
package/dist/toZonedTime.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Temporal } from '@js-temporal/polyfill';
|
|
2
2
|
import type { Timezone } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* Convert a UTC ISO string, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
|
|
4
|
+
* Convert a UTC ISO string, Unix timestamp, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
|
|
5
5
|
*
|
|
6
|
-
* @param input - A UTC ISO 8601 string, Date object, Temporal.Instant, or Temporal.ZonedDateTime
|
|
6
|
+
* @param input - A UTC ISO 8601 string, Unix timestamp (milliseconds), Date object, Temporal.Instant, or Temporal.ZonedDateTime
|
|
7
7
|
* @param timezone - IANA timezone identifier (e.g., "America/New_York", "Europe/London") or "UTC"
|
|
8
8
|
* @returns A Temporal.ZonedDateTime in the specified timezone
|
|
9
9
|
*
|
|
@@ -20,18 +20,22 @@ import type { Timezone } from './types';
|
|
|
20
20
|
* // Client-side: Convert to browser's timezone
|
|
21
21
|
* const localTime = toZonedTime("2025-01-20T20:00:00Z", browserTimezone());
|
|
22
22
|
*
|
|
23
|
+
* // From Unix timestamp (e.g., from database BIGINT or API response)
|
|
24
|
+
* const timestamp = 1737403200000;
|
|
25
|
+
* const zoned = toZonedTime(timestamp, "America/New_York");
|
|
26
|
+
*
|
|
23
27
|
* // From Date (e.g., from Drizzle ORM)
|
|
24
28
|
* const date = new Date("2025-01-20T20:00:00.000Z");
|
|
25
|
-
* const
|
|
29
|
+
* const zoned2 = toZonedTime(date, "America/New_York");
|
|
26
30
|
*
|
|
27
31
|
* // From Instant
|
|
28
32
|
* const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
|
|
29
|
-
* const
|
|
33
|
+
* const zoned3 = toZonedTime(instant, "Asia/Tokyo");
|
|
30
34
|
*
|
|
31
35
|
* // From ZonedDateTime (convert to different timezone)
|
|
32
36
|
* const nyTime = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
|
|
33
37
|
* const tokyoTime = toZonedTime(nyTime, "Asia/Tokyo");
|
|
34
38
|
* ```
|
|
35
39
|
*/
|
|
36
|
-
export declare function toZonedTime(input: string | Date | Temporal.Instant | Temporal.ZonedDateTime, timezone: Timezone): Temporal.ZonedDateTime;
|
|
40
|
+
export declare function toZonedTime(input: string | number | Date | Temporal.Instant | Temporal.ZonedDateTime, timezone: Timezone): Temporal.ZonedDateTime;
|
|
37
41
|
//# 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;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC
|
|
1
|
+
{"version":3,"file":"toZonedTime.d.ts","sourceRoot":"","sources":["../src/toZonedTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EACzE,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,aAAa,CAkBxB"}
|
package/dist/toZonedTime.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/toUtc.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * Convert a UTC ISO string, Date, or ZonedDateTime to a Temporal.Instant (UTC).\n *\n * @param input - A UTC ISO 8601 string, Date object, or Temporal.ZonedDateTime\n * @returns A Temporal.Instant representing the same moment in UTC\n *\n * @example\n * ```typescript\n * // From ISO string\n * const instant = toUtc(\"2025-01-20T20:00:00.000Z\");\n *\n * // From Date (e.g., from Drizzle ORM)\n * const date = new Date(\"2025-01-20T20:00:00.000Z\");\n * const instant2 = toUtc(date);\n *\n * // From ZonedDateTime\n * const zoned = Temporal.ZonedDateTime.from(\"2025-01-20T15:00:00-05:00[America/New_York]\");\n * const instant3 = toUtc(zoned);\n * // All represent the same UTC moment: 2025-01-20T20:00:00Z\n * ```\n */\nexport function toUtc(\n input: string | Date | Temporal.ZonedDateTime\n): Temporal.Instant {\n if (typeof input === 'string') {\n return Temporal.Instant.from(input);\n }\n\n if (input instanceof Date) {\n return Temporal.Instant.from(input.toISOString());\n }\n\n return input.toInstant();\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAuBlB,SAAS,MACd,OACkB;AAClB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK;AAAA,EACpC;AAEA,MAAI,iBAAiB,MAAM;AACzB,WAAO,SAAS,QAAQ,KAAK,MAAM,YAAY,CAAC;AAAA,EAClD;AAEA,SAAO,MAAM,UAAU;AACzB;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/toZonedTime.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\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;AAoClB,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":[]}
|