@gobrand/tiempo 2.3.3 → 2.3.5

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
@@ -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
- 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.
7
+ Comprehensive datetime utilities for the [Temporal API](https://tc39.es/proposal-temporal/docs/). Full timezone support, nanosecond precision, and a familiar API.
8
8
 
9
9
  ## Installation
10
10
 
@@ -18,31 +18,39 @@ 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. **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
38
-
39
- **Perfect for:**
40
- - Social media scheduling apps
41
- - Calendar applications
42
- - Booking systems
43
- - Time tracking tools
44
- - Analytics dashboards
45
- - Any app that needs to handle user timezones
21
+ JavaScript's `Date` object was modeled after a Java class that was deprecated over 25 years ago. It conflates timestamps with calendar dates, only works in UTC or device-local time, and its mutating methods cause countless bugs. The [Temporal API](https://tc39.es/proposal-temporal/docs/) is the modern replacement, designed from the ground up to fix these problems.
22
+
23
+ **tiempo** makes Temporal accessible with an intuitive, date-fns-style API:
24
+
25
+ ### The Temporal Advantage
26
+
27
+ | Problem with `Date` | Temporal Solution | tiempo API |
28
+ |---------------------|-------------------|------------|
29
+ | Only UTC or local time | Any IANA timezone | `toZonedTime(date, "America/New_York")` |
30
+ | Millisecond precision | Nanosecond precision | `addNanoseconds()`, `differenceInNanoseconds()` |
31
+ | Mutating methods | Immutable operations | All functions return new values |
32
+ | Ambiguous representations | Distinct types for each use case | `Instant`, `ZonedDateTime`, `PlainDate` |
33
+ | DST bugs everywhere | DST-aware arithmetic | `addDays()` respects timezone rules |
34
+ | Gregorian calendar only | Multi-calendar support | Works with Hebrew, Chinese, Japanese, and more |
35
+
36
+ ### Features
37
+
38
+ - **First-class timezone support** - Convert, compare, and calculate across any of 400+ IANA timezones with confidence
39
+ - **Nanosecond precision** - Beyond milliseconds for scientific computing, financial systems, and high-frequency operations
40
+ - **DST-safe arithmetic** - Adding days means calendar days, not 24-hour periods that break at clock changes
41
+ - **Immutable by design** - No mutations, no side effects, no surprises
42
+ - **Type-safe** - Full TypeScript support catches datetime errors at compile time
43
+ - **Familiar API** - date-fns-style functions built on modern foundations
44
+ - **Zero dependencies** - Only the Temporal polyfill for browser compatibility
45
+
46
+ ### Perfect for
47
+
48
+ - **Scheduling apps** - Social media, meetings, reminders with proper timezone handling
49
+ - **Booking systems** - Hotels, flights, events across global timezones
50
+ - **Calendar applications** - Date math that respects DST and leap years
51
+ - **Time tracking** - Precise duration calculations with nanosecond accuracy
52
+ - **Analytics dashboards** - Aggregate by day/week/month in user timezones
53
+ - **Global applications** - Any app serving users across multiple timezones
46
54
 
47
55
  ## Quick Start
48
56
 
@@ -355,6 +363,54 @@ const todayFormatted = formatPlainDate(today(), "EEEE, MMMM do");
355
363
  // "Thursday, January 23rd"
356
364
  ```
357
365
 
366
+ #### `simpleFormat(input, options?)`
367
+
368
+ Format a Temporal date in a human-friendly way: "Dec 23" or "Dec 23, 2020". By default, shows the year only if the date is not in the current year. Optionally includes time in 12-hour or 24-hour format.
369
+
370
+ **Parameters:**
371
+ - `input` (Temporal.PlainDate | Temporal.ZonedDateTime | Temporal.Instant): The date to format
372
+ - `options` (object, optional): Formatting options
373
+ - `locale` (string): BCP 47 language tag (default: "en-US")
374
+ - `year` ('auto' | 'always' | 'never'): Control year display (default: 'auto')
375
+ - `time` ('12h' | '24h'): Include time in output (not available for PlainDate)
376
+ - `timeZone` (string): IANA timezone identifier (required for Instant, optional for ZonedDateTime)
377
+
378
+ **Returns:** `string` - Human-friendly formatted date string
379
+
380
+ **Example:**
381
+ ```typescript
382
+ import { simpleFormat, today, now } from '@gobrand/tiempo';
383
+
384
+ // Assuming current year is 2026
385
+ const date2026 = Temporal.ZonedDateTime.from("2026-12-23T15:30:00[America/New_York]");
386
+ const date2020 = Temporal.ZonedDateTime.from("2020-12-23T15:30:00[America/New_York]");
387
+
388
+ // Basic usage - year shown only for past years
389
+ simpleFormat(date2026); // "Dec 23"
390
+ simpleFormat(date2020); // "Dec 23, 2020"
391
+
392
+ // With time
393
+ simpleFormat(date2026, { time: '12h' }); // "Dec 23, 3:30 PM"
394
+ simpleFormat(date2026, { time: '24h' }); // "Dec 23, 15:30"
395
+
396
+ // Control year display
397
+ simpleFormat(date2026, { year: 'always' }); // "Dec 23, 2026"
398
+ simpleFormat(date2020, { year: 'never' }); // "Dec 23"
399
+
400
+ // With Instant (timeZone required)
401
+ const instant = Temporal.Instant.from("2026-12-23T20:30:00Z");
402
+ simpleFormat(instant, { timeZone: 'America/New_York' }); // "Dec 23"
403
+ simpleFormat(instant, { timeZone: 'America/New_York', time: '12h' }); // "Dec 23, 3:30 PM"
404
+
405
+ // With PlainDate (no time option available)
406
+ const plain = Temporal.PlainDate.from("2020-12-23");
407
+ simpleFormat(plain); // "Dec 23, 2020"
408
+
409
+ // Different locales
410
+ simpleFormat(date2020, { locale: 'es-ES' }); // "23 dic 2020"
411
+ simpleFormat(date2020, { locale: 'de-DE' }); // "23. Dez. 2020"
412
+ ```
413
+
358
414
  ### Start/End Utilities
359
415
 
360
416
  #### `today(timezone?)`
@@ -0,0 +1,46 @@
1
+ // src/simpleFormat.ts
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ function simpleFormat(input, options = {}) {
4
+ const locale = options.locale ?? "en-US";
5
+ const time = "time" in options ? options.time : void 0;
6
+ const timeZone = "timeZone" in options ? options.timeZone : void 0;
7
+ const yearOption = "year" in options ? options.year : void 0;
8
+ let year;
9
+ let dateTimeForFormat;
10
+ if (input instanceof Temporal.Instant) {
11
+ const tz = timeZone ?? "UTC";
12
+ const zoned = input.toZonedDateTimeISO(tz);
13
+ year = zoned.year;
14
+ dateTimeForFormat = zoned;
15
+ } else if (input instanceof Temporal.ZonedDateTime) {
16
+ if (timeZone) {
17
+ const zoned = input.toInstant().toZonedDateTimeISO(timeZone);
18
+ year = zoned.year;
19
+ dateTimeForFormat = zoned;
20
+ } else {
21
+ year = input.year;
22
+ dateTimeForFormat = input;
23
+ }
24
+ } else {
25
+ year = input.year;
26
+ dateTimeForFormat = input;
27
+ }
28
+ const currentYear = Temporal.Now.plainDateISO().year;
29
+ const showYear = yearOption === "always" ? true : yearOption === "never" ? false : year !== currentYear;
30
+ const dateOptions = {
31
+ day: "numeric",
32
+ month: "short",
33
+ year: showYear ? "numeric" : void 0
34
+ };
35
+ if (time && !(input instanceof Temporal.PlainDate)) {
36
+ dateOptions.hour = "numeric";
37
+ dateOptions.minute = "2-digit";
38
+ dateOptions.hour12 = time === "12h";
39
+ }
40
+ return dateTimeForFormat.toLocaleString(locale, dateOptions);
41
+ }
42
+
43
+ export {
44
+ simpleFormat
45
+ };
46
+ //# sourceMappingURL=chunk-GQBO2UXH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/simpleFormat.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n// simpleFormat options - discriminated by input type\ninterface PlainDateOptions {\n locale?: string;\n year?: 'auto' | 'always' | 'never';\n}\n\ninterface ZonedDateTimeOptions {\n locale?: string;\n time?: '12h' | '24h';\n timeZone?: string;\n year?: 'auto' | 'always' | 'never';\n}\n\ninterface InstantOptions {\n locale?: string;\n time?: '12h' | '24h';\n timeZone: string; // required for Instant\n year?: 'auto' | 'always' | 'never';\n}\n\n/**\n * Format a Temporal date in a human-friendly way: \"Dec 23\" or \"Dec 23, 2020\"\n *\n * By default (year: 'auto'), shows the year only if the date is not in the current year.\n * Use year: 'always' to always show the year, or year: 'never' to always hide it.\n * Optionally includes time in 12-hour or 24-hour format.\n *\n * @example\n * ```typescript\n * // Assuming current year is 2026\n * const date2026 = Temporal.ZonedDateTime.from(\"2026-12-23T15:30:00[America/New_York]\");\n * const date2020 = Temporal.ZonedDateTime.from(\"2020-12-23T15:30:00[America/New_York]\");\n *\n * simpleFormat(date2026); // \"Dec 23\"\n * simpleFormat(date2020); // \"Dec 23, 2020\"\n * simpleFormat(date2026, { time: '12h' }); // \"Dec 23, 3:30 PM\"\n * simpleFormat(date2026, { time: '24h' }); // \"Dec 23, 15:30\"\n *\n * // Control year display\n * simpleFormat(date2026, { year: 'always' }); // \"Dec 23, 2026\"\n * simpleFormat(date2020, { year: 'never' }); // \"Dec 23\"\n * simpleFormat(date2020, { year: 'auto' }); // \"Dec 23, 2020\" (default behavior)\n *\n * // With Instant (timeZone required)\n * const instant = Temporal.Instant.from(\"2026-12-23T20:30:00Z\");\n * simpleFormat(instant, { timeZone: 'America/New_York' }); // \"Dec 23\"\n * simpleFormat(instant, { timeZone: 'America/New_York', time: '12h' }); // \"Dec 23, 3:30 PM\"\n *\n * // With PlainDate (no time option)\n * const plain = Temporal.PlainDate.from(\"2020-12-23\");\n * simpleFormat(plain); // \"Dec 23, 2020\"\n * ```\n */\nexport function simpleFormat(input: Temporal.PlainDate, options?: PlainDateOptions): string;\nexport function simpleFormat(input: Temporal.ZonedDateTime, options?: ZonedDateTimeOptions): string;\nexport function simpleFormat(input: Temporal.Instant, options: InstantOptions): string;\nexport function simpleFormat(\n input: Temporal.PlainDate | Temporal.ZonedDateTime | Temporal.Instant,\n options: PlainDateOptions | ZonedDateTimeOptions | InstantOptions = {}\n): string {\n const locale = options.locale ?? 'en-US';\n const time = 'time' in options ? options.time : undefined;\n const timeZone = 'timeZone' in options ? options.timeZone : undefined;\n const yearOption = 'year' in options ? options.year : undefined;\n\n // Get year from the input (converting Instant to ZonedDateTime if needed)\n let year: number;\n let dateTimeForFormat: Temporal.PlainDate | Temporal.ZonedDateTime;\n\n if (input instanceof Temporal.Instant) {\n const tz = timeZone ?? 'UTC';\n const zoned = input.toZonedDateTimeISO(tz);\n year = zoned.year;\n dateTimeForFormat = zoned;\n } else if (input instanceof Temporal.ZonedDateTime) {\n if (timeZone) {\n const zoned = input.toInstant().toZonedDateTimeISO(timeZone);\n year = zoned.year;\n dateTimeForFormat = zoned;\n } else {\n year = input.year;\n dateTimeForFormat = input;\n }\n } else {\n year = input.year;\n dateTimeForFormat = input;\n }\n\n // Determine if year should be shown\n const currentYear = Temporal.Now.plainDateISO().year;\n const showYear =\n yearOption === 'always' ? true : yearOption === 'never' ? false : year !== currentYear;\n\n const dateOptions: Intl.DateTimeFormatOptions = {\n day: 'numeric',\n month: 'short',\n year: showYear ? 'numeric' : undefined,\n };\n\n // Add time options if requested and input supports it\n if (time && !(input instanceof Temporal.PlainDate)) {\n dateOptions.hour = 'numeric';\n dateOptions.minute = '2-digit';\n dateOptions.hour12 = time === '12h';\n }\n\n return dateTimeForFormat.toLocaleString(locale, dateOptions);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AA0DlB,SAAS,aACd,OACA,UAAoE,CAAC,GAC7D;AACR,QAAM,SAAS,QAAQ,UAAU;AACjC,QAAM,OAAO,UAAU,UAAU,QAAQ,OAAO;AAChD,QAAM,WAAW,cAAc,UAAU,QAAQ,WAAW;AAC5D,QAAM,aAAa,UAAU,UAAU,QAAQ,OAAO;AAGtD,MAAI;AACJ,MAAI;AAEJ,MAAI,iBAAiB,SAAS,SAAS;AACrC,UAAM,KAAK,YAAY;AACvB,UAAM,QAAQ,MAAM,mBAAmB,EAAE;AACzC,WAAO,MAAM;AACb,wBAAoB;AAAA,EACtB,WAAW,iBAAiB,SAAS,eAAe;AAClD,QAAI,UAAU;AACZ,YAAM,QAAQ,MAAM,UAAU,EAAE,mBAAmB,QAAQ;AAC3D,aAAO,MAAM;AACb,0BAAoB;AAAA,IACtB,OAAO;AACL,aAAO,MAAM;AACb,0BAAoB;AAAA,IACtB;AAAA,EACF,OAAO;AACL,WAAO,MAAM;AACb,wBAAoB;AAAA,EACtB;AAGA,QAAM,cAAc,SAAS,IAAI,aAAa,EAAE;AAChD,QAAM,WACJ,eAAe,WAAW,OAAO,eAAe,UAAU,QAAQ,SAAS;AAE7E,QAAM,cAA0C;AAAA,IAC9C,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM,WAAW,YAAY;AAAA,EAC/B;AAGA,MAAI,QAAQ,EAAE,iBAAiB,SAAS,YAAY;AAClD,gBAAY,OAAO;AACnB,gBAAY,SAAS;AACrB,gBAAY,SAAS,SAAS;AAAA,EAChC;AAEA,SAAO,kBAAkB,eAAe,QAAQ,WAAW;AAC7D;","names":[]}
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { toUtcString } from './toUtcString';
4
4
  export { toDate } from './toDate';
5
5
  export { format, type FormatOptions } from './format';
6
6
  export { formatPlainDate, type FormatPlainDateOptions } from './formatPlainDate';
7
+ export { simpleFormat } from './simpleFormat';
7
8
  export { today } from './today';
8
9
  export { now } from './now';
9
10
  export { startOfDay } from './startOfDay';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":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AE,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,9 +1,15 @@
1
+ import {
2
+ toUtcString
3
+ } from "./chunk-DMKGJY4N.js";
1
4
  import {
2
5
  toZonedTime
3
6
  } from "./chunk-2MP3ESL7.js";
4
7
  import {
5
8
  today
6
9
  } from "./chunk-67QHALIG.js";
10
+ import {
11
+ subMonths
12
+ } from "./chunk-52NEOY34.js";
7
13
  import {
8
14
  subNanoseconds
9
15
  } from "./chunk-WVHAYLBW.js";
@@ -23,8 +29,8 @@ import {
23
29
  toUtc
24
30
  } from "./chunk-BW5SFCKS.js";
25
31
  import {
26
- toUtcString
27
- } from "./chunk-DMKGJY4N.js";
32
+ startOfMonth
33
+ } from "./chunk-TU2UNOOW.js";
28
34
  import {
29
35
  startOfWeek
30
36
  } from "./chunk-2WMXB7QL.js";
