@gobrand/tiempo 2.3.0 → 2.3.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/README.md CHANGED
@@ -47,15 +47,24 @@ The Temporal API is powerful but requires understanding its various methods and
47
47
  ## Quick Start
48
48
 
49
49
  ```typescript
50
- import { toZonedTime, toUtcString } from '@gobrand/tiempo';
50
+ import { toZonedTime, toUtcString, toUtc, toDate } from '@gobrand/tiempo';
51
51
 
52
- // Backend sends: "2025-01-20T20:00:00.000Z"
52
+ // From ISO string (typical backend API)
53
53
  const zoned = toZonedTime("2025-01-20T20:00:00.000Z", "America/New_York");
54
54
  console.log(zoned.hour); // 15 (3 PM in New York)
55
55
 
56
- // Send back to backend:
57
- const utc = toUtcString(zoned);
58
- console.log(utc); // "2025-01-20T20:00:00Z"
56
+ // From Date object (e.g., Drizzle ORM)
57
+ const date = new Date("2025-01-20T20:00:00.000Z");
58
+ const zonedFromDate = toZonedTime(date, "America/New_York");
59
+ console.log(zonedFromDate.hour); // 15 (3 PM in New York)
60
+
61
+ // Back to ISO string
62
+ const utcString = toUtcString(zoned);
63
+ console.log(utcString); // "2025-01-20T20:00:00Z"
64
+
65
+ // Back to Date object (for Drizzle ORM)
66
+ const backToDate = toDate(zoned);
67
+ console.log(backToDate.toISOString()); // "2025-01-20T20:00:00.000Z"
59
68
  ```
60
69
 
61
70
  ## API
@@ -64,10 +73,10 @@ console.log(utc); // "2025-01-20T20:00:00Z"
64
73
 
65
74
  #### `toZonedTime(input, timezone)`
66
75
 
67
- Convert a UTC ISO string, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
76
+ Convert a UTC ISO string, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
68
77
 
69
78
  **Parameters:**
70
- - `input` (string | Temporal.Instant | Temporal.ZonedDateTime): A UTC ISO 8601 string, Temporal.Instant, or Temporal.ZonedDateTime
79
+ - `input` (string | Date | Temporal.Instant | Temporal.ZonedDateTime): A UTC ISO 8601 string, Date object, Temporal.Instant, or Temporal.ZonedDateTime
71
80
  - `timezone` (string): An IANA timezone identifier (e.g., `"America/New_York"`, `"Europe/London"`)
72
81
 
73
82
  **Returns:** `Temporal.ZonedDateTime` - The same instant in the specified timezone
@@ -81,9 +90,14 @@ const zoned = toZonedTime("2025-01-20T20:00:00.000Z", "America/New_York");
81
90
  console.log(zoned.hour); // 15 (3 PM in New York)
82
91
  console.log(zoned.toString()); // "2025-01-20T15:00:00-05:00[America/New_York]"
83
92
 
93
+ // From Date (e.g., from Drizzle ORM)
94
+ const date = new Date("2025-01-20T20:00:00.000Z");
95
+ const zoned2 = toZonedTime(date, "America/New_York");
96
+ console.log(zoned2.hour); // 15 (3 PM in New York)
97
+
84
98
  // From Instant
85
99
  const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
86
- const zoned2 = toZonedTime(instant, "Asia/Tokyo");
100
+ const zoned3 = toZonedTime(instant, "Asia/Tokyo");
87
101
 
88
102
  // From ZonedDateTime (convert to different timezone)
89
103
  const nyTime = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
@@ -92,10 +106,10 @@ const tokyoTime = toZonedTime(nyTime, "Asia/Tokyo");
92
106
 
93
107
  #### `toUtc(input)`
94
108
 
95
- Convert a UTC ISO string or ZonedDateTime to a Temporal.Instant (UTC).
109
+ Convert a UTC ISO string, Date, or ZonedDateTime to a Temporal.Instant (UTC).
96
110
 
97
111
  **Parameters:**
98
- - `input` (string | Temporal.ZonedDateTime): A UTC ISO 8601 string or Temporal.ZonedDateTime
112
+ - `input` (string | Date | Temporal.ZonedDateTime): A UTC ISO 8601 string, Date object, or Temporal.ZonedDateTime
99
113
 
