@gobrand/tiempo 2.3.0 → 2.3.2
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 +127 -12
- package/dist/{chunk-KD5GEHUA.js → chunk-2MP3ESL7.js} +4 -1
- package/dist/chunk-2MP3ESL7.js.map +1 -0
- package/dist/chunk-4E7OGJ3F.js +10 -0
- package/dist/chunk-4E7OGJ3F.js.map +1 -0
- package/dist/chunk-BPZ7BRJW.js +10 -0
- package/dist/chunk-BPZ7BRJW.js.map +1 -0
- package/dist/{chunk-GPAFAHKJ.js → chunk-BW5SFCKS.js} +4 -1
- package/dist/chunk-BW5SFCKS.js.map +1 -0
- package/dist/chunk-O6RIN7K3.js +10 -0
- package/dist/chunk-O6RIN7K3.js.map +1 -0
- package/dist/chunk-TGKWBQ7L.js +13 -0
- package/dist/chunk-TGKWBQ7L.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +43 -27
- package/dist/isPlainDateAfter.d.ts +21 -0
- package/dist/isPlainDateAfter.d.ts.map +1 -0
- package/dist/isPlainDateAfter.js +7 -0
- package/dist/isPlainDateAfter.js.map +1 -0
- package/dist/isPlainDateAfter.test.d.ts +2 -0
- package/dist/isPlainDateAfter.test.d.ts.map +1 -0
- package/dist/isPlainDateBefore.d.ts +21 -0
- package/dist/isPlainDateBefore.d.ts.map +1 -0
- package/dist/isPlainDateBefore.js +7 -0
- package/dist/isPlainDateBefore.js.map +1 -0
- package/dist/isPlainDateBefore.test.d.ts +2 -0
- package/dist/isPlainDateBefore.test.d.ts.map +1 -0
- package/dist/isPlainDateEqual.d.ts +21 -0
- package/dist/isPlainDateEqual.d.ts.map +1 -0
- package/dist/isPlainDateEqual.js +7 -0
- package/dist/isPlainDateEqual.js.map +1 -0
- package/dist/isPlainDateEqual.test.d.ts +2 -0
- package/dist/isPlainDateEqual.test.d.ts.map +1 -0
- package/dist/toDate.d.ts +27 -0
- package/dist/toDate.d.ts.map +1 -0
- package/dist/toDate.js +7 -0
- package/dist/toDate.js.map +1 -0
- package/dist/toDate.test.d.ts +2 -0
- package/dist/toDate.test.d.ts.map +1 -0
- package/dist/toUtc.d.ts +9 -5
- package/dist/toUtc.d.ts.map +1 -1
- package/dist/toUtc.js +1 -1
- package/dist/toZonedTime.d.ts +8 -4
- package/dist/toZonedTime.d.ts.map +1 -1
- package/dist/toZonedTime.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-GPAFAHKJ.js.map +0 -1
- package/dist/chunk-KD5GEHUA.js.map +0 -1
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
|
-
//
|
|
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
|
-
//
|
|
57
|
-
const
|
|
58
|
-
|
|
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
|
|
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
|
|
112
|
-
//
|
|
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
|
|
@@ -776,6 +853,44 @@ const minutesUntil = differenceInMinutes(meeting, now);
|
|
|
776
853
|
console.log(`Meeting starts in ${minutesUntil} minutes`);
|
|
777
854
|
```
|
|
778
855
|
|
|
856
|
+
### PlainDate Comparisons
|
|
857
|
+
|
|
858
|
+
For comparing calendar dates without time or timezone considerations, tiempo provides dedicated PlainDate comparison functions. These are useful for calendars, date pickers, and scheduling UIs where you work with pure dates.
|
|
859
|
+
|
|
860
|
+
#### `isPlainDateBefore(date1, date2)` / `isPlainDateAfter(date1, date2)` / `isPlainDateEqual(date1, date2)`
|
|
861
|
+
|
|
862
|
+
Compare two `Temporal.PlainDate` values. Unlike `isBefore`/`isAfter` which compare instants in time, these functions compare pure calendar dates.
|
|
863
|
+
|
|
864
|
+
```typescript
|
|
865
|
+
import { isPlainDateBefore, isPlainDateAfter, isPlainDateEqual } from '@gobrand/tiempo';
|
|
866
|
+
|
|
867
|
+
const jan20 = Temporal.PlainDate.from('2025-01-20');
|
|
868
|
+
const jan25 = Temporal.PlainDate.from('2025-01-25');
|
|
869
|
+
|
|
870
|
+
isPlainDateBefore(jan20, jan25); // true
|
|
871
|
+
isPlainDateBefore(jan25, jan20); // false
|
|
872
|
+
|
|
873
|
+
isPlainDateAfter(jan25, jan20); // true
|
|
874
|
+
isPlainDateAfter(jan20, jan25); // false
|
|
875
|
+
|
|
876
|
+
isPlainDateEqual(jan20, Temporal.PlainDate.from('2025-01-20')); // true
|
|
877
|
+
isPlainDateEqual(jan20, jan25); // false
|
|
878
|
+
```
|
|
879
|
+
|
|
880
|
+
**When to use PlainDate vs Instant/ZonedDateTime:**
|
|
881
|
+
- Use `isPlainDateBefore`/`isPlainDateAfter` when comparing calendar dates (e.g., "Is January 20th before January 25th?")
|
|
882
|
+
- Use `isBefore`/`isAfter` when comparing specific moments in time (e.g., "Did event A happen before event B?")
|
|
883
|
+
|
|
884
|
+
```typescript
|
|
885
|
+
// Calendar UI: Disable dates before today
|
|
886
|
+
const isDateDisabled = (date: Temporal.PlainDate) =>
|
|
887
|
+
isPlainDateBefore(date, today());
|
|
888
|
+
|
|
889
|
+
// Booking system: Check if selected date is in the past
|
|
890
|
+
const isPastDate = (date: Temporal.PlainDate) =>
|
|
891
|
+
isPlainDateBefore(date, today());
|
|
892
|
+
```
|
|
893
|
+
|
|
779
894
|
## Browser Support
|
|
780
895
|
|
|
781
896
|
The Temporal API is a Stage 3 TC39 proposal. The polyfill `@js-temporal/polyfill` is included as a dependency, so you're ready to go!
|
|
@@ -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-
|
|
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":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/isPlainDateBefore.ts
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
function isPlainDateBefore(date1, date2) {
|
|
4
|
+
return Temporal.PlainDate.compare(date1, date2) < 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
isPlainDateBefore
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=chunk-4E7OGJ3F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/isPlainDateBefore.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * Returns true if the first plain date is before the second plain date.\n * Compares calendar dates without time or timezone considerations.\n *\n * @param date1 - First plain date\n * @param date2 - Second plain date\n * @returns true if date1 is before date2, false otherwise\n *\n * @example\n * ```ts\n * const jan20 = Temporal.PlainDate.from('2025-01-20');\n * const jan25 = Temporal.PlainDate.from('2025-01-25');\n *\n * isPlainDateBefore(jan20, jan25); // true\n * isPlainDateBefore(jan25, jan20); // false\n * isPlainDateBefore(jan20, jan20); // false\n * ```\n */\nexport function isPlainDateBefore(\n date1: Temporal.PlainDate,\n date2: Temporal.PlainDate\n): boolean {\n return Temporal.PlainDate.compare(date1, date2) < 0;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAoBlB,SAAS,kBACd,OACA,OACS;AACT,SAAO,SAAS,UAAU,QAAQ,OAAO,KAAK,IAAI;AACpD;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/isPlainDateAfter.ts
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
function isPlainDateAfter(date1, date2) {
|
|
4
|
+
return Temporal.PlainDate.compare(date1, date2) > 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
isPlainDateAfter
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=chunk-BPZ7BRJW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/isPlainDateAfter.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * Returns true if the first plain date is after the second plain date.\n * Compares calendar dates without time or timezone considerations.\n *\n * @param date1 - First plain date\n * @param date2 - Second plain date\n * @returns true if date1 is after date2, false otherwise\n *\n * @example\n * ```ts\n * const jan20 = Temporal.PlainDate.from('2025-01-20');\n * const jan25 = Temporal.PlainDate.from('2025-01-25');\n *\n * isPlainDateAfter(jan25, jan20); // true\n * isPlainDateAfter(jan20, jan25); // false\n * isPlainDateAfter(jan20, jan20); // false\n * ```\n */\nexport function isPlainDateAfter(\n date1: Temporal.PlainDate,\n date2: Temporal.PlainDate\n): boolean {\n return Temporal.PlainDate.compare(date1, date2) > 0;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAoBlB,SAAS,iBACd,OACA,OACS;AACT,SAAO,SAAS,UAAU,QAAQ,OAAO,KAAK,IAAI;AACpD;","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-
|
|
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,10 @@
|
|
|
1
|
+
// src/isPlainDateEqual.ts
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
function isPlainDateEqual(date1, date2) {
|
|
4
|
+
return Temporal.PlainDate.compare(date1, date2) === 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
isPlainDateEqual
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=chunk-O6RIN7K3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/isPlainDateEqual.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * Returns true if the two plain dates are equal.\n * Compares calendar dates without time or timezone considerations.\n *\n * @param date1 - First plain date\n * @param date2 - Second plain date\n * @returns true if date1 equals date2, false otherwise\n *\n * @example\n * ```ts\n * const jan20a = Temporal.PlainDate.from('2025-01-20');\n * const jan20b = Temporal.PlainDate.from('2025-01-20');\n * const jan25 = Temporal.PlainDate.from('2025-01-25');\n *\n * isPlainDateEqual(jan20a, jan20b); // true\n * isPlainDateEqual(jan20a, jan25); // false\n * ```\n */\nexport function isPlainDateEqual(\n date1: Temporal.PlainDate,\n date2: Temporal.PlainDate\n): boolean {\n return Temporal.PlainDate.compare(date1, date2) === 0;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAoBlB,SAAS,iBACd,OACA,OACS;AACT,SAAO,SAAS,UAAU,QAAQ,OAAO,KAAK,MAAM;AACtD;","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';
|
|
@@ -57,4 +58,7 @@ export { differenceInWeeks } from './differenceInWeeks';
|
|
|
57
58
|
export { differenceInMonths } from './differenceInMonths';
|
|
58
59
|
export { differenceInYears } from './differenceInYears';
|
|
59
60
|
export { intlFormatDistance, type IntlFormatDistanceOptions, } from './intlFormatDistance';
|
|
61
|
+
export { isPlainDateBefore } from './isPlainDateBefore';
|
|
62
|
+
export { isPlainDateAfter } from './isPlainDateAfter';
|
|
63
|
+
export { isPlainDateEqual } from './isPlainDateEqual';
|
|
60
64
|
//# sourceMappingURL=index.d.ts.map
|
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;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;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OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,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;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,15 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
today
|
|
3
|
+
} from "./chunk-67QHALIG.js";
|
|
4
|
+
import {
|
|
5
|
+
subSeconds
|
|
6
|
+
} from "./chunk-BH2YB4MV.js";
|
|
7
|
+
import {
|
|
8
|
+
subWeeks
|
|
9
|
+
} from "./chunk-U4RNUZXO.js";
|
|
10
|
+
import {
|
|
11
|
+
subYears
|
|
12
|
+
} from "./chunk-AHMKY474.js";
|
|
13
|
+
import {
|
|
14
|
+
toDate
|
|
15
|
+
} from "./chunk-TGKWBQ7L.js";
|
|
1
16
|
import {
|
|
2
17
|
toUtc
|
|
3
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-BW5SFCKS.js";
|
|
4
19
|
import {
|
|
5
20
|
toUtcString
|
|
6
21
|
} from "./chunk-DMKGJY4N.js";
|
|
7
22
|
import {
|
|
8
23
|
toZonedTime
|
|
9
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-2MP3ESL7.js";
|
|
10
25
|
import {
|
|
11
|
-
|
|
12
|
-
} from "./chunk-
|
|
26
|
+
startOfYear
|
|
27
|
+
} from "./chunk-YR2UCUIT.js";
|
|
28
|
+
import {
|
|
29
|
+
subDays
|
|
30
|
+
} from "./chunk-YKBP3G7L.js";
|
|
31
|
+
import {
|
|
32
|
+
subHours
|
|
33
|
+
} from "./chunk-XW5MLXX5.js";
|
|
13
34
|
import {
|
|
14
35
|
subMicroseconds
|
|
15
36
|
} from "./chunk-BQBLSXK2.js";
|
|
@@ -26,14 +47,14 @@ import {
|
|
|
26
47
|
subNanoseconds
|
|
27
48
|
} from "./chunk-WVHAYLBW.js";
|
|
28
49
|
import {
|
|
29
|
-
|
|
30
|
-
} from "./chunk-
|
|
50
|
+
isSameNanosecond
|
|
51
|
+
} from "./chunk-S63QUP4W.js";
|
|
31
52
|
import {
|
|
32
|
-
|
|
33
|
-
} from "./chunk-
|
|
53
|
+
isSameSecond
|
|
54
|
+
} from "./chunk-CY746ZUQ.js";
|
|
34
55
|
import {
|
|
35
|
-
|
|
36
|
-
} from "./chunk-
|
|
56
|
+
isSameWeek
|
|
57
|
+
} from "./chunk-JOD4ATPE.js";
|
|
37
58
|
import {
|
|
38
59
|
isSameYear
|
|
39
60
|
} from "./chunk-VLZ3HQQA.js";
|
|
@@ -50,14 +71,14 @@ import {
|
|
|
50
71
|
startOfWeek
|
|
51
72
|
} from "./chunk-2WMXB7QL.js";
|
|
52
73
|
import {
|
|
53
|
-
|
|
54
|
-
} from "./chunk-
|
|
74
|
+
isPlainDateBefore
|
|
75
|
+
} from "./chunk-4E7OGJ3F.js";
|
|
55
76
|
import {
|
|
56
|
-
|
|
57
|
-
} from "./chunk-
|
|
77
|
+
isPlainDateEqual
|
|
78
|
+
} from "./chunk-O6RIN7K3.js";
|
|
58
79
|
import {
|
|
59
|
-
|
|
60
|
-
} from "./chunk-
|
|
80
|
+
isSameDay
|
|
81
|
+
} from "./chunk-RW3C2677.js";
|
|
61
82
|
import {
|
|
62
83
|
isSameHour
|
|
63
84
|
} from "./chunk-EEQ3REET.js";
|
|
@@ -73,15 +94,6 @@ import {
|
|
|
73
94
|
import {
|
|
74
95
|
isSameMonth
|
|
75
96
|
} from "./chunk-ADQTZVMH.js";
|
|
76
|
-
import {
|
|
77
|
-
isSameNanosecond
|
|
78
|
-
} from "./chunk-S63QUP4W.js";
|
|
79
|
-
import {
|
|
80
|
-
isSameSecond
|
|
81
|
-
} from "./chunk-CY746ZUQ.js";
|
|
82
|
-
import {
|
|
83
|
-
isSameWeek
|
|
84
|
-
} from "./chunk-JOD4ATPE.js";
|
|
85
97
|
import {
|
|
86
98
|
format
|
|
87
99
|
} from "./chunk-2G5RJGPR.js";
|
|
@@ -101,8 +113,8 @@ import {
|
|
|
101
113
|
isPast
|
|
102
114
|
} from "./chunk-2H4KLXGL.js";
|
|
103
115
|
import {
|
|
104
|
-
|
|
105
|
-
} from "./chunk-
|
|
116
|
+
isPlainDateAfter
|
|
117
|
+
} from "./chunk-BPZ7BRJW.js";
|
|
106
118
|
import {
|
|
107
119
|
differenceInNanoseconds
|
|
108
120
|
} from "./chunk-OABS374T.js";
|
|
@@ -208,6 +220,9 @@ export {
|
|
|
208
220
|
isBefore,
|
|
209
221
|
isFuture,
|
|
210
222
|
isPast,
|
|
223
|
+
isPlainDateAfter,
|
|
224
|
+
isPlainDateBefore,
|
|
225
|
+
isPlainDateEqual,
|
|
211
226
|
isSameDay,
|
|
212
227
|
isSameHour,
|
|
213
228
|
isSameMicrosecond,
|
|
@@ -233,6 +248,7 @@ export {
|
|
|
233
248
|
subSeconds,
|
|
234
249
|
subWeeks,
|
|
235
250
|
subYears,
|
|
251
|
+
toDate,
|
|
236
252
|
toUtc,
|
|
237
253
|
toUtcString,
|
|
238
254
|
toZonedTime,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the first plain date is after the second plain date.
|
|
4
|
+
* Compares calendar dates without time or timezone considerations.
|
|
5
|
+
*
|
|
6
|
+
* @param date1 - First plain date
|
|
7
|
+
* @param date2 - Second plain date
|
|
8
|
+
* @returns true if date1 is after date2, false otherwise
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const jan20 = Temporal.PlainDate.from('2025-01-20');
|
|
13
|
+
* const jan25 = Temporal.PlainDate.from('2025-01-25');
|
|
14
|
+
*
|
|
15
|
+
* isPlainDateAfter(jan25, jan20); // true
|
|
16
|
+
* isPlainDateAfter(jan20, jan25); // false
|
|
17
|
+
* isPlainDateAfter(jan20, jan20); // false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPlainDateAfter(date1: Temporal.PlainDate, date2: Temporal.PlainDate): boolean;
|
|
21
|
+
//# sourceMappingURL=isPlainDateAfter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPlainDateAfter.d.ts","sourceRoot":"","sources":["../src/isPlainDateAfter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,KAAK,EAAE,QAAQ,CAAC,SAAS,GACxB,OAAO,CAET"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPlainDateAfter.test.d.ts","sourceRoot":"","sources":["../src/isPlainDateAfter.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the first plain date is before the second plain date.
|
|
4
|
+
* Compares calendar dates without time or timezone considerations.
|
|
5
|
+
*
|
|
6
|
+
* @param date1 - First plain date
|
|
7
|
+
* @param date2 - Second plain date
|
|
8
|
+
* @returns true if date1 is before date2, false otherwise
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const jan20 = Temporal.PlainDate.from('2025-01-20');
|
|
13
|
+
* const jan25 = Temporal.PlainDate.from('2025-01-25');
|
|
14
|
+
*
|
|
15
|
+
* isPlainDateBefore(jan20, jan25); // true
|
|
16
|
+
* isPlainDateBefore(jan25, jan20); // false
|
|
17
|
+
* isPlainDateBefore(jan20, jan20); // false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPlainDateBefore(date1: Temporal.PlainDate, date2: Temporal.PlainDate): boolean;
|
|
21
|
+
//# sourceMappingURL=isPlainDateBefore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPlainDateBefore.d.ts","sourceRoot":"","sources":["../src/isPlainDateBefore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,KAAK,EAAE,QAAQ,CAAC,SAAS,GACxB,OAAO,CAET"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPlainDateBefore.test.d.ts","sourceRoot":"","sources":["../src/isPlainDateBefore.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the two plain dates are equal.
|
|
4
|
+
* Compares calendar dates without time or timezone considerations.
|
|
5
|
+
*
|
|
6
|
+
* @param date1 - First plain date
|
|
7
|
+
* @param date2 - Second plain date
|
|
8
|
+
* @returns true if date1 equals date2, false otherwise
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const jan20a = Temporal.PlainDate.from('2025-01-20');
|
|
13
|
+
* const jan20b = Temporal.PlainDate.from('2025-01-20');
|
|
14
|
+
* const jan25 = Temporal.PlainDate.from('2025-01-25');
|
|
15
|
+
*
|
|
16
|
+
* isPlainDateEqual(jan20a, jan20b); // true
|
|
17
|
+
* isPlainDateEqual(jan20a, jan25); // false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPlainDateEqual(date1: Temporal.PlainDate, date2: Temporal.PlainDate): boolean;
|
|
21
|
+
//# sourceMappingURL=isPlainDateEqual.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPlainDateEqual.d.ts","sourceRoot":"","sources":["../src/isPlainDateEqual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,KAAK,EAAE,QAAQ,CAAC,SAAS,GACxB,OAAO,CAET"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isPlainDateEqual.test.d.ts","sourceRoot":"","sources":["../src/isPlainDateEqual.test.ts"],"names":[],"mappings":""}
|
package/dist/toDate.d.ts
ADDED
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -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
|
|
16
|
-
* //
|
|
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
|
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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,aAAa,GAC5C,QAAQ,CAAC,OAAO,CAUlB"}
|
package/dist/toUtc.js
CHANGED
package/dist/toZonedTime.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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"}
|
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 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":[]}
|