@gobrand/tiempo 2.6.3 → 2.8.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.
@@ -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 (typeof input === "number") {
8
+ return Temporal.Instant.fromEpochMilliseconds(input).toZonedDateTimeISO(timezone);
9
+ }
7
10
  if (input instanceof Date) {
8
11
  return Temporal.Instant.from(input.toISOString()).toZonedDateTimeISO(timezone);
9
12
  }
@@ -16,4 +19,4 @@ function toZonedTime(input, timezone) {
16
19
  export {
17
20
  toZonedTime
18
21
  };
19
- //# sourceMappingURL=chunk-MXQFENCR.js.map
22
+ //# sourceMappingURL=chunk-4PSMM55Q.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/toZonedTime.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\n\n/**\n * Convert a UTC ISO string, Unix timestamp, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.\n *\n * @param input - A UTC ISO 8601 string, Unix timestamp (milliseconds), Date object, Temporal.Instant, or Temporal.ZonedDateTime\n * @param timezone - IANA timezone identifier (e.g., \"America/New_York\", \"Europe/London\") or \"UTC\"\n * @returns A Temporal.ZonedDateTime in the specified timezone\n *\n * @example\n * ```typescript\n * import { toZonedTime, browserTimezone } from '@gobrand/tiempo';\n *\n * // Server-side: Convert to UTC\n * const utcTime = toZonedTime(\"2025-01-20T20:00:00Z\", \"UTC\");\n *\n * // Server-side: Convert to user's timezone (from DB/preferences)\n * const userTime = toZonedTime(\"2025-01-20T20:00:00Z\", user.timezone);\n *\n * // Client-side: Convert to browser's timezone\n * const localTime = toZonedTime(\"2025-01-20T20:00:00Z\", browserTimezone());\n *\n * // From Unix timestamp (e.g., from database BIGINT or API response)\n * const timestamp = 1737403200000;\n * const zoned = toZonedTime(timestamp, \"America/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 | number | Date | Temporal.Instant | Temporal.ZonedDateTime,\n timezone: Timezone\n): Temporal.ZonedDateTime {\n if (typeof input === 'string') {\n return Temporal.Instant.from(input).toZonedDateTimeISO(timezone);\n }\n\n if (typeof input === 'number') {\n return Temporal.Instant.fromEpochMilliseconds(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;AAwClB,SAAS,YACd,OACA,UACwB;AACxB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK,EAAE,mBAAmB,QAAQ;AAAA,EACjE;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,sBAAsB,KAAK,EAAE,mBAAmB,QAAQ;AAAA,EAClF;AAEA,MAAI,iBAAiB,MAAM;AACzB,WAAO,SAAS,QAAQ,KAAK,MAAM,YAAY,CAAC,EAAE,mBAAmB,QAAQ;AAAA,EAC/E;AAEA,MAAI,iBAAiB,SAAS,SAAS;AACrC,WAAO,MAAM,mBAAmB,QAAQ;AAAA,EAC1C;AAEA,SAAO,MAAM,UAAU,EAAE,mBAAmB,QAAQ;AACtD;","names":[]}
@@ -4,6 +4,9 @@ function toUtc(input) {
4
4
  if (typeof input === "string") {
5
5
  return Temporal.Instant.from(input);
6
6
  }
7
+ if (typeof input === "number") {
8
+ return Temporal.Instant.fromEpochMilliseconds(input);
9
+ }
7
10
  if (input instanceof Date) {
8
11
  return Temporal.Instant.from(input.toISOString());
9
12
  }
@@ -13,4 +16,4 @@ function toUtc(input) {
13
16
  export {
14
17
  toUtc
15
18
  };
16
- //# sourceMappingURL=chunk-BW5SFCKS.js.map
19
+ //# sourceMappingURL=chunk-AE36GX4F.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, Unix timestamp, Date, or ZonedDateTime to a Temporal.Instant (UTC).\n *\n * @param input - A UTC ISO 8601 string, Unix timestamp (milliseconds), 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 Unix timestamp (milliseconds since epoch)\n * const instant2 = toUtc(1737403200000);\n *\n * // From Date (e.g., from Drizzle ORM)\n * const date = new Date(\"2025-01-20T20:00:00.000Z\");\n * const instant3 = toUtc(date);\n *\n * // From ZonedDateTime\n * const zoned = Temporal.ZonedDateTime.from(\"2025-01-20T15:00:00-05:00[America/New_York]\");\n * const instant4 = toUtc(zoned);\n * // All represent the same UTC moment: 2025-01-20T20:00:00Z\n * ```\n */\nexport function toUtc(\n input: string | number | Date | Temporal.ZonedDateTime\n): Temporal.Instant {\n if (typeof input === 'string') {\n return Temporal.Instant.from(input);\n }\n\n if (typeof input === 'number') {\n return Temporal.Instant.fromEpochMilliseconds(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;AA0BlB,SAAS,MACd,OACkB;AAClB,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,KAAK,KAAK;AAAA,EACpC;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,SAAS,QAAQ,sBAAsB,KAAK;AAAA,EACrD;AAEA,MAAI,iBAAiB,MAAM;AACzB,WAAO,SAAS,QAAQ,KAAK,MAAM,YAAY,CAAC;AAAA,EAClD;AAEA,SAAO,MAAM,UAAU;AACzB;","names":[]}
@@ -0,0 +1,57 @@
1
+ // src/simpleFormat.ts
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ function simpleFormat(input, options) {
4
+ const { locale = "en-US", timeZone } = options;
5
+ const dateFormat = "date" in options ? options.date : void 0;
6
+ const timeFormat = "time" in options ? options.time : void 0;
7
+ let zdt;
8
+ if (input instanceof Temporal.Instant) {
9
+ const tz = timeZone ?? "UTC";
10
+ zdt = input.toZonedDateTimeISO(tz);
11
+ } else if (input instanceof Temporal.ZonedDateTime) {
12
+ if (timeZone) {
13
+ zdt = input.toInstant().toZonedDateTimeISO(timeZone);
14
+ } else {
15
+ zdt = input;
16
+ }
17
+ } else {
18
+ zdt = input.toZonedDateTime({ timeZone: timeZone ?? "UTC", plainTime: new Temporal.PlainTime() });
19
+ }
20
+ const parts = [];
21
+ if (dateFormat) {
22
+ const currentYear = Temporal.Now.plainDateISO().year;
23
+ const showYear = dateFormat === "full" ? true : dateFormat === "compact" ? false : zdt.year !== currentYear;
24
+ const dateOptions = {
25
+ day: "numeric",
26
+ month: "short",
27
+ year: showYear ? "numeric" : void 0
28
+ };
29
+ parts.push(zdt.toLocaleString(locale, dateOptions));
30
+ }
31
+ if (timeFormat) {
32
+ if (timeFormat === "compact") {
33
+ parts.push(formatCompactTime(zdt));
34
+ } else {
35
+ const timeOptions = {
36
+ hour: "numeric",
37
+ minute: "2-digit",
38
+ hour12: timeFormat === "12h"
39
+ };
40
+ parts.push(zdt.toLocaleString(locale, timeOptions));
41
+ }
42
+ }
43
+ return parts.join(", ");
44
+ }
45
+ function formatCompactTime(zdt) {
46
+ const hour12 = zdt.hour % 12 || 12;
47
+ const ampm = zdt.hour < 12 ? "am" : "pm";
48
+ if (zdt.minute === 0) {
49
+ return `${hour12}${ampm}`;
50
+ }
51
+ return `${hour12}:${zdt.minute.toString().padStart(2, "0")}${ampm}`;
52
+ }
53
+
54
+ export {
55
+ simpleFormat
56
+ };
57
+ //# sourceMappingURL=chunk-YQBM63DC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/simpleFormat.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\n\ninterface BaseOptions {\n locale?: string;\n timeZone?: Timezone;\n}\n\ninterface DateOnlyOptions extends BaseOptions {\n date: 'compact' | 'auto' | 'full';\n time?: never;\n}\n\ninterface TimeOnlyOptions extends BaseOptions {\n date?: never;\n time: '12h' | '24h' | 'compact';\n}\n\ninterface DateAndTimeOptions extends BaseOptions {\n date: 'compact' | 'auto' | 'full';\n time: '12h' | '24h' | 'compact';\n}\n\nexport type SimpleFormatOptions = DateOnlyOptions | TimeOnlyOptions | DateAndTimeOptions;\n\n/**\n * Format a Temporal date/time in a human-friendly way.\n *\n * Pass `date`, `time`, or both to control what's displayed.\n * At least one of `date` or `time` is required.\n *\n * @param input - A Temporal.Instant, ZonedDateTime, or PlainDate\n * @param options - Format options (at least `date` or `time` required)\n *\n * Date formats:\n * - `'compact'` - \"Dec 23\" (never shows year)\n * - `'auto'` - \"Dec 23\" or \"Dec 23, 2020\" (shows year only if not current year)\n * - `'full'` - \"Dec 23, 2026\" (always shows year)\n *\n * Time formats:\n * - `'12h'` - \"3:30 PM\"\n * - `'24h'` - \"15:30\"\n * - `'compact'` - \"9am\" or \"2:30pm\" (omits minutes when zero, lowercase am/pm)\n *\n * @example\n * ```typescript\n * const zdt = Temporal.ZonedDateTime.from(\"2026-12-23T09:00:00[America/New_York]\");\n * const pastZdt = Temporal.ZonedDateTime.from(\"2020-12-23T14:30:00[America/New_York]\");\n *\n * // Date only\n * simpleFormat(zdt, { date: 'compact' }); // \"Dec 23\"\n * simpleFormat(zdt, { date: 'auto' }); // \"Dec 23\"\n * simpleFormat(pastZdt, { date: 'auto' }); // \"Dec 23, 2020\"\n * simpleFormat(zdt, { date: 'full' }); // \"Dec 23, 2026\"\n *\n * // Time only\n * simpleFormat(zdt, { time: 'compact' }); // \"9am\"\n * simpleFormat(pastZdt, { time: 'compact' }); // \"2:30pm\"\n * simpleFormat(zdt, { time: '12h' }); // \"9:00 AM\"\n * simpleFormat(zdt, { time: '24h' }); // \"09:00\"\n *\n * // Date and time\n * simpleFormat(zdt, { date: 'auto', time: 'compact' }); // \"Dec 23, 9am\"\n * simpleFormat(zdt, { date: 'full', time: '12h' }); // \"Dec 23, 2026, 9:00 AM\"\n *\n * // With Instant (timeZone required)\n * const instant = Temporal.Instant.from(\"2026-12-23T14:00:00Z\");\n * simpleFormat(instant, { date: 'auto', timeZone: 'America/New_York' }); // \"Dec 23\"\n * ```\n */\nexport function simpleFormat(\n input: Temporal.PlainDate | Temporal.ZonedDateTime | Temporal.Instant,\n options: SimpleFormatOptions\n): string {\n const { locale = 'en-US', timeZone } = options;\n const dateFormat = 'date' in options ? options.date : undefined;\n const timeFormat = 'time' in options ? options.time : undefined;\n\n // Convert input to ZonedDateTime for consistent handling\n let zdt: Temporal.ZonedDateTime;\n\n if (input instanceof Temporal.Instant) {\n const tz = timeZone ?? 'UTC';\n zdt = input.toZonedDateTimeISO(tz);\n } else if (input instanceof Temporal.ZonedDateTime) {\n if (timeZone) {\n zdt = input.toInstant().toZonedDateTimeISO(timeZone);\n } else {\n zdt = input;\n }\n } else {\n // PlainDate - convert to ZonedDateTime at midnight UTC for formatting\n zdt = input.toZonedDateTime({ timeZone: timeZone ?? 'UTC', plainTime: new Temporal.PlainTime() });\n }\n\n const parts: string[] = [];\n\n // Format date part\n if (dateFormat) {\n const currentYear = Temporal.Now.plainDateISO().year;\n const showYear =\n dateFormat === 'full' ? true : dateFormat === 'compact' ? false : zdt.year !== currentYear;\n\n const dateOptions: Intl.DateTimeFormatOptions = {\n day: 'numeric',\n month: 'short',\n year: showYear ? 'numeric' : undefined,\n };\n\n parts.push(zdt.toLocaleString(locale, dateOptions));\n }\n\n // Format time part\n if (timeFormat) {\n if (timeFormat === 'compact') {\n parts.push(formatCompactTime(zdt));\n } else {\n const timeOptions: Intl.DateTimeFormatOptions = {\n hour: 'numeric',\n minute: '2-digit',\n hour12: timeFormat === '12h',\n };\n parts.push(zdt.toLocaleString(locale, timeOptions));\n }\n }\n\n return parts.join(', ');\n}\n\n/**\n * Format time in compact style: \"9am\" or \"2:30pm\"\n * Omits minutes when they're zero for cleaner display.\n */\nfunction formatCompactTime(zdt: Temporal.ZonedDateTime): string {\n const hour12 = zdt.hour % 12 || 12;\n const ampm = zdt.hour < 12 ? 'am' : 'pm';\n\n if (zdt.minute === 0) {\n return `${hour12}${ampm}`;\n }\n return `${hour12}:${zdt.minute.toString().padStart(2, '0')}${ampm}`;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAsElB,SAAS,aACd,OACA,SACQ;AACR,QAAM,EAAE,SAAS,SAAS,SAAS,IAAI;AACvC,QAAM,aAAa,UAAU,UAAU,QAAQ,OAAO;AACtD,QAAM,aAAa,UAAU,UAAU,QAAQ,OAAO;AAGtD,MAAI;AAEJ,MAAI,iBAAiB,SAAS,SAAS;AACrC,UAAM,KAAK,YAAY;AACvB,UAAM,MAAM,mBAAmB,EAAE;AAAA,EACnC,WAAW,iBAAiB,SAAS,eAAe;AAClD,QAAI,UAAU;AACZ,YAAM,MAAM,UAAU,EAAE,mBAAmB,QAAQ;AAAA,IACrD,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF,OAAO;AAEL,UAAM,MAAM,gBAAgB,EAAE,UAAU,YAAY,OAAO,WAAW,IAAI,SAAS,UAAU,EAAE,CAAC;AAAA,EAClG;AAEA,QAAM,QAAkB,CAAC;AAGzB,MAAI,YAAY;AACd,UAAM,cAAc,SAAS,IAAI,aAAa,EAAE;AAChD,UAAM,WACJ,eAAe,SAAS,OAAO,eAAe,YAAY,QAAQ,IAAI,SAAS;AAEjF,UAAM,cAA0C;AAAA,MAC9C,KAAK;AAAA,MACL,OAAO;AAAA,MACP,MAAM,WAAW,YAAY;AAAA,IAC/B;AAEA,UAAM,KAAK,IAAI,eAAe,QAAQ,WAAW,CAAC;AAAA,EACpD;AAGA,MAAI,YAAY;AACd,QAAI,eAAe,WAAW;AAC5B,YAAM,KAAK,kBAAkB,GAAG,CAAC;AAAA,IACnC,OAAO;AACL,YAAM,cAA0C;AAAA,QAC9C,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ,eAAe;AAAA,MACzB;AACA,YAAM,KAAK,IAAI,eAAe,QAAQ,WAAW,CAAC;AAAA,IACpD;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAMA,SAAS,kBAAkB,KAAqC;AAC9D,QAAM,SAAS,IAAI,OAAO,MAAM;AAChC,QAAM,OAAO,IAAI,OAAO,KAAK,OAAO;AAEpC,MAAI,IAAI,WAAW,GAAG;AACpB,WAAO,GAAG,MAAM,GAAG,IAAI;AAAA,EACzB;AACA,SAAO,GAAG,MAAM,IAAI,IAAI,OAAO,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,GAAG,IAAI;AACnE;","names":[]}
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export { toIso9075, type ToIso9075Options, type Iso9075Representation, type Iso9
9
9
  export { toDate } from './toDate';
10
10
  export { format, type FormatOptions } from './format';
11
11
  export { formatPlainDate, type FormatPlainDateOptions } from './formatPlainDate';
12
- export { simpleFormat } from './simpleFormat';
12
+ export { simpleFormat, type SimpleFormatOptions } from './simpleFormat';
13
13
  export { today } from './today';
14
14
  export { now } from './now';
15
15
  export { startOfDay } from './startOfDay';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index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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;AACtD,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
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-UJWM2BV2.js";
4
4
  import {
5
5
  toUtc
6
- } from "./chunk-BW5SFCKS.js";
6
+ } from "./chunk-AE36GX4F.js";
7
7
  import {
8
8
  toZonedTime
9
- } from "./chunk-MXQFENCR.js";
9
+ } from "./chunk-4PSMM55Q.js";
10
10
  import {
11
11
  today
12
12
  } from "./chunk-KZB6NERH.js";
@@ -69,7 +69,7 @@ import {
69
69
  } from "./chunk-JHRXY36W.js";
70
70
  import {
71
71
  simpleFormat
72
- } from "./chunk-TFSZ55L7.js";
72
+ } from "./chunk-YQBM63DC.js";
73
73
  import {
74
74
  startOfDay
75
75
  } from "./chunk-YIT6EMBC.js";
@@ -1,56 +1,67 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
2
  import type { Timezone } from './types';
3
- interface PlainDateOptions {
3
+ interface BaseOptions {
4
4
  locale?: string;
5
- year?: 'auto' | 'always' | 'never';
6
- }
7
- interface ZonedDateTimeOptions {
8
- locale?: string;
9
- time?: '12h' | '24h';
10
5
  timeZone?: Timezone;
11
- year?: 'auto' | 'always' | 'never';
12
6
  }
13
- interface InstantOptions {
14
- locale?: string;
15
- time?: '12h' | '24h';
16
- timeZone: Timezone;
17
- year?: 'auto' | 'always' | 'never';
7
+ interface DateOnlyOptions extends BaseOptions {
8
+ date: 'compact' | 'auto' | 'full';
9
+ time?: never;
10
+ }
11
+ interface TimeOnlyOptions extends BaseOptions {
12
+ date?: never;
13
+ time: '12h' | '24h' | 'compact';
14
+ }
15
+ interface DateAndTimeOptions extends BaseOptions {
16
+ date: 'compact' | 'auto' | 'full';
17
+ time: '12h' | '24h' | 'compact';
18
18
  }
19
+ export type SimpleFormatOptions = DateOnlyOptions | TimeOnlyOptions | DateAndTimeOptions;
19
20
  /**
20
- * Format a Temporal date in a human-friendly way: "Dec 23" or "Dec 23, 2020"
21
+ * Format a Temporal date/time in a human-friendly way.
21
22
  *
22
- * By default (year: 'auto'), shows the year only if the date is not in the current year.
23
- * Use year: 'always' to always show the year, or year: 'never' to always hide it.
24
- * Optionally includes time in 12-hour or 24-hour format.
23
+ * Pass `date`, `time`, or both to control what's displayed.
24
+ * At least one of `date` or `time` is required.
25
+ *
26
+ * @param input - A Temporal.Instant, ZonedDateTime, or PlainDate
27
+ * @param options - Format options (at least `date` or `time` required)
28
+ *
29
+ * Date formats:
30
+ * - `'compact'` - "Dec 23" (never shows year)
31
+ * - `'auto'` - "Dec 23" or "Dec 23, 2020" (shows year only if not current year)
32
+ * - `'full'` - "Dec 23, 2026" (always shows year)
33
+ *
34
+ * Time formats:
35
+ * - `'12h'` - "3:30 PM"
36
+ * - `'24h'` - "15:30"
37
+ * - `'compact'` - "9am" or "2:30pm" (omits minutes when zero, lowercase am/pm)
25
38
  *
26
39
  * @example
27
40
  * ```typescript
28
- * // Assuming current year is 2026
29
- * const date2026 = Temporal.ZonedDateTime.from("2026-12-23T15:30:00[America/New_York]");
30
- * const date2020 = Temporal.ZonedDateTime.from("2020-12-23T15:30:00[America/New_York]");
41
+ * const zdt = Temporal.ZonedDateTime.from("2026-12-23T09:00:00[America/New_York]");
42
+ * const pastZdt = Temporal.ZonedDateTime.from("2020-12-23T14:30:00[America/New_York]");
31
43
  *
32
- * simpleFormat(date2026); // "Dec 23"
33
- * simpleFormat(date2020); // "Dec 23, 2020"
34
- * simpleFormat(date2026, { time: '12h' }); // "Dec 23, 3:30 PM"
35
- * simpleFormat(date2026, { time: '24h' }); // "Dec 23, 15:30"
44
+ * // Date only
45
+ * simpleFormat(zdt, { date: 'compact' }); // "Dec 23"
46
+ * simpleFormat(zdt, { date: 'auto' }); // "Dec 23"
47
+ * simpleFormat(pastZdt, { date: 'auto' }); // "Dec 23, 2020"
48
+ * simpleFormat(zdt, { date: 'full' }); // "Dec 23, 2026"
36
49
  *
37
- * // Control year display
38
- * simpleFormat(date2026, { year: 'always' }); // "Dec 23, 2026"
39
- * simpleFormat(date2020, { year: 'never' }); // "Dec 23"
40
- * simpleFormat(date2020, { year: 'auto' }); // "Dec 23, 2020" (default behavior)
50
+ * // Time only
51
+ * simpleFormat(zdt, { time: 'compact' }); // "9am"
52
+ * simpleFormat(pastZdt, { time: 'compact' }); // "2:30pm"
53
+ * simpleFormat(zdt, { time: '12h' }); // "9:00 AM"
54
+ * simpleFormat(zdt, { time: '24h' }); // "09:00"
41
55
  *
42
- * // With Instant (timeZone required)
43
- * const instant = Temporal.Instant.from("2026-12-23T20:30:00Z");
44
- * simpleFormat(instant, { timeZone: 'America/New_York' }); // "Dec 23"
45
- * simpleFormat(instant, { timeZone: 'America/New_York', time: '12h' }); // "Dec 23, 3:30 PM"
56
+ * // Date and time
57
+ * simpleFormat(zdt, { date: 'auto', time: 'compact' }); // "Dec 23, 9am"
58
+ * simpleFormat(zdt, { date: 'full', time: '12h' }); // "Dec 23, 2026, 9:00 AM"
46
59
  *
47
- * // With PlainDate (no time option)
48
- * const plain = Temporal.PlainDate.from("2020-12-23");
49
- * simpleFormat(plain); // "Dec 23, 2020"
60
+ * // With Instant (timeZone required)
61
+ * const instant = Temporal.Instant.from("2026-12-23T14:00:00Z");
62
+ * simpleFormat(instant, { date: 'auto', timeZone: 'America/New_York' }); // "Dec 23"
50
63
  * ```
51
64
  */
52
- export declare function simpleFormat(input: Temporal.PlainDate, options?: PlainDateOptions): string;
53
- export declare function simpleFormat(input: Temporal.ZonedDateTime, options?: ZonedDateTimeOptions): string;
54
- export declare function simpleFormat(input: Temporal.Instant, options: InstantOptions): string;
65
+ export declare function simpleFormat(input: Temporal.PlainDate | Temporal.ZonedDateTime | Temporal.Instant, options: SimpleFormatOptions): string;
55
66
  export {};
56
67
  //# sourceMappingURL=simpleFormat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"simpleFormat.d.ts","sourceRoot":"","sources":["../src/simpleFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxC,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,QAAQ,CAAC;IACpB,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,QAAQ,CAAC;IACnB,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"}
1
+ {"version":3,"file":"simpleFormat.d.ts","sourceRoot":"","sources":["../src/simpleFormat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,UAAU,WAAW;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,UAAU,eAAgB,SAAQ,WAAW;IAC3C,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,IAAI,CAAC,EAAE,KAAK,CAAC;CACd;AAED,UAAU,eAAgB,SAAQ,WAAW;IAC3C,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;CACjC;AAED,UAAU,kBAAmB,SAAQ,WAAW;IAC9C,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;CACjC;AAED,MAAM,MAAM,mBAAmB,GAAG,eAAe,GAAG,eAAe,GAAG,kBAAkB,CAAC;AAEzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,OAAO,EACrE,OAAO,EAAE,mBAAmB,GAC3B,MAAM,CAsDR"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  simpleFormat
3
- } from "./chunk-TFSZ55L7.js";
3
+ } from "./chunk-YQBM63DC.js";
4
4
  export {
5
5
  simpleFormat
6
6
  };
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, Date, or ZonedDateTime to a Temporal.Instant (UTC).
3
+ * Convert a UTC ISO string, Unix timestamp, Date, or ZonedDateTime to a Temporal.Instant (UTC).
4
4
  *
5
- * @param input - A UTC ISO 8601 string, Date object, or Temporal.ZonedDateTime
5
+ * @param input - A UTC ISO 8601 string, Unix timestamp (milliseconds), Date object, or Temporal.ZonedDateTime
6
6
  * @returns A Temporal.Instant representing the same moment in UTC
7
7
  *
8
8
  * @example
@@ -10,15 +10,18 @@ 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 Unix timestamp (milliseconds since epoch)
14
+ * const instant2 = toUtc(1737403200000);
15
+ *
13
16
  * // From Date (e.g., from Drizzle ORM)
14
17
  * const date = new Date("2025-01-20T20:00:00.000Z");
15
- * const instant2 = toUtc(date);
18
+ * const instant3 = toUtc(date);
16
19
  *
17
20
  * // From ZonedDateTime
18
21
  * const zoned = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
19
- * const instant3 = toUtc(zoned);
22
+ * const instant4 = toUtc(zoned);
20
23
  * // All represent the same UTC moment: 2025-01-20T20:00:00Z
21
24
  * ```
22
25
  */
23
- export declare function toUtc(input: string | Date | Temporal.ZonedDateTime): Temporal.Instant;
26
+ export declare function toUtc(input: string | number | Date | Temporal.ZonedDateTime): Temporal.Instant;
24
27
  //# sourceMappingURL=toUtc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toUtc.d.ts","sourceRoot":"","sources":["../src/toUtc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,aAAa,GAC5C,QAAQ,CAAC,OAAO,CAUlB"}
1
+ {"version":3,"file":"toUtc.d.ts","sourceRoot":"","sources":["../src/toUtc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,aAAa,GACrD,QAAQ,CAAC,OAAO,CAclB"}
package/dist/toUtc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toUtc
3
- } from "./chunk-BW5SFCKS.js";
3
+ } from "./chunk-AE36GX4F.js";
4
4
  export {
5
5
  toUtc
6
6
  };
@@ -1,9 +1,9 @@
1
1
  import { Temporal } from '@js-temporal/polyfill';
2
2
  import type { Timezone } from './types';
3
3
  /**
4
- * Convert a UTC ISO string, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
4
+ * Convert a UTC ISO string, Unix timestamp, Date, Instant, or ZonedDateTime to a ZonedDateTime in the specified timezone.
5
5
  *
6
- * @param input - A UTC ISO 8601 string, Date object, Temporal.Instant, or Temporal.ZonedDateTime
6
+ * @param input - A UTC ISO 8601 string, Unix timestamp (milliseconds), Date object, Temporal.Instant, or Temporal.ZonedDateTime
7
7
  * @param timezone - IANA timezone identifier (e.g., "America/New_York", "Europe/London") or "UTC"
8
8
  * @returns A Temporal.ZonedDateTime in the specified timezone
9
9
  *
@@ -20,18 +20,22 @@ import type { Timezone } from './types';
20
20
  * // Client-side: Convert to browser's timezone
21
21
  * const localTime = toZonedTime("2025-01-20T20:00:00Z", browserTimezone());
22
22
  *
23
+ * // From Unix timestamp (e.g., from database BIGINT or API response)
24
+ * const timestamp = 1737403200000;
25
+ * const zoned = toZonedTime(timestamp, "America/New_York");
26
+ *
23
27
  * // From Date (e.g., from Drizzle ORM)
24
28
  * const date = new Date("2025-01-20T20:00:00.000Z");
25
- * const zoned = toZonedTime(date, "America/New_York");
29
+ * const zoned2 = toZonedTime(date, "America/New_York");
26
30
  *
27
31
  * // From Instant
28
32
  * const instant = Temporal.Instant.from("2025-01-20T20:00:00Z");
29
- * const zoned = toZonedTime(instant, "Asia/Tokyo");
33
+ * const zoned3 = toZonedTime(instant, "Asia/Tokyo");
30
34
  *
31
35
  * // From ZonedDateTime (convert to different timezone)
32
36
  * const nyTime = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
33
37
  * const tokyoTime = toZonedTime(nyTime, "Asia/Tokyo");
34
38
  * ```
35
39
  */
36
- export declare function toZonedTime(input: string | Date | Temporal.Instant | Temporal.ZonedDateTime, timezone: Timezone): Temporal.ZonedDateTime;
40
+ export declare function toZonedTime(input: string | number | Date | Temporal.Instant | Temporal.ZonedDateTime, timezone: Timezone): Temporal.ZonedDateTime;
37
41
  //# 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;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChE,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,aAAa,CAcxB"}
1
+ {"version":3,"file":"toZonedTime.d.ts","sourceRoot":"","sources":["../src/toZonedTime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EACzE,QAAQ,EAAE,QAAQ,GACjB,QAAQ,CAAC,aAAa,CAkBxB"}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  toZonedTime
3
- } from "./chunk-MXQFENCR.js";
3
+ } from "./chunk-4PSMM55Q.js";
4
4
  export {
5
5
  toZonedTime
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobrand/tiempo",
3
- "version": "2.6.3",
3
+ "version": "2.8.0",
4
4
  "description": "Lightweight utility functions for converting between UTC and timezone-aware datetimes using the Temporal API",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/toUtc.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\n/**\n * Convert a UTC ISO string, 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":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/toZonedTime.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\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\") or \"UTC\"\n * @returns A Temporal.ZonedDateTime in the specified timezone\n *\n * @example\n * ```typescript\n * import { toZonedTime, browserTimezone } from '@gobrand/tiempo';\n *\n * // Server-side: Convert to UTC\n * const utcTime = toZonedTime(\"2025-01-20T20:00:00Z\", \"UTC\");\n *\n * // Server-side: Convert to user's timezone (from DB/preferences)\n * const userTime = toZonedTime(\"2025-01-20T20:00:00Z\", user.timezone);\n *\n * // Client-side: Convert to browser's timezone\n * const localTime = toZonedTime(\"2025-01-20T20:00:00Z\", browserTimezone());\n *\n * // From Date (e.g., from Drizzle ORM)\n * const date = new Date(\"2025-01-20T20:00:00.000Z\");\n * const zoned = toZonedTime(date, \"America/New_York\");\n *\n * // From Instant\n * const instant = Temporal.Instant.from(\"2025-01-20T20:00:00Z\");\n * const zoned = 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: Timezone\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;AAoClB,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":[]}
@@ -1,46 +0,0 @@
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-TFSZ55L7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/simpleFormat.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\nimport type { Timezone } from './types';\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?: Timezone;\n year?: 'auto' | 'always' | 'never';\n}\n\ninterface InstantOptions {\n locale?: string;\n time?: '12h' | '24h';\n timeZone: Timezone; // 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;AA2DlB,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":[]}