@@ -46,9 +52,6 @@ import {
46
52
  import {
47
53
  subMinutes
48
54
  } from "./chunk-J6G2I2TU.js";
49
- import {
50
- subMonths
51
- } from "./chunk-52NEOY34.js";
52
55
  import {
53
56
  isSameMonth
54
57
  } from "./chunk-ADQTZVMH.js";
@@ -67,12 +70,12 @@ import {
67
70
  import {
68
71
  now
69
72
  } from "./chunk-3YGPHHB6.js";
73
+ import {
74
+ simpleFormat
75
+ } from "./chunk-GQBO2UXH.js";
70
76
  import {
71
77
  startOfDay
72
78
  } from "./chunk-TW5EV3DH.js";
73
- import {
74
- startOfMonth
75
- } from "./chunk-TU2UNOOW.js";
76
79
  import {
77
80
  isPlainDateAfter
78
81
  } from "./chunk-BPZ7BRJW.js";
@@ -238,6 +241,7 @@ export {
238
241
  isSameWeek,
239
242
  isSameYear,
240
243
  now,
244
+ simpleFormat,
241
245
  startOfDay,
242
246
  startOfMonth,
243
247
  startOfWeek,
@@ -0,0 +1,55 @@
1
+ import { Temporal } from '@js-temporal/polyfill';
2
+ interface PlainDateOptions {
3
+ locale?: string;
4
+ year?: 'auto' | 'always' | 'never';
5
+ }
6
+ interface ZonedDateTimeOptions {
7
+ locale?: string;
8
+ time?: '12h' | '24h';
9
+ timeZone?: string;
10
+ year?: 'auto' | 'always' | 'never';
11
+ }
12
+ interface InstantOptions {
13
+ locale?: string;
14
+ time?: '12h' | '24h';
15
+ timeZone: string;
16
+ year?: 'auto' | 'always' | 'never';
17
+ }
18
+ /**
19
+ * Format a Temporal date in a human-friendly way: "Dec 23" or "Dec 23, 2020"
20
+ *
21
+ * By default (year: 'auto'), shows the year only if the date is not in the current year.
22
+ * Use year: 'always' to always show the year, or year: 'never' to always hide it.
23
+ * Optionally includes time in 12-hour or 24-hour format.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Assuming current year is 2026
28
+ * const date2026 = Temporal.ZonedDateTime.from("2026-12-23T15:30:00[America/New_York]");
29
+ * const date2020 = Temporal.ZonedDateTime.from("2020-12-23T15:30:00[America/New_York]");
30
+ *
31
+ * simpleFormat(date2026); // "Dec 23"
32
+ * simpleFormat(date2020); // "Dec 23, 2020"
33
+ * simpleFormat(date2026, { time: '12h' }); // "Dec 23, 3:30 PM"
34
+ * simpleFormat(date2026, { time: '24h' }); // "Dec 23, 15:30"
35
+ *
36
+ * // Control year display
37
+ * simpleFormat(date2026, { year: 'always' }); // "Dec 23, 2026"
38
+ * simpleFormat(date2020, { year: 'never' }); // "Dec 23"
39
+ * simpleFormat(date2020, { year: 'auto' }); // "Dec 23, 2020" (default behavior)
40
+ *
41
+ * // With Instant (timeZone required)
42
+ * const instant = Temporal.Instant.from("2026-12-23T20:30:00Z");
43
+ * simpleFormat(instant, { timeZone: 'America/New_York' }); // "Dec 23"
44
+ * simpleFormat(instant, { timeZone: 'America/New_York', time: '12h' }); // "Dec 23, 3:30 PM"
45
+ *
46
+ * // With PlainDate (no time option)
47
+ * const plain = Temporal.PlainDate.from("2020-12-23");
48
+ * simpleFormat(plain); // "Dec 23, 2020"
49
+ * ```
50
+ */
51
+ export declare function simpleFormat(input: Temporal.PlainDate, options?: PlainDateOptions): string;
52
+ export declare function simpleFormat(input: Temporal.ZonedDateTime, options?: ZonedDateTimeOptions): string;
53
+ export declare function simpleFormat(input: Temporal.Instant, options: InstantOptions): string;
54
+ export {};
55
+ //# sourceMappingURL=simpleFormat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simpleFormat.d.ts","sourceRoot":"","sources":["../src/simpleFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CACpC;AAED,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CACpC;AAED,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAAC;AAC5F,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAC;AACpG,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM,CAAC"}
@@ -0,0 +1,7 @@
1
+ import {
2
+ simpleFormat
3
+ } from "./chunk-GQBO2UXH.js";
4
+ export {
5
+ simpleFormat
6
+ };
7
+ //# sourceMappingURL=simpleFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=simpleFormat.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simpleFormat.test.d.ts","sourceRoot":"","sources":["../src/simpleFormat.test.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobrand/tiempo",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
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": {
@@ -28,7 +28,7 @@
28
28
  "bugs": {
29
29
  "url": "https://github.com/go-brand/tiempo/issues"
30
30
  },
31
- "homepage": "https://github.com/go-brand/tiempo#readme",
31
+ "homepage": "https://eng.gobrand.app/tiempo",
32
32
  "scripts": {
33
33
  "build": "tsup && tsc --emitDeclarationOnly",
34
34
  "clean": "git clean -xdf .cache .turbo dist node_modules tsconfig.tsbuildinfo",