100
114
  **Returns:** `Temporal.Instant` - A Temporal.Instant representing the same moment in UTC
101
115
 
@@ -106,10 +120,14 @@ import { toUtc } from '@gobrand/tiempo';
106
120
  // From ISO string
107
121
  const instant = toUtc("2025-01-20T20:00:00.000Z");
108
122
 
123
+ // From Date (e.g., from Drizzle ORM)
124
+ const date = new Date("2025-01-20T20:00:00.000Z");
125
+ const instant2 = toUtc(date);
126
+
109
127
  // From ZonedDateTime
110
128
  const zoned = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
111
- const instant2 = toUtc(zoned);
112
- // Both represent the same UTC moment: 2025-01-20T20:00:00Z
129
+ const instant3 = toUtc(zoned);
130
+ // All represent the same UTC moment: 2025-01-20T20:00:00Z
113
131
  ```
114
132
 
115
133
  #### `toUtcString(input)`
@@ -136,6 +154,35 @@ const iso2 = toUtcString(instant);
136
154
  console.log(iso2); // "2025-01-20T20:00:00Z"
137
155
  ```
138
156
 
157
+ #### `toDate(input)`
158
+
159
+ Convert a Temporal.Instant or ZonedDateTime to a Date object.
160
+
161
+ **Parameters:**
162
+ - `input` (Temporal.Instant | Temporal.ZonedDateTime): A Temporal.Instant or Temporal.ZonedDateTime
163
+
164
+ **Returns:** `Date` - A Date object representing the same moment in time
165
+
166
+ **Example:**
167
+ ```typescript
168
+ import { toDate } from '@gobrand/tiempo';
169
+
170
+ // From Instant
171
+ const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
172
+ const date = toDate(instant);
173
+ console.log(date.toISOString()); // "2025-01-20T20:00:00.000Z"
174
+
175
+ // From ZonedDateTime
176
+ const zoned = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
177
+ const date2 = toDate(zoned);
178
+ console.log(date2.toISOString()); // "2025-01-20T20:00:00.000Z"
179
+
180
+ // Use with Drizzle ORM (for storing back to database)
181
+ const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
182
+ const dateForDb = toDate(instant);
183
+ await db.update(posts).set({ publishedAt: dateForDb });
184
+ ```
185
+
139
186
  ### Formatting
140
187
 
141
188
  #### `intlFormatDistance(laterDate, earlierDate, options?)`
@@ -700,6 +747,36 @@ const instant2 = Temporal.Instant.from('2025-01-20T23:00:00Z');
700
747
  isSameDay(instant1, instant2); // true (both Jan 20 in UTC)
