@gobrand/tiempo 2.1.2 → 2.1.4

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.
Files changed (2) hide show
  1. package/README.md +22 -19
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![CI](https://github.com/go-brand/tiempo/actions/workflows/ci.yml/badge.svg)](https://github.com/go-brand/tiempo/actions/workflows/ci.yml)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
7
- Lightweight utility functions for converting between UTC and timezone-aware datetimes using the [Temporal API](https://tc39.es/proposal-temporal/docs/).
7
+ Lightweight utilities for timezones and datetimes with the [Temporal API](https://tc39.es/proposal-temporal/docs/).
8
8
 
9
9
  ## Installation
10
10
 
@@ -18,7 +18,7 @@ yarn add @gobrand/tiempo
18
18
 
19
19
  ## Why tiempo?
20
20
 
21
- The Temporal API is already designed for timezone conversions, but it requires understanding its various methods and objects. `tiempo` provides a simple, focused API for the most common use case: converting between UTC ISO strings (from your backend) and timezone-aware ZonedDateTime objects (for your frontend).
21
+ The Temporal API is powerful but requires understanding its various methods and objects. `tiempo` provides intuitive utilities for common datetime tasks: timezone conversions, formatting, start/end calculations, and comparisons. Whether you're converting UTC strings from your backend or formatting dates for display, tiempo makes working with timezones straightforward.
22
22
 
23
23
  **Perfect for:**
24
24
  - Social media scheduling apps
@@ -186,22 +186,17 @@ startOfDay(zoned); // 2025-01-20T00:00:00-05:00[America/New_York]
186
186
  endOfDay(zoned); // 2025-01-20T23:59:59.999999999-05:00[America/New_York]
187
187
  ```
188
188
 
189
- #### `startOfWeek(input, options?)` / `endOfWeek(input, options?)`
189
+ #### `startOfWeek(input)` / `endOfWeek(input)`
190
190
 
191
- Get the start or end of the week. Customize the week start day (defaults to Sunday).
191
+ Get the start or end of the week. Uses ISO 8601 week definition (Monday to Sunday).
192
192
 
193
193
  ```typescript
194
194
  import { startOfWeek, endOfWeek } from '@gobrand/tiempo';
195
195
 
196
- const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]');
197
-
198
- // Default: Sunday start
199
- startOfWeek(zoned); // 2025-01-19T00:00:00-05:00[America/New_York]
200
- endOfWeek(zoned); // 2025-01-25T23:59:59.999999999-05:00[America/New_York]
196
+ const zoned = Temporal.ZonedDateTime.from('2025-01-20T15:30:00-05:00[America/New_York]'); // Monday
201
197
 
202
- // Custom: Monday start
203
- startOfWeek(zoned, { weekStartsOn: 1 }); // 2025-01-20T00:00:00-05:00[America/New_York]
204
- endOfWeek(zoned, { weekStartsOn: 1 }); // 2025-01-26T23:59:59.999999999-05:00[America/New_York]
198
+ startOfWeek(zoned); // 2025-01-20T00:00:00-05:00[America/New_York] (Monday)
199
+ endOfWeek(zoned); // 2025-01-26T23:59:59.999999999-05:00[America/New_York] (Sunday)
205
200
  ```
206
201
 
207
202
  #### `startOfMonth(input)` / `endOfMonth(input)`
@@ -288,24 +283,32 @@ const instant2 = Temporal.Instant.from('2025-01-20T23:00:00Z');
288
283
  isSameDay(instant1, instant2); // true (both Jan 20 in UTC)
289
284
  ```
290
285
 
291
- ## Complete Workflow Example
286
+ ## Real World Example
287
+
288
+ 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 based on user input, and sending it back to your backend as a UTC ISO 8601 string.
292
289
 
293
290
  ```typescript
294
- import { toZonedTime, toUtcString } from '@gobrand/tiempo';
291
+ import { toZonedTime, toUtcString, format } from '@gobrand/tiempo';
295
292
 
296
- // 1. Receive UTC datetime from backend
293
+ // 1. Receive UTC ISO 8601 string from backend
297
294
  const scheduledAtUTC = "2025-01-20T20:00:00.000Z";
298
295
 
299
- // 2. Convert to user's timezone for display/editing
296
+ // 2. Convert to user's timezone (Temporal.ZonedDateTime)
300
297
  const userTimezone = "America/New_York";
301
298
  const zonedDateTime = toZonedTime(scheduledAtUTC, userTimezone);
302
299
 
303
- console.log(`Scheduled for: ${zonedDateTime.hour}:00`); // "Scheduled for: 15:00"
300
+ // 3. Format for display in the UI
301
+ const displayTime = format(zonedDateTime, "EEEE, MMMM do 'at' h:mm a");
302
+ console.log(displayTime); // "Monday, January 20th at 3:00 PM"
304
303
 
305
- // 3. User modifies the time
304
+ // 4. User reschedules to 4:00 PM their time
306
305
  const updatedZoned = zonedDateTime.with({ hour: 16 });
307
306
 
308
- // 4. Convert back to UTC for sending to backend
307
+ // 5. Format the updated time for confirmation
308
+ const confirmTime = format(updatedZoned, "h:mm a");
309
+ console.log(`Rescheduled to ${confirmTime}`); // "Rescheduled to 4:00 PM"
310
+
311
+ // 6. Convert back to UTC ISO 8601 string for backend
309
312
  const updatedUTC = toUtcString(updatedZoned);
310
313
  console.log(updatedUTC); // "2025-01-20T21:00:00Z"
311
314
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobrand/tiempo",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
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": {