@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.
@@ -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-MXQFENCR.js.map
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-BW5SFCKS.js.map
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-BW5SFCKS.js";
6
+ } from "./chunk-AE36GX4F.js";
7
7
  import {
8
8
  toZonedTime
9
- } from "./chunk-MXQFENCR.js";
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 instant2 = toUtc(date);
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 instant3 = toUtc(zoned);
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
@@ -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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,aAAa,GAC5C,QAAQ,CAAC,OAAO,CAUlB"}
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
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toUtc
3
- } from "./chunk-BW5SFCKS.js";
3
+ } from "./chunk-AE36GX4F.js";
4
4
  export {
5
5
  toUtc
6
6
  };
@@ -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 zoned = toZonedTime(date, "America/New_York");
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 zoned = toZonedTime(instant, "Asia/Tokyo");
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"}
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"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toZonedTime
3
- } from "./chunk-MXQFENCR.js";
3
+ } from "./chunk-4PSMM55Q.js";
4
4
  export {
5
5
  toZonedTime
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobrand/tiempo",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "Lightweight utility functions for converting between UTC and timezone-aware datetimes using the Temporal API",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -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":[]}