@gobrand/tiempo 2.2.2 → 2.3.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/README.md +286 -12
- package/dist/addDays.d.ts +37 -0
- package/dist/addDays.d.ts.map +1 -0
- package/dist/addDays.js +8 -0
- package/dist/addDays.js.map +1 -0
- package/dist/addDays.test.d.ts +2 -0
- package/dist/addDays.test.d.ts.map +1 -0
- package/dist/addHours.d.ts +37 -0
- package/dist/addHours.d.ts.map +1 -0
- package/dist/addHours.js +8 -0
- package/dist/addHours.js.map +1 -0
- package/dist/addHours.test.d.ts +2 -0
- package/dist/addHours.test.d.ts.map +1 -0
- package/dist/addMicroseconds.d.ts +36 -0
- package/dist/addMicroseconds.d.ts.map +1 -0
- package/dist/addMicroseconds.js +8 -0
- package/dist/addMicroseconds.js.map +1 -0
- package/dist/addMicroseconds.test.d.ts +2 -0
- package/dist/addMicroseconds.test.d.ts.map +1 -0
- package/dist/addMilliseconds.d.ts +36 -0
- package/dist/addMilliseconds.d.ts.map +1 -0
- package/dist/addMilliseconds.js +8 -0
- package/dist/addMilliseconds.js.map +1 -0
- package/dist/addMilliseconds.test.d.ts +2 -0
- package/dist/addMilliseconds.test.d.ts.map +1 -0
- package/dist/addMinutes.d.ts +36 -0
- package/dist/addMinutes.d.ts.map +1 -0
- package/dist/addMinutes.js +8 -0
- package/dist/addMinutes.js.map +1 -0
- package/dist/addMinutes.test.d.ts +2 -0
- package/dist/addMinutes.test.d.ts.map +1 -0
- package/dist/addMonths.d.ts +37 -0
- package/dist/addMonths.d.ts.map +1 -0
- package/dist/addMonths.js +8 -0
- package/dist/addMonths.js.map +1 -0
- package/dist/addMonths.test.d.ts +2 -0
- package/dist/addMonths.test.d.ts.map +1 -0
- package/dist/addNanoseconds.d.ts +36 -0
- package/dist/addNanoseconds.d.ts.map +1 -0
- package/dist/addNanoseconds.js +8 -0
- package/dist/addNanoseconds.js.map +1 -0
- package/dist/addNanoseconds.test.d.ts +2 -0
- package/dist/addNanoseconds.test.d.ts.map +1 -0
- package/dist/addSeconds.d.ts +36 -0
- package/dist/addSeconds.d.ts.map +1 -0
- package/dist/addSeconds.js +8 -0
- package/dist/addSeconds.js.map +1 -0
- package/dist/addSeconds.test.d.ts +2 -0
- package/dist/addSeconds.test.d.ts.map +1 -0
- package/dist/addWeeks.d.ts +37 -0
- package/dist/addWeeks.d.ts.map +1 -0
- package/dist/addWeeks.js +8 -0
- package/dist/addWeeks.js.map +1 -0
- package/dist/addWeeks.test.d.ts +2 -0
- package/dist/addWeeks.test.d.ts.map +1 -0
- package/dist/addYears.d.ts +37 -0
- package/dist/addYears.d.ts.map +1 -0
- package/dist/addYears.js +8 -0
- package/dist/addYears.js.map +1 -0
- package/dist/addYears.test.d.ts +2 -0
- package/dist/addYears.test.d.ts.map +1 -0
- package/dist/chunk-2XHAHSB6.js +14 -0
- package/dist/chunk-2XHAHSB6.js.map +1 -0
- package/dist/chunk-4NJMCCUM.js +14 -0
- package/dist/chunk-4NJMCCUM.js.map +1 -0
- package/dist/chunk-52NEOY34.js +13 -0
- package/dist/chunk-52NEOY34.js.map +1 -0
- package/dist/chunk-7ATM7AXL.js +14 -0
- package/dist/chunk-7ATM7AXL.js.map +1 -0
- package/dist/chunk-A5VVBYNT.js +14 -0
- package/dist/chunk-A5VVBYNT.js.map +1 -0
- package/dist/chunk-ADQTZVMH.js +15 -0
- package/dist/chunk-ADQTZVMH.js.map +1 -0
- package/dist/chunk-AHMKY474.js +13 -0
- package/dist/chunk-AHMKY474.js.map +1 -0
- package/dist/chunk-BH2YB4MV.js +13 -0
- package/dist/chunk-BH2YB4MV.js.map +1 -0
- package/dist/chunk-BQBLSXK2.js +13 -0
- package/dist/chunk-BQBLSXK2.js.map +1 -0
- package/dist/chunk-CY746ZUQ.js +15 -0
- package/dist/chunk-CY746ZUQ.js.map +1 -0
- package/dist/chunk-DT2EWLHU.js +14 -0
- package/dist/chunk-DT2EWLHU.js.map +1 -0
- package/dist/chunk-EEQ3REET.js +15 -0
- package/dist/chunk-EEQ3REET.js.map +1 -0
- package/dist/chunk-EYO2ZJLH.js +14 -0
- package/dist/chunk-EYO2ZJLH.js.map +1 -0
- package/dist/chunk-HDBH7RTY.js +13 -0
- package/dist/chunk-HDBH7RTY.js.map +1 -0
- package/dist/chunk-ISHZRFVN.js +15 -0
- package/dist/chunk-ISHZRFVN.js.map +1 -0
- package/dist/chunk-J6G2I2TU.js +13 -0
- package/dist/chunk-J6G2I2TU.js.map +1 -0
- package/dist/chunk-JOD4ATPE.js +15 -0
- package/dist/chunk-JOD4ATPE.js.map +1 -0
- package/dist/chunk-L4SVABDH.js +14 -0
- package/dist/chunk-L4SVABDH.js.map +1 -0
- package/dist/chunk-LDO6PRNJ.js +15 -0
- package/dist/chunk-LDO6PRNJ.js.map +1 -0
- package/dist/chunk-NRD5HRZV.js +14 -0
- package/dist/chunk-NRD5HRZV.js.map +1 -0
- package/dist/chunk-PPB62JYV.js +15 -0
- package/dist/chunk-PPB62JYV.js.map +1 -0
- package/dist/chunk-Q2F3HEXB.js +14 -0
- package/dist/chunk-Q2F3HEXB.js.map +1 -0
- package/dist/chunk-S63QUP4W.js +15 -0
- package/dist/chunk-S63QUP4W.js.map +1 -0
- package/dist/chunk-U4RNUZXO.js +13 -0
- package/dist/chunk-U4RNUZXO.js.map +1 -0
- package/dist/chunk-V27NUBXQ.js +14 -0
- package/dist/chunk-V27NUBXQ.js.map +1 -0
- package/dist/chunk-VLZ3HQQA.js +15 -0
- package/dist/chunk-VLZ3HQQA.js.map +1 -0
- package/dist/chunk-WVHAYLBW.js +13 -0
- package/dist/chunk-WVHAYLBW.js.map +1 -0
- package/dist/chunk-XEDXPI5G.js +94 -0
- package/dist/chunk-XEDXPI5G.js.map +1 -0
- package/dist/chunk-XW5MLXX5.js +13 -0
- package/dist/chunk-XW5MLXX5.js.map +1 -0
- package/dist/chunk-YKBP3G7L.js +13 -0
- package/dist/chunk-YKBP3G7L.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +139 -19
- package/dist/intlFormatDistance.d.ts +85 -0
- package/dist/intlFormatDistance.d.ts.map +1 -0
- package/dist/intlFormatDistance.js +15 -0
- package/dist/intlFormatDistance.js.map +1 -0
- package/dist/intlFormatDistance.test.d.ts +2 -0
- package/dist/intlFormatDistance.test.d.ts.map +1 -0
- package/dist/isSameHour.d.ts +58 -0
- package/dist/isSameHour.d.ts.map +1 -0
- package/dist/isSameHour.js +8 -0
- package/dist/isSameHour.js.map +1 -0
- package/dist/isSameHour.test.d.ts +2 -0
- package/dist/isSameHour.test.d.ts.map +1 -0
- package/dist/isSameMicrosecond.d.ts +59 -0
- package/dist/isSameMicrosecond.d.ts.map +1 -0
- package/dist/isSameMicrosecond.js +8 -0
- package/dist/isSameMicrosecond.js.map +1 -0
- package/dist/isSameMicrosecond.test.d.ts +2 -0
- package/dist/isSameMicrosecond.test.d.ts.map +1 -0
- package/dist/isSameMillisecond.d.ts +59 -0
- package/dist/isSameMillisecond.d.ts.map +1 -0
- package/dist/isSameMillisecond.js +8 -0
- package/dist/isSameMillisecond.js.map +1 -0
- package/dist/isSameMillisecond.test.d.ts +2 -0
- package/dist/isSameMillisecond.test.d.ts.map +1 -0
- package/dist/isSameMinute.d.ts +58 -0
- package/dist/isSameMinute.d.ts.map +1 -0
- package/dist/isSameMinute.js +8 -0
- package/dist/isSameMinute.js.map +1 -0
- package/dist/isSameMinute.test.d.ts +2 -0
- package/dist/isSameMinute.test.d.ts.map +1 -0
- package/dist/isSameMonth.d.ts +58 -0
- package/dist/isSameMonth.d.ts.map +1 -0
- package/dist/isSameMonth.js +8 -0
- package/dist/isSameMonth.js.map +1 -0
- package/dist/isSameMonth.test.d.ts +2 -0
- package/dist/isSameMonth.test.d.ts.map +1 -0
- package/dist/isSameNanosecond.d.ts +59 -0
- package/dist/isSameNanosecond.d.ts.map +1 -0
- package/dist/isSameNanosecond.js +8 -0
- package/dist/isSameNanosecond.js.map +1 -0
- package/dist/isSameNanosecond.test.d.ts +2 -0
- package/dist/isSameNanosecond.test.d.ts.map +1 -0
- package/dist/isSameSecond.d.ts +59 -0
- package/dist/isSameSecond.d.ts.map +1 -0
- package/dist/isSameSecond.js +8 -0
- package/dist/isSameSecond.js.map +1 -0
- package/dist/isSameSecond.test.d.ts +2 -0
- package/dist/isSameSecond.test.d.ts.map +1 -0
- package/dist/isSameWeek.d.ts +72 -0
- package/dist/isSameWeek.d.ts.map +1 -0
- package/dist/isSameWeek.js +8 -0
- package/dist/isSameWeek.js.map +1 -0
- package/dist/isSameWeek.test.d.ts +2 -0
- package/dist/isSameWeek.test.d.ts.map +1 -0
- package/dist/isSameYear.d.ts +58 -0
- package/dist/isSameYear.d.ts.map +1 -0
- package/dist/isSameYear.js +8 -0
- package/dist/isSameYear.js.map +1 -0
- package/dist/isSameYear.test.d.ts +2 -0
- package/dist/isSameYear.test.d.ts.map +1 -0
- package/dist/subDays.d.ts +20 -0
- package/dist/subDays.d.ts.map +1 -0
- package/dist/subDays.js +9 -0
- package/dist/subDays.js.map +1 -0
- package/dist/subDays.test.d.ts +2 -0
- package/dist/subDays.test.d.ts.map +1 -0
- package/dist/subHours.d.ts +20 -0
- package/dist/subHours.d.ts.map +1 -0
- package/dist/subHours.js +9 -0
- package/dist/subHours.js.map +1 -0
- package/dist/subHours.test.d.ts +2 -0
- package/dist/subHours.test.d.ts.map +1 -0
- package/dist/subMicroseconds.d.ts +19 -0
- package/dist/subMicroseconds.d.ts.map +1 -0
- package/dist/subMicroseconds.js +9 -0
- package/dist/subMicroseconds.js.map +1 -0
- package/dist/subMicroseconds.test.d.ts +2 -0
- package/dist/subMicroseconds.test.d.ts.map +1 -0
- package/dist/subMilliseconds.d.ts +19 -0
- package/dist/subMilliseconds.d.ts.map +1 -0
- package/dist/subMilliseconds.js +9 -0
- package/dist/subMilliseconds.js.map +1 -0
- package/dist/subMilliseconds.test.d.ts +2 -0
- package/dist/subMilliseconds.test.d.ts.map +1 -0
- package/dist/subMinutes.d.ts +19 -0
- package/dist/subMinutes.d.ts.map +1 -0
- package/dist/subMinutes.js +9 -0
- package/dist/subMinutes.js.map +1 -0
- package/dist/subMinutes.test.d.ts +2 -0
- package/dist/subMinutes.test.d.ts.map +1 -0
- package/dist/subMonths.d.ts +20 -0
- package/dist/subMonths.d.ts.map +1 -0
- package/dist/subMonths.js +9 -0
- package/dist/subMonths.js.map +1 -0
- package/dist/subMonths.test.d.ts +2 -0
- package/dist/subMonths.test.d.ts.map +1 -0
- package/dist/subNanoseconds.d.ts +19 -0
- package/dist/subNanoseconds.d.ts.map +1 -0
- package/dist/subNanoseconds.js +9 -0
- package/dist/subNanoseconds.js.map +1 -0
- package/dist/subNanoseconds.test.d.ts +2 -0
- package/dist/subNanoseconds.test.d.ts.map +1 -0
- package/dist/subSeconds.d.ts +19 -0
- package/dist/subSeconds.d.ts.map +1 -0
- package/dist/subSeconds.js +9 -0
- package/dist/subSeconds.js.map +1 -0
- package/dist/subSeconds.test.d.ts +2 -0
- package/dist/subSeconds.test.d.ts.map +1 -0
- package/dist/subWeeks.d.ts +20 -0
- package/dist/subWeeks.d.ts.map +1 -0
- package/dist/subWeeks.js +9 -0
- package/dist/subWeeks.js.map +1 -0
- package/dist/subWeeks.test.d.ts +2 -0
- package/dist/subWeeks.test.d.ts.map +1 -0
- package/dist/subYears.d.ts +20 -0
- package/dist/subYears.d.ts.map +1 -0
- package/dist/subYears.js +9 -0
- package/dist/subYears.js.map +1 -0
- package/dist/subYears.test.d.ts +2 -0
- package/dist/subYears.test.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# tiempo
|
|
1
|
+
# @gobrand/tiempo
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@gobrand/tiempo)
|
|
4
4
|
[](https://github.com/go-brand/tiempo/actions/workflows/ci.yml)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Comprehensive datetime utilities for the [Temporal API](https://tc39.es/proposal-temporal/docs/). Full timezone support, nanosecond precision, and 54+ utility functions with a familiar API.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -18,12 +18,30 @@ yarn add @gobrand/tiempo
|
|
|
18
18
|
|
|
19
19
|
## Why tiempo?
|
|
20
20
|
|
|
21
|
-
The Temporal API is powerful but requires understanding its various methods and objects.
|
|
21
|
+
The Temporal API is powerful but requires understanding its various methods and objects. **tiempo** (`@gobrand/tiempo`) provides 54+ intuitive utilities for every datetime task:
|
|
22
|
+
|
|
23
|
+
- **🌍 Timezone conversions** - Convert between UTC and any timezone effortlessly
|
|
24
|
+
- **➕ Complete arithmetic** - Add/subtract any time unit from nanoseconds to years
|
|
25
|
+
- **📅 Calendar operations** - Start/end of day, week, month, year with DST handling
|
|
26
|
+
- **🔍 Comparisons** - Check if dates are before, after, same day, future, or past
|
|
27
|
+
- **📊 Differences** - Calculate precise differences in any time unit
|
|
28
|
+
- **🎨 Formatting** - Format dates with date-fns-style tokens or Intl
|
|
29
|
+
- **⚡️ Type-safe** - Full TypeScript support with proper Temporal types
|
|
30
|
+
- **🎯 Zero config** - Simple, direct function signatures
|
|
31
|
+
|
|
32
|
+
**Key features:**
|
|
33
|
+
- ✅ Native timezone support with Temporal API
|
|
34
|
+
- ✅ DST transitions handled automatically
|
|
35
|
+
- ✅ Nanosecond precision (beyond milliseconds)
|
|
36
|
+
- ✅ Calendar-aware arithmetic (leap years, month-end dates)
|
|
37
|
+
- ✅ Familiar date-fns-style API, built for the future
|
|
22
38
|
|
|
23
39
|
**Perfect for:**
|
|
24
40
|
- Social media scheduling apps
|
|
25
41
|
- Calendar applications
|
|
26
42
|
- Booking systems
|
|
43
|
+
- Time tracking tools
|
|
44
|
+
- Analytics dashboards
|
|
27
45
|
- Any app that needs to handle user timezones
|
|
28
46
|
|
|
29
47
|
## Quick Start
|
|
@@ -120,6 +138,84 @@ console.log(iso2); // "2025-01-20T20:00:00Z"
|
|
|
120
138
|
|
|
121
139
|
### Formatting
|
|
122
140
|
|
|
141
|
+
#### `intlFormatDistance(laterDate, earlierDate, options?)`
|
|
142
|
+
|
|
143
|
+
Format the distance between two dates as a human-readable, internationalized string using `Intl.RelativeTimeFormat`. Automatically selects the most appropriate unit (seconds, minutes, hours, days, weeks, months, years) based on the distance.
|
|
144
|
+
|
|
145
|
+
**Parameters:**
|
|
146
|
+
- `laterDate` (Temporal.Instant | Temporal.ZonedDateTime): The later date to compare
|
|
147
|
+
- `earlierDate` (Temporal.Instant | Temporal.ZonedDateTime): The earlier date to compare with
|
|
148
|
+
- `options` (IntlFormatDistanceOptions, optional): Formatting options
|
|
149
|
+
- `unit` (Intl.RelativeTimeFormatUnit): Force a specific unit instead of automatic selection
|
|
150
|
+
- `locale` (string | string[]): Locale for formatting (default: system locale)
|
|
151
|
+
- `numeric` ('always' | 'auto'): Use numeric values always or allow natural language like "tomorrow" (default: 'auto')
|
|
152
|
+
- `style` ('long' | 'short' | 'narrow'): Formatting style (default: 'long')
|
|
153
|
+
- `localeMatcher` ('best fit' | 'lookup'): Locale matching algorithm
|
|
154
|
+
|
|
155
|
+
**Returns:** `string` - Formatted relative time string
|
|
156
|
+
|
|
157
|
+
**Automatic unit selection:**
|
|
158
|
+
- < 60 seconds → "in X seconds" / "X seconds ago"
|
|
159
|
+
- < 60 minutes → "in X minutes" / "X minutes ago"
|
|
160
|
+
- < 24 hours → "in X hours" / "X hours ago"
|
|
161
|
+
- < 7 days → "tomorrow" / "yesterday" / "in X days" / "X days ago"
|
|
162
|
+
- < 4 weeks → "next week" / "last week" / "in X weeks" / "X weeks ago"
|
|
163
|
+
- < 12 months → "next month" / "last month" / "in X months" / "X months ago"
|
|
164
|
+
- ≥ 12 months → "next year" / "last year" / "in X years" / "X years ago"
|
|
165
|
+
|
|
166
|
+
**Example:**
|
|
167
|
+
```typescript
|
|
168
|
+
import { intlFormatDistance } from '@gobrand/tiempo';
|
|
169
|
+
|
|
170
|
+
const later = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
171
|
+
const earlier = Temporal.Instant.from('2025-01-20T11:00:00Z');
|
|
172
|
+
|
|
173
|
+
// Basic usage
|
|
174
|
+
intlFormatDistance(later, earlier);
|
|
175
|
+
// => "in 1 hour"
|
|
176
|
+
|
|
177
|
+
intlFormatDistance(earlier, later);
|
|
178
|
+
// => "1 hour ago"
|
|
179
|
+
|
|
180
|
+
// With different locales
|
|
181
|
+
intlFormatDistance(later, earlier, { locale: 'es' });
|
|
182
|
+
// => "dentro de 1 hora"
|
|
183
|
+
|
|
184
|
+
intlFormatDistance(later, earlier, { locale: 'ja' });
|
|
185
|
+
// => "1 時間後"
|
|
186
|
+
|
|
187
|
+
// Force numeric format
|
|
188
|
+
const tomorrow = Temporal.Instant.from('2025-01-21T00:00:00Z');
|
|
189
|
+
const today = Temporal.Instant.from('2025-01-20T00:00:00Z');
|
|
190
|
+
|
|
191
|
+
intlFormatDistance(tomorrow, today, { numeric: 'auto' });
|
|
192
|
+
// => "tomorrow"
|
|
193
|
+
|
|
194
|
+
intlFormatDistance(tomorrow, today, { numeric: 'always' });
|
|
195
|
+
// => "in 1 day"
|
|
196
|
+
|
|
197
|
+
// Different styles
|
|
198
|
+
const future = Temporal.Instant.from('2027-01-20T00:00:00Z');
|
|
199
|
+
const now = Temporal.Instant.from('2025-01-20T00:00:00Z');
|
|
200
|
+
|
|
201
|
+
intlFormatDistance(future, now, { style: 'long' });
|
|
202
|
+
// => "in 2 years"
|
|
203
|
+
|
|
204
|
+
intlFormatDistance(future, now, { style: 'short' });
|
|
205
|
+
// => "in 2 yr."
|
|
206
|
+
|
|
207
|
+
intlFormatDistance(future, now, { style: 'narrow' });
|
|
208
|
+
// => "in 2y"
|
|
209
|
+
|
|
210
|
+
// Force specific units
|
|
211
|
+
intlFormatDistance(future, now, { unit: 'quarter' });
|
|
212
|
+
// => "in 8 quarters"
|
|
213
|
+
|
|
214
|
+
const dayLater = Temporal.Instant.from('2025-01-21T00:00:00Z');
|
|
215
|
+
intlFormatDistance(dayLater, today, { unit: 'hour' });
|
|
216
|
+
// => "in 24 hours"
|
|
217
|
+
```
|
|
218
|
+
|
|
123
219
|
#### `format(input, formatStr, options?)`
|
|
124
220
|
|
|
125
221
|
Format a Temporal.Instant or ZonedDateTime using date-fns-like format tokens.
|
|
@@ -268,6 +364,138 @@ startOfYear(zoned); // 2025-01-01T00:00:00-05:00[America/New_York]
|
|
|
268
364
|
endOfYear(zoned); // 2025-12-31T23:59:59.999999999-05:00[America/New_York]
|
|
269
365
|
```
|
|
270
366
|
|
|
367
|
+
### Addition/Subtraction Utilities
|
|
368
|
+
|
|
369
|
+
tiempo provides comprehensive datetime arithmetic functions for all time units, from nanoseconds to years. All functions:
|
|
370
|
+
- Accept `Temporal.Instant` or `Temporal.ZonedDateTime` as input
|
|
371
|
+
- Return `Temporal.ZonedDateTime` preserving the original timezone
|
|
372
|
+
- Properly handle DST transitions, leap years, and month-end edge cases
|
|
373
|
+
- Support negative values for subtraction
|
|
374
|
+
|
|
375
|
+
#### Addition Functions
|
|
376
|
+
|
|
377
|
+
##### `addYears(input, years)` / `addMonths(input, months)` / `addWeeks(input, weeks)` / `addDays(input, days)`
|
|
378
|
+
|
|
379
|
+
Add calendar units (years, months, weeks, or days) to a datetime.
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
import { addYears, addMonths, addWeeks, addDays } from '@gobrand/tiempo';
|
|
383
|
+
|
|
384
|
+
const date = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
385
|
+
|
|
386
|
+
addYears(date, 2); // 2027-01-20T12:00:00Z[UTC] (2 years later)
|
|
387
|
+
addMonths(date, 3); // 2025-04-20T12:00:00Z[UTC] (3 months later)
|
|
388
|
+
addWeeks(date, 2); // 2025-02-03T12:00:00Z[UTC] (2 weeks later)
|
|
389
|
+
addDays(date, 5); // 2025-01-25T12:00:00Z[UTC] (5 days later)
|
|
390
|
+
|
|
391
|
+
// Handle month-end edge cases automatically
|
|
392
|
+
const endOfJan = Temporal.Instant.from('2025-01-31T12:00:00Z');
|
|
393
|
+
addMonths(endOfJan, 1); // 2025-02-28T12:00:00Z[UTC] (Jan 31 → Feb 28)
|
|
394
|
+
|
|
395
|
+
// Negative values subtract
|
|
396
|
+
addMonths(date, -3); // 2024-10-20T12:00:00Z[UTC] (3 months earlier)
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
##### `addHours(input, hours)` / `addMinutes(input, minutes)` / `addSeconds(input, seconds)`
|
|
400
|
+
|
|
401
|
+
Add time units (hours, minutes, or seconds) to a datetime.
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
import { addHours, addMinutes, addSeconds } from '@gobrand/tiempo';
|
|
405
|
+
|
|
406
|
+
const time = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
407
|
+
|
|
408
|
+
addHours(time, 3); // 2025-01-20T15:00:00Z[UTC] (3 hours later)
|
|
409
|
+
addMinutes(time, 30); // 2025-01-20T12:30:00Z[UTC] (30 minutes later)
|
|
410
|
+
addSeconds(time, 45); // 2025-01-20T12:00:45Z[UTC] (45 seconds later)
|
|
411
|
+
|
|
412
|
+
// Works with ZonedDateTime and preserves timezone
|
|
413
|
+
const ny = Temporal.ZonedDateTime.from('2025-01-20T15:00:00-05:00[America/New_York]');
|
|
414
|
+
addHours(ny, 2); // 2025-01-20T17:00:00-05:00[America/New_York]
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
##### `addMilliseconds(input, ms)` / `addMicroseconds(input, μs)` / `addNanoseconds(input, ns)`
|
|
418
|
+
|
|
419
|
+
Add sub-second precision units (milliseconds, microseconds, or nanoseconds) to a datetime.
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
import { addMilliseconds, addMicroseconds, addNanoseconds } from '@gobrand/tiempo';
|
|
423
|
+
|
|
424
|
+
const precise = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
425
|
+
|
|
426
|
+
addMilliseconds(precise, 500); // 2025-01-20T12:00:00.500Z[UTC]
|
|
427
|
+
addMicroseconds(precise, 500); // 2025-01-20T12:00:00.000500Z[UTC]
|
|
428
|
+
addNanoseconds(precise, 500); // 2025-01-20T12:00:00.000000500Z[UTC]
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
#### Subtraction Functions
|
|
432
|
+
|
|
433
|
+
All subtraction functions are convenience wrappers that call their corresponding addition functions with negated values.
|
|
434
|
+
|
|
435
|
+
##### `subYears(input, years)` / `subMonths(input, months)` / `subWeeks(input, weeks)` / `subDays(input, days)`
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
import { subYears, subMonths, subWeeks, subDays } from '@gobrand/tiempo';
|
|
439
|
+
|
|
440
|
+
const date = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
441
|
+
|
|
442
|
+
subYears(date, 2); // 2023-01-20T12:00:00Z[UTC] (2 years earlier)
|
|
443
|
+
subMonths(date, 3); // 2024-10-20T12:00:00Z[UTC] (3 months earlier)
|
|
444
|
+
subWeeks(date, 2); // 2025-01-06T12:00:00Z[UTC] (2 weeks earlier)
|
|
445
|
+
subDays(date, 5); // 2025-01-15T12:00:00Z[UTC] (5 days earlier)
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
##### `subHours(input, hours)` / `subMinutes(input, minutes)` / `subSeconds(input, seconds)`
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
import { subHours, subMinutes, subSeconds } from '@gobrand/tiempo';
|
|
452
|
+
|
|
453
|
+
const time = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
454
|
+
|
|
455
|
+
subHours(time, 3); // 2025-01-20T09:00:00Z[UTC] (3 hours earlier)
|
|
456
|
+
subMinutes(time, 30); // 2025-01-20T11:30:00Z[UTC] (30 minutes earlier)
|
|
457
|
+
subSeconds(time, 45); // 2025-01-20T11:59:15Z[UTC] (45 seconds earlier)
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
##### `subMilliseconds(input, ms)` / `subMicroseconds(input, μs)` / `subNanoseconds(input, ns)`
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
import { subMilliseconds, subMicroseconds, subNanoseconds } from '@gobrand/tiempo';
|
|
464
|
+
|
|
465
|
+
const precise = Temporal.Instant.from('2025-01-20T12:00:00.500Z');
|
|
466
|
+
|
|
467
|
+
subMilliseconds(precise, 250); // 2025-01-20T12:00:00.250Z[UTC]
|
|
468
|
+
subMicroseconds(precise, 250); // 2025-01-20T12:00:00.499750Z[UTC]
|
|
469
|
+
subNanoseconds(precise, 250); // 2025-01-20T12:00:00.499999750Z[UTC]
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
#### Real-world Example: Meeting Scheduler
|
|
473
|
+
|
|
474
|
+
```typescript
|
|
475
|
+
import {
|
|
476
|
+
toZonedTime,
|
|
477
|
+
addDays,
|
|
478
|
+
addMinutes,
|
|
479
|
+
format
|
|
480
|
+
} from '@gobrand/tiempo';
|
|
481
|
+
|
|
482
|
+
// User's current meeting time
|
|
483
|
+
const meeting = toZonedTime('2025-01-20T15:00:00Z', 'America/New_York');
|
|
484
|
+
// 2025-01-20T10:00:00-05:00[America/New_York] (10 AM in NY)
|
|
485
|
+
|
|
486
|
+
// Reschedule to tomorrow, same time
|
|
487
|
+
const tomorrow = addDays(meeting, 1);
|
|
488
|
+
format(tomorrow, 'EEEE, MMMM do'); // "Tuesday, January 21st"
|
|
489
|
+
|
|
490
|
+
// Add 30-minute buffer before the meeting
|
|
491
|
+
const arriveBy = subMinutes(tomorrow, 30);
|
|
492
|
+
format(arriveBy, 'h:mm a'); // "9:30 AM"
|
|
493
|
+
|
|
494
|
+
// Schedule follow-up 2 weeks later
|
|
495
|
+
const followUp = addWeeks(tomorrow, 2);
|
|
496
|
+
format(followUp, 'MMM d'); // "Feb 4"
|
|
497
|
+
```
|
|
498
|
+
|
|
271
499
|
### Comparison Utilities
|
|
272
500
|
|
|
273
501
|
#### `isBefore(date1, date2)` / `isAfter(date1, date2)`
|
|
@@ -472,12 +700,21 @@ const instant2 = Temporal.Instant.from('2025-01-20T23:00:00Z');
|
|
|
472
700
|
isSameDay(instant1, instant2); // true (both Jan 20 in UTC)
|
|
473
701
|
```
|
|
474
702
|
|
|
475
|
-
## Real World
|
|
703
|
+
## Real World Examples
|
|
476
704
|
|
|
477
|
-
|
|
705
|
+
### Example 1: Social Media Post Scheduler
|
|
706
|
+
|
|
707
|
+
This example demonstrates the complete workflow of working with datetimes in a frontend application: receiving a UTC ISO 8601 string from your backend, converting it to a Temporal object in the user's timezone, formatting it for display, manipulating it with tiempo's arithmetic functions, and sending it back to your backend as a UTC ISO 8601 string.
|
|
478
708
|
|
|
479
709
|
```typescript
|
|
480
|
-
import {
|
|
710
|
+
import {
|
|
711
|
+
toZonedTime,
|
|
712
|
+
toUtcString,
|
|
713
|
+
format,
|
|
714
|
+
addDays,
|
|
715
|
+
addHours,
|
|
716
|
+
subMinutes
|
|
717
|
+
} from '@gobrand/tiempo';
|
|
481
718
|
|
|
482
719
|
// 1. Receive UTC ISO 8601 string from backend
|
|
483
720
|
const scheduledAtUTC = "2025-01-20T20:00:00.000Z";
|
|
@@ -490,16 +727,53 @@ const zonedDateTime = toZonedTime(scheduledAtUTC, userTimezone);
|
|
|
490
727
|
const displayTime = format(zonedDateTime, "EEEE, MMMM do 'at' h:mm a");
|
|
491
728
|
console.log(displayTime); // "Monday, January 20th at 3:00 PM"
|
|
492
729
|
|
|
493
|
-
// 4. User
|
|
494
|
-
const
|
|
730
|
+
// 4. User wants to reschedule to tomorrow, 2 hours later
|
|
731
|
+
const tomorrow = addDays(zonedDateTime, 1);
|
|
732
|
+
const twoHoursLater = addHours(tomorrow, 2);
|
|
495
733
|
|
|
496
734
|
// 5. Format the updated time for confirmation
|
|
497
|
-
const confirmTime = format(
|
|
498
|
-
console.log(`Rescheduled to ${confirmTime}`); // "
|
|
735
|
+
const confirmTime = format(twoHoursLater, "EEEE 'at' h:mm a");
|
|
736
|
+
console.log(`Rescheduled to ${confirmTime}`); // "Tuesday at 5:00 PM"
|
|
499
737
|
|
|
500
738
|
// 6. Convert back to UTC ISO 8601 string for backend
|
|
501
|
-
const updatedUTC = toUtcString(
|
|
502
|
-
console.log(updatedUTC); // "2025-01-
|
|
739
|
+
const updatedUTC = toUtcString(twoHoursLater);
|
|
740
|
+
console.log(updatedUTC); // "2025-01-21T22:00:00Z"
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
### Example 2: Meeting Reminder System
|
|
744
|
+
|
|
745
|
+
```typescript
|
|
746
|
+
import {
|
|
747
|
+
toZonedTime,
|
|
748
|
+
format,
|
|
749
|
+
subMinutes,
|
|
750
|
+
subHours,
|
|
751
|
+
differenceInMinutes,
|
|
752
|
+
isFuture
|
|
753
|
+
} from '@gobrand/tiempo';
|
|
754
|
+
|
|
755
|
+
// Meeting scheduled for 2 PM
|
|
756
|
+
const meeting = toZonedTime('2025-01-20T19:00:00Z', 'America/New_York');
|
|
757
|
+
// 2025-01-20T14:00:00-05:00[America/New_York]
|
|
758
|
+
|
|
759
|
+
// Send reminders at multiple intervals
|
|
760
|
+
const reminders = [
|
|
761
|
+
{ time: subMinutes(meeting, 15), label: '15 minutes before' },
|
|
762
|
+
{ time: subHours(meeting, 1), label: '1 hour before' },
|
|
763
|
+
{ time: subHours(meeting, 24), label: '1 day before' },
|
|
764
|
+
];
|
|
765
|
+
|
|
766
|
+
reminders.forEach(({ time, label }) => {
|
|
767
|
+
if (isFuture(time)) {
|
|
768
|
+
const formatted = format(time, 'MMM d, h:mm a');
|
|
769
|
+
console.log(`Send reminder "${label}" at ${formatted}`);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
|
|
773
|
+
// Calculate time until meeting
|
|
774
|
+
const now = Temporal.Now.zonedDateTimeISO('America/New_York');
|
|
775
|
+
const minutesUntil = differenceInMinutes(meeting, now);
|
|
776
|
+
console.log(`Meeting starts in ${minutesUntil} minutes`);
|
|
503
777
|
```
|
|
504
778
|
|
|
505
779
|
## Browser Support
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the specified number of days to a datetime.
|
|
4
|
+
*
|
|
5
|
+
* Properly handles DST transitions and calendar edge cases through Temporal API.
|
|
6
|
+
* Instant inputs are converted to UTC. For ZonedDateTime inputs, their timezone is preserved.
|
|
7
|
+
*
|
|
8
|
+
* @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime
|
|
9
|
+
* @param days - Number of days to add (can be negative to subtract)
|
|
10
|
+
* @returns ZonedDateTime with days added, in the same timezone as input
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // From Instant (always UTC)
|
|
15
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
16
|
+
* const result = addDays(instant, 5);
|
|
17
|
+
* // 2025-01-25T12:00:00Z[UTC] (5 days later)
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // From ZonedDateTime (preserves timezone)
|
|
23
|
+
* const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');
|
|
24
|
+
* const result = addDays(zoned, 10);
|
|
25
|
+
* // 2025-01-30T15:30:00-05:00[America/New_York]
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Negative values subtract days
|
|
31
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
32
|
+
* const result = addDays(instant, -7);
|
|
33
|
+
* // 2025-01-13T12:00:00Z[UTC] (7 days earlier)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function addDays(input: Temporal.Instant | Temporal.ZonedDateTime, days: number): Temporal.ZonedDateTime;
|
|
37
|
+
//# sourceMappingURL=addDays.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addDays.d.ts","sourceRoot":"","sources":["../src/addDays.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,OAAO,CACrB,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChD,IAAI,EAAE,MAAM,GACX,QAAQ,CAAC,aAAa,CAGxB"}
|
package/dist/addDays.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addDays.test.d.ts","sourceRoot":"","sources":["../src/addDays.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the specified number of hours to a datetime.
|
|
4
|
+
*
|
|
5
|
+
* Properly handles DST transitions through Temporal API.
|
|
6
|
+
* Instant inputs are converted to UTC. For ZonedDateTime inputs, their timezone is preserved.
|
|
7
|
+
*
|
|
8
|
+
* @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime
|
|
9
|
+
* @param hours - Number of hours to add (can be negative to subtract)
|
|
10
|
+
* @returns ZonedDateTime with hours added, in the same timezone as input
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* // From Instant (always UTC)
|
|
15
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
16
|
+
* const result = addHours(instant, 3);
|
|
17
|
+
* // 2025-01-20T15:00:00Z[UTC] (3 hours later)
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // From ZonedDateTime (preserves timezone)
|
|
23
|
+
* const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');
|
|
24
|
+
* const result = addHours(zoned, 24);
|
|
25
|
+
* // 2025-01-21T15:30:00-05:00[America/New_York]
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // Negative values subtract hours
|
|
31
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
32
|
+
* const result = addHours(instant, -5);
|
|
33
|
+
* // 2025-01-20T07:00:00Z[UTC] (5 hours earlier)
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function addHours(input: Temporal.Instant | Temporal.ZonedDateTime, hours: number): Temporal.ZonedDateTime;
|
|
37
|
+
//# sourceMappingURL=addHours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addHours.d.ts","sourceRoot":"","sources":["../src/addHours.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChD,KAAK,EAAE,MAAM,GACZ,QAAQ,CAAC,aAAa,CAGxB"}
|
package/dist/addHours.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addHours.test.d.ts","sourceRoot":"","sources":["../src/addHours.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the specified number of microseconds to a datetime.
|
|
4
|
+
*
|
|
5
|
+
* Instant inputs are converted to UTC. For ZonedDateTime inputs, their timezone is preserved.
|
|
6
|
+
*
|
|
7
|
+
* @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime
|
|
8
|
+
* @param microseconds - Number of microseconds to add (can be negative to subtract)
|
|
9
|
+
* @returns ZonedDateTime with microseconds added, in the same timezone as input
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // From Instant (always UTC)
|
|
14
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
15
|
+
* const result = addMicroseconds(instant, 500);
|
|
16
|
+
* // 2025-01-20T12:00:00.000500Z[UTC] (500 microseconds later)
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // From ZonedDateTime (preserves timezone)
|
|
22
|
+
* const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');
|
|
23
|
+
* const result = addMicroseconds(zoned, 1000);
|
|
24
|
+
* // 2025-01-20T15:30:00.001-05:00[America/New_York]
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // Negative values subtract microseconds
|
|
30
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00.001Z');
|
|
31
|
+
* const result = addMicroseconds(instant, -500);
|
|
32
|
+
* // 2025-01-20T12:00:00.000500Z[UTC] (500 microseconds earlier)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function addMicroseconds(input: Temporal.Instant | Temporal.ZonedDateTime, microseconds: number): Temporal.ZonedDateTime;
|
|
36
|
+
//# sourceMappingURL=addMicroseconds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMicroseconds.d.ts","sourceRoot":"","sources":["../src/addMicroseconds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChD,YAAY,EAAE,MAAM,GACnB,QAAQ,CAAC,aAAa,CAGxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMicroseconds.test.d.ts","sourceRoot":"","sources":["../src/addMicroseconds.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the specified number of milliseconds to a datetime.
|
|
4
|
+
*
|
|
5
|
+
* Instant inputs are converted to UTC. For ZonedDateTime inputs, their timezone is preserved.
|
|
6
|
+
*
|
|
7
|
+
* @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime
|
|
8
|
+
* @param milliseconds - Number of milliseconds to add (can be negative to subtract)
|
|
9
|
+
* @returns ZonedDateTime with milliseconds added, in the same timezone as input
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // From Instant (always UTC)
|
|
14
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
15
|
+
* const result = addMilliseconds(instant, 500);
|
|
16
|
+
* // 2025-01-20T12:00:00.500Z[UTC] (500 milliseconds later)
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // From ZonedDateTime (preserves timezone)
|
|
22
|
+
* const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');
|
|
23
|
+
* const result = addMilliseconds(zoned, 1500);
|
|
24
|
+
* // 2025-01-20T15:30:01.500-05:00[America/New_York]
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // Negative values subtract milliseconds
|
|
30
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00.500Z');
|
|
31
|
+
* const result = addMilliseconds(instant, -250);
|
|
32
|
+
* // 2025-01-20T12:00:00.250Z[UTC] (250 milliseconds earlier)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function addMilliseconds(input: Temporal.Instant | Temporal.ZonedDateTime, milliseconds: number): Temporal.ZonedDateTime;
|
|
36
|
+
//# sourceMappingURL=addMilliseconds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMilliseconds.d.ts","sourceRoot":"","sources":["../src/addMilliseconds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChD,YAAY,EAAE,MAAM,GACnB,QAAQ,CAAC,aAAa,CAGxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMilliseconds.test.d.ts","sourceRoot":"","sources":["../src/addMilliseconds.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
/**
|
|
3
|
+
* Adds the specified number of minutes to a datetime.
|
|
4
|
+
*
|
|
5
|
+
* Instant inputs are converted to UTC. For ZonedDateTime inputs, their timezone is preserved.
|
|
6
|
+
*
|
|
7
|
+
* @param input - A Temporal.Instant (UTC) or Temporal.ZonedDateTime
|
|
8
|
+
* @param minutes - Number of minutes to add (can be negative to subtract)
|
|
9
|
+
* @returns ZonedDateTime with minutes added, in the same timezone as input
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // From Instant (always UTC)
|
|
14
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
15
|
+
* const result = addMinutes(instant, 30);
|
|
16
|
+
* // 2025-01-20T12:30:00Z[UTC] (30 minutes later)
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // From ZonedDateTime (preserves timezone)
|
|
22
|
+
* const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');
|
|
23
|
+
* const result = addMinutes(zoned, 90);
|
|
24
|
+
* // 2025-01-20T17:00:00-05:00[America/New_York]
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // Negative values subtract minutes
|
|
30
|
+
* const instant = Temporal.Instant.from('2025-01-20T12:00:00Z');
|
|
31
|
+
* const result = addMinutes(instant, -15);
|
|
32
|
+
* // 2025-01-20T11:45:00Z[UTC] (15 minutes earlier)
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function addMinutes(input: Temporal.Instant | Temporal.ZonedDateTime, minutes: number): Temporal.ZonedDateTime;
|
|
36
|
+
//# sourceMappingURL=addMinutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMinutes.d.ts","sourceRoot":"","sources":["../src/addMinutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChD,OAAO,EAAE,MAAM,GACd,QAAQ,CAAC,aAAa,CAGxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addMinutes.test.d.ts","sourceRoot":"","sources":["../src/addMinutes.test.ts"],"names":[],"mappings":""}
|