701
748
  ```
702
749
 
750
+ ## Drizzle ORM Integration
751
+
752
+ tiempo seamlessly integrates with Drizzle ORM for database datetime operations. When using Drizzle with PostgreSQL `timestamptz` columns and `mode: 'date'`, tiempo provides utilities to convert between Date objects and Temporal.
753
+
754
+ ```typescript
755
+ import { toZonedTime, toUtc, toDate } from '@gobrand/tiempo';
756
+
757
+ // 1. Reading from database (Drizzle returns Date with mode: 'date')
758
+ const post = await db.query.posts.findFirst();
759
+ const publishedAt = post.publishedAt; // Date object
760
+
761
+ // 2. Convert to user's timezone for display
762
+ const userTimezone = "America/New_York";
763
+ const zonedTime = toZonedTime(publishedAt, userTimezone);
764
+ console.log(zonedTime.hour); // Local hour in user's timezone
765
+
766
+ // 3. User reschedules post to tomorrow at 3 PM their time
767
+ const rescheduled = zonedTime.add({ days: 1 }).with({ hour: 15, minute: 0 });
768
+
769
+ // 4. Convert back to Date for database storage
770
+ const dateForDb = toDate(rescheduled);
771
+ await db.update(posts).set({ publishedAt: dateForDb }).where(eq(posts.id, post.id));
772
+ ```
773
+
774
+ **Why this works:**
775
+ - Drizzle's `mode: 'date'` returns JavaScript `Date` objects (timestamps)
776
+ - `toZonedTime(date, tz)` converts the Date to a timezone-aware Temporal object
777
+ - Work with Temporal's powerful API for date arithmetic and manipulation
778
+ - `toDate(temporal)` converts back to Date for Drizzle storage
779
+
703
780
  ## Real World Examples
704
781
 
705
782
  ### Example 1: Social Media Post Scheduler
@@ -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 (input instanceof Date) {
8
+ return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone);
9
+ }
7
10
  if (input instanceof Temporal.Instant) {
8
11
  return input.toZonedDateTimeISO(timezone);
9
12
  }
@@ -13,4 +16,4 @@ function toZonedTime(input, timezone) {
13
16
  export {
14
17
  toZonedTime
15
18
  };
16
- //# sourceMappingURL=chunk-KD5GEHUA.js.map
19
+ //# sourceMappingURL=chunk-2MP3ESL7.js.map
@@ -0,0 +1 @@
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":[]}
@@ -4,10 +4,13 @@ function toUtc(input) {
4
4
  if (typeof input === "string") {
5
5
  return Temporal.Instant.from(input);
6
6
  }
7
+ if (input instanceof Date) {
8
+ return Temporal.Instant.from(input.toISOString());
9
+ }
7
10
  return input.toInstant();
8
11
  }
9
12
 
10
13
  export {
11
14
  toUtc
12
15
  };
13
- //# sourceMappingURL=chunk-GPAFAHKJ.js.map
16
+ //# sourceMappingURL=chunk-BW5SFCKS.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, 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":[]}
@@ -0,0 +1,13 @@
1
+ // src/toDate.ts
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ function toDate(input) {
4
+ if (input instanceof Temporal.Instant) {
5
+ return new Date(input.toString());
6
+ }
7
+ return new Date(input.toInstant().toString());
8
+ }
9
+
10
+ export {
11
+ toDate
12
+ };
13
+ //# sourceMappingURL=chunk-TGKWBQ7L.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/toDate.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * Convert a Temporal.Instant or ZonedDateTime to a Date object.\n *\n * @param input - A Temporal.Instant or Temporal.ZonedDateTime\n * @returns A Date object representing the same moment in time\n *\n * @example\n * ```typescript\n * // From Instant\n * const instant = Temporal.Instant.from(\"2025-01-20T20:00:00Z\");\n * const date = toDate(instant);\n * // date.toISOString() === \"2025-01-20T20:00:00.000Z\"\n *\n * // From ZonedDateTime\n * const zoned = Temporal.ZonedDateTime.from(\"2025-01-20T15:00:00-05:00[America/New_York]\");\n * const date2 = toDate(zoned);\n * // date2.toISOString() === \"2025-01-20T20:00:00.000Z\"\n *\n * // Use with Drizzle ORM (for storing back to database)\n * const instant = Temporal.Instant.from(\"2025-01-20T20:00:00Z\");\n * const date = toDate(instant);\n * await db.update(posts).set({ publishedAt: date });\n * ```\n */\nexport function toDate(\n input: Temporal.Instant | Temporal.ZonedDateTime\n): Date {\n if (input instanceof Temporal.Instant) {\n return new Date(input.toString());\n }\n\n return new Date(input.toInstant().toString());\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AA0BlB,SAAS,OACd,OACM;AACN,MAAI,iBAAiB,SAAS,SAAS;AACrC,WAAO,IAAI,KAAK,MAAM,SAAS,CAAC;AAAA,EAClC;AAEA,SAAO,IAAI,KAAK,MAAM,UAAU,EAAE,SAAS,CAAC;AAC9C;","names":[]}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { toZonedTime } from './toZonedTime';
2
2
  export { toUtc } from './toUtc';
3
3
  export { toUtcString } from './toUtcString';
4
+ export { toDate } from './toDate';
4
5
  export { format, type FormatOptions } from './format';
5
6
  export { today } from './today';
6
7
  export { now } from './now';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,O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EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,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"}
package/dist/index.js CHANGED
@@ -1,12 +1,15 @@
1
+ import {
2
+ toDate
3
+ } from "./chunk-TGKWBQ7L.js";
1
4
  import {
2
5
  toUtc
3
- } from "./chunk-GPAFAHKJ.js";
6
+ } from "./chunk-BW5SFCKS.js";
4
7
  import {
5
8
  toUtcString
6
9
  } from "./chunk-DMKGJY4N.js";
7
10
  import {
8
11
  toZonedTime
9
- } from "./chunk-KD5GEHUA.js";
12
+ } from "./chunk-2MP3ESL7.js";
10
13
  import {
11
14
  today
12
15
  } from "./chunk-67QHALIG.js";
@@ -233,6 +236,7 @@ export {
233
236
  subSeconds,
234
237
  subWeeks,
235
238
  subYears,
239
+ toDate,
236
240
  toUtc,
237
241
  toUtcString,
238
242
  toZonedTime,
@@ -0,0 +1,27 @@
1
+ import { Temporal } from '@js-temporal/polyfill';
2
+ /**
3
+ * Convert a Temporal.Instant or ZonedDateTime to a Date object.
4
+ *
5
+ * @param input - A Temporal.Instant or Temporal.ZonedDateTime
6
+ * @returns A Date object representing the same moment in time
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // From Instant
11
+ * const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
12
+ * const date = toDate(instant);
13
+ * // date.toISOString() === "2025-01-20T20:00:00.000Z"
14
+ *
15
+ * // From ZonedDateTime
16
+ * const zoned = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
17
+ * const date2 = toDate(zoned);
18
+ * // date2.toISOString() === "2025-01-20T20:00:00.000Z"
19
+ *
20
+ * // Use with Drizzle ORM (for storing back to database)
21
+ * const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
22
+ * const date = toDate(instant);
23
+ * await db.update(posts).set({ publishedAt: date });
24
+ * ```
25
+ */
26
+ export declare function toDate(input: Temporal.Instant | Temporal.ZonedDateTime): Date;
27
+ //# sourceMappingURL=toDate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toDate.d.ts","sourceRoot":"","sources":["../src/toDate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,GAC/C,IAAI,CAMN"}
package/dist/toDate.js ADDED
@@ -0,0 +1,7 @@
1
+ import {
2
+ toDate
3
+ } from "./chunk-TGKWBQ7L.js";
4
+ export {
5
+ toDate
6
+ };
7
+ //# sourceMappingURL=toDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=toDate.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toDate.test.d.ts","sourceRoot":"","sources":["../src/toDate.test.ts"],"names":[],"mappings":""}
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 or ZonedDateTime to a Temporal.Instant (UTC).
3
+ * Convert a UTC ISO string, Date, or ZonedDateTime to a Temporal.Instant (UTC).
4
4
  *
5
- * @param input - A UTC ISO 8601 string or Temporal.ZonedDateTime
5
+ * @param input - A UTC ISO 8601 string, Date object, or Temporal.ZonedDateTime
6
6
  * @returns A Temporal.Instant representing the same moment in UTC
7
7
  *
8
8
  * @example
@@ -10,11 +10,15 @@ 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 Date (e.g., from Drizzle ORM)
14
+ * const date = new Date("2025-01-20T20:00:00.000Z");
15
+ * const instant2 = toUtc(date);
16
+ *
13
17
  * // From ZonedDateTime
14
18
  * const zoned = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
15
- * const instant2 = toUtc(zoned);
16
- * // Both represent the same UTC moment: 2025-01-20T20:00:00Z
19
+ * const instant3 = toUtc(zoned);
20
+ * // All represent the same UTC moment: 2025-01-20T20:00:00Z
17
21
  * ```
18
22
  */
19
- export declare function toUtc(input: string | Temporal.ZonedDateTime): Temporal.Instant;
23
+ export declare function toUtc(input: string | Date | Temporal.ZonedDateTime): Temporal.Instant;
20
24
  //# 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;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,aAAa,GACrC,QAAQ,CAAC,OAAO,CAMlB"}
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"}
package/dist/toUtc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toUtc
3
- } from "./chunk-GPAFAHKJ.js";
3
+ } from "./chunk-BW5SFCKS.js";
4
4
  export {
5
5
  toUtc
6
6
  };
@@ -1,8 +1,8 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
2
  /**
3
- * Convert a UTC ISO string, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
3
+ * Convert a UTC ISO string, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
4
4
  *
5
- * @param input - A UTC ISO 8601 string, Temporal.Instant, or Temporal.ZonedDateTime
5
+ * @param input - A UTC ISO 8601 string, Date object, Temporal.Instant, or Temporal.ZonedDateTime
6
6
  * @param timezone - IANA timezone identifier (e.g., "America/New_York", "Europe/London")
7
7
  * @returns A Temporal.ZonedDateTime in the specified timezone
8
8
  *
@@ -12,14 +12,18 @@ import { Temporal } from '@js-temporal/polyfill';
12
12
  * const zoned = toZonedTime("2025-01-20T20:00:00.000Z", "America/New_York");
13
13
  * // zoned.hour === 15 (3 PM in New York)
14
14
  *
15
+ * // From Date (e.g., from Drizzle ORM)
16
+ * const date = new Date("2025-01-20T20:00:00.000Z");
17
+ * const zoned2 = toZonedTime(date, "America/New_York");
18
+ *
15
19
  * // From Instant
16
20
  * const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
17
- * const zoned2 = toZonedTime(instant, "Asia/Tokyo");
21
+ * const zoned3 = toZonedTime(instant, "Asia/Tokyo");
18
22
  *
19
23
  * // From ZonedDateTime (convert to different timezone)
20
24
  * const nyTime = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
21
25
  * const tokyoTime = toZonedTime(nyTime, "Asia/Tokyo");
22
26
  * ```
23
27
  */
24
- export declare function toZonedTime(input: string | Temporal.Instant | Temporal.ZonedDateTime, timezone: string): Temporal.ZonedDateTime;
28
+ export declare function toZonedTime(input: string | Date | Temporal.Instant | Temporal.ZonedDateTime, timezone: string): Temporal.ZonedDateTime;
25
29
  //# 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;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EACzD,QAAQ,EAAE,MAAM,GACf,QAAQ,CAAC,aAAa,CAUxB"}
1
+ {"version":3,"file":"toZonedTime.d.ts","sourceRoot":"","sources":["../src/toZonedTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChE,QAAQ,EAAE,MAAM,GACf,QAAQ,CAAC,aAAa,CAcxB"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toZonedTime
3
- } from "./chunk-KD5GEHUA.js";
3
+ } from "./chunk-2MP3ESL7.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.3.0",
3
+ "version": "2.3.1",
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 or ZonedDateTime to a Temporal.Instant (UTC).\n *\n * @param input - A UTC ISO 8601 string 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 ZonedDateTime\n * const zoned = Temporal.ZonedDateTime.from(\"2025-01-20T15:00:00-05:00[America/New_York]\");\n * const instant2 = toUtc(zoned);\n * // Both represent the same UTC moment: 2025-01-20T20:00:00Z\n * ```\n */\nexport function toUtc(\n input: string | Temporal.ZonedDateTime\n): Temporal.Instant {\n if (typeof input === 'string') {\n return Temporal.Instant.from(input);\n }\n\n return input.toInstant();\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAmBlB,SAAS,MACd,OACkB;AAClB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK;AAAA,EACpC;AAEA,SAAO,MAAM,UAAU;AACzB;","names":[]}
@@ -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, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.\n *\n * @param input - A UTC ISO 8601 string, 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 Instant\n * const instant = Temporal.Instant.from(\"2025-01-20T20:00:00Z\");\n * const zoned2 = 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 | 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 Temporal.Instant) {\n return input.toZonedDateTimeISO(timezone);\n }\n\n return input.toInstant().toZonedDateTimeISO(timezone);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAwBlB,SAAS,YACd,OACA,UACwB;AACxB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK,EAAE,mBAAmB,QAAQ;AAAA,EACjE;AAEA,MAAI,iBAAiB,SAAS,SAAS;AACrC,WAAO,MAAM,mBAAmB,QAAQ;AAAA,EAC1C;AAEA,SAAO,MAAM,UAAU,EAAE,mBAAmB,QAAQ;AACtD;","names":[]}