@gobrand/tiempo 2.7.0 → 2.8.1

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":[]}
@@ -54,31 +54,31 @@ function intlFormatDistance(laterDate, earlierDate, options) {
54
54
  let value;
55
55
  switch (unit) {
56
56
  case "second":
57
- value = differenceInSeconds(zoned1, zoned2);
57
+ value = Math.round(differenceInSeconds(zoned1, zoned2));
58
58
  break;
59
59
  case "minute":
60
- value = differenceInMinutes(zoned1, zoned2);
60
+ value = Math.round(differenceInMinutes(zoned1, zoned2));
61
61
  break;
62
62
  case "hour":
63
- value = differenceInHours(zoned1, zoned2);
63
+ value = Math.round(differenceInHours(zoned1, zoned2));
64
64
  break;
65
65
  case "day":
66
- value = differenceInDays(zoned1, zoned2);
66
+ value = Math.round(differenceInDays(zoned1, zoned2));
67
67
  break;
68
68
  case "week":
69
- value = differenceInWeeks(zoned1, zoned2);
69
+ value = Math.round(differenceInWeeks(zoned1, zoned2));
70
70
  break;
71
71
  case "month":
72
- value = differenceInMonths(zoned1, zoned2);
72
+ value = Math.round(differenceInMonths(zoned1, zoned2));
73
73
  break;
74
74
  case "quarter":
75
75
  value = Math.round(differenceInMonths(zoned1, zoned2) / 3);
76
76
  break;
77
77
  case "year":
78
- value = differenceInYears(zoned1, zoned2);
78
+ value = Math.round(differenceInYears(zoned1, zoned2));
79
79
  break;
80
80
  default:
81
- value = differenceInSeconds(zoned1, zoned2);
81
+ value = Math.round(differenceInSeconds(zoned1, zoned2));
82
82
  }
83
83
  const formatter = new Intl.RelativeTimeFormat(options?.locale, {
84
84
  localeMatcher: options?.localeMatcher,
@@ -91,4 +91,4 @@ function intlFormatDistance(laterDate, earlierDate, options) {
91
91
  export {
92
92
  intlFormatDistance
93
93
  };
94
- //# sourceMappingURL=chunk-ZJQS7ZY7.js.map
94
+ //# sourceMappingURL=chunk-5BYRBC7H.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/intlFormatDistance.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { differenceInDays } from './differenceInDays.js';\nimport { differenceInHours } from './differenceInHours.js';\nimport { differenceInMinutes } from './differenceInMinutes.js';\nimport { differenceInMonths } from './differenceInMonths.js';\nimport { differenceInSeconds } from './differenceInSeconds.js';\nimport { differenceInWeeks } from './differenceInWeeks.js';\nimport { differenceInYears } from './differenceInYears.js';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput.js';\n\nexport interface IntlFormatDistanceOptions {\n /**\n * The unit to force formatting in. If not specified, the unit will be automatically selected.\n */\n unit?: Intl.RelativeTimeFormatUnit;\n /**\n * The locale to use for formatting. Defaults to the system locale.\n */\n locale?: string | string[];\n /**\n * The locale matching algorithm to use.\n */\n localeMatcher?: 'best fit' | 'lookup';\n /**\n * Whether to use numeric values always, or use special strings like \"yesterday\", \"tomorrow\", etc.\n * Defaults to 'auto'.\n */\n numeric?: 'always' | 'auto';\n /**\n * The formatting style to use.\n */\n style?: 'long' | 'short' | 'narrow';\n}\n\n/**\n * Formats the distance between two dates as a human-readable, internationalized string.\n *\n * The function automatically picks the most appropriate unit based on the distance between dates.\n * For example, if the distance is a few hours, it returns \"in X hours\". If the distance is a few\n * months, it returns \"in X months\".\n *\n * You can force a specific unit using the `options.unit` parameter.\n *\n * @param laterDate - The later date to compare\n * @param earlierDate - The earlier date to compare with\n * @param options - Formatting options\n * @returns The formatted distance string\n *\n * @example\n * ```typescript\n * const later = Temporal.Instant.from('2024-01-01T12:00:00Z');\n * const earlier = Temporal.Instant.from('2024-01-01T11:00:00Z');\n *\n * intlFormatDistance(later, earlier);\n * // => 'in 1 hour'\n *\n * intlFormatDistance(earlier, later);\n * // => '1 hour ago'\n * ```\n *\n * @example\n * ```typescript\n * // Force a specific unit\n * const later = Temporal.Instant.from('2025-01-01T00:00:00Z');\n * const earlier = Temporal.Instant.from('2024-01-01T00:00:00Z');\n *\n * intlFormatDistance(later, earlier, { unit: 'quarter' });\n * // => 'in 4 quarters'\n * ```\n *\n * @example\n * ```typescript\n * // Use a different locale\n * const later = Temporal.Instant.from('2024-01-01T12:00:00Z');\n * const earlier = Temporal.Instant.from('2024-01-01T11:00:00Z');\n *\n * intlFormatDistance(later, earlier, { locale: 'es' });\n * // => 'dentro de 1 hora'\n * ```\n *\n * @example\n * ```typescript\n * // Use numeric: 'always' to avoid special strings\n * const later = Temporal.Instant.from('2024-01-02T00:00:00Z');\n * const earlier = Temporal.Instant.from('2024-01-01T00:00:00Z');\n *\n * intlFormatDistance(later, earlier, { numeric: 'auto' });\n * // => 'tomorrow'\n *\n * intlFormatDistance(later, earlier, { numeric: 'always' });\n * // => 'in 1 day'\n * ```\n */\nexport function intlFormatDistance(\n laterDate: Temporal.Instant | Temporal.ZonedDateTime,\n earlierDate: Temporal.Instant | Temporal.ZonedDateTime,\n options?: IntlFormatDistanceOptions\n): string {\n const zoned1 = normalizeTemporalInput(laterDate);\n const zoned2 = normalizeTemporalInput(earlierDate);\n\n // Determine unit if not specified\n let unit = options?.unit;\n if (!unit) {\n const absSeconds = Math.abs(differenceInSeconds(zoned1, zoned2));\n const absMinutes = Math.abs(differenceInMinutes(zoned1, zoned2));\n const absHours = Math.abs(differenceInHours(zoned1, zoned2));\n const absDays = Math.abs(differenceInDays(zoned1, zoned2));\n const absWeeks = Math.abs(differenceInWeeks(zoned1, zoned2));\n const absMonths = Math.abs(differenceInMonths(zoned1, zoned2));\n\n if (absSeconds < 60) {\n unit = 'second';\n } else if (absMinutes < 60) {\n unit = 'minute';\n } else if (absHours < 24) {\n unit = 'hour';\n } else if (absDays < 7) {\n unit = 'day';\n } else if (absWeeks < 4) {\n unit = 'week';\n } else if (absMonths < 12) {\n unit = 'month';\n } else {\n unit = 'year';\n }\n }\n\n // Calculate value for the selected unit\n let value: number;\n switch (unit) {\n case 'second':\n value = differenceInSeconds(zoned1, zoned2);\n break;\n case 'minute':\n value = differenceInMinutes(zoned1, zoned2);\n break;\n case 'hour':\n value = differenceInHours(zoned1, zoned2);\n break;\n case 'day':\n value = differenceInDays(zoned1, zoned2);\n break;\n case 'week':\n value = differenceInWeeks(zoned1, zoned2);\n break;\n case 'month':\n value = differenceInMonths(zoned1, zoned2);\n break;\n case 'quarter':\n value = Math.round(differenceInMonths(zoned1, zoned2) / 3);\n break;\n case 'year':\n value = differenceInYears(zoned1, zoned2);\n break;\n default:\n // For any other unit type, try to use it directly\n value = differenceInSeconds(zoned1, zoned2);\n }\n\n // Format using Intl.RelativeTimeFormat\n const formatter = new Intl.RelativeTimeFormat(options?.locale, {\n localeMatcher: options?.localeMatcher,\n numeric: options?.numeric ?? 'auto',\n style: options?.style,\n });\n\n return formatter.format(value, unit);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6FO,SAAS,mBACd,WACA,aACA,SACQ;AACR,QAAM,SAAS,uBAAuB,SAAS;AAC/C,QAAM,SAAS,uBAAuB,WAAW;AAGjD,MAAI,OAAO,SAAS;AACpB,MAAI,CAAC,MAAM;AACT,UAAM,aAAa,KAAK,IAAI,oBAAoB,QAAQ,MAAM,CAAC;AAC/D,UAAM,aAAa,KAAK,IAAI,oBAAoB,QAAQ,MAAM,CAAC;AAC/D,UAAM,WAAW,KAAK,IAAI,kBAAkB,QAAQ,MAAM,CAAC;AAC3D,UAAM,UAAU,KAAK,IAAI,iBAAiB,QAAQ,MAAM,CAAC;AACzD,UAAM,WAAW,KAAK,IAAI,kBAAkB,QAAQ,MAAM,CAAC;AAC3D,UAAM,YAAY,KAAK,IAAI,mBAAmB,QAAQ,MAAM,CAAC;AAE7D,QAAI,aAAa,IAAI;AACnB,aAAO;AAAA,IACT,WAAW,aAAa,IAAI;AAC1B,aAAO;AAAA,IACT,WAAW,WAAW,IAAI;AACxB,aAAO;AAAA,IACT,WAAW,UAAU,GAAG;AACtB,aAAO;AAAA,IACT,WAAW,WAAW,GAAG;AACvB,aAAO;AAAA,IACT,WAAW,YAAY,IAAI;AACzB,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAGA,MAAI;AACJ,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,cAAQ,oBAAoB,QAAQ,MAAM;AAC1C;AAAA,IACF,KAAK;AACH,cAAQ,oBAAoB,QAAQ,MAAM;AAC1C;AAAA,IACF,KAAK;AACH,cAAQ,kBAAkB,QAAQ,MAAM;AACxC;AAAA,IACF,KAAK;AACH,cAAQ,iBAAiB,QAAQ,MAAM;AACvC;AAAA,IACF,KAAK;AACH,cAAQ,kBAAkB,QAAQ,MAAM;AACxC;AAAA,IACF,KAAK;AACH,cAAQ,mBAAmB,QAAQ,MAAM;AACzC;AAAA,IACF,KAAK;AACH,cAAQ,KAAK,MAAM,mBAAmB,QAAQ,MAAM,IAAI,CAAC;AACzD;AAAA,IACF,KAAK;AACH,cAAQ,kBAAkB,QAAQ,MAAM;AACxC;AAAA,IACF;AAEE,cAAQ,oBAAoB,QAAQ,MAAM;AAAA,EAC9C;AAGA,QAAM,YAAY,IAAI,KAAK,mBAAmB,SAAS,QAAQ;AAAA,IAC7D,eAAe,SAAS;AAAA,IACxB,SAAS,SAAS,WAAW;AAAA,IAC7B,OAAO,SAAS;AAAA,EAClB,CAAC;AAED,SAAO,UAAU,OAAO,OAAO,IAAI;AACrC;","names":[]}
1
+ {"version":3,"sources":["../src/intlFormatDistance.ts"],"sourcesContent":["import type { Temporal } from '@js-temporal/polyfill';\nimport { differenceInDays } from './differenceInDays.js';\nimport { differenceInHours } from './differenceInHours.js';\nimport { differenceInMinutes } from './differenceInMinutes.js';\nimport { differenceInMonths } from './differenceInMonths.js';\nimport { differenceInSeconds } from './differenceInSeconds.js';\nimport { differenceInWeeks } from './differenceInWeeks.js';\nimport { differenceInYears } from './differenceInYears.js';\nimport { normalizeTemporalInput } from './shared/normalizeTemporalInput.js';\n\nexport interface IntlFormatDistanceOptions {\n /**\n * The unit to force formatting in. If not specified, the unit will be automatically selected.\n */\n unit?: Intl.RelativeTimeFormatUnit;\n /**\n * The locale to use for formatting. Defaults to the system locale.\n */\n locale?: string | string[];\n /**\n * The locale matching algorithm to use.\n */\n localeMatcher?: 'best fit' | 'lookup';\n /**\n * Whether to use numeric values always, or use special strings like \"yesterday\", \"tomorrow\", etc.\n * Defaults to 'auto'.\n */\n numeric?: 'always' | 'auto';\n /**\n * The formatting style to use.\n */\n style?: 'long' | 'short' | 'narrow';\n}\n\n/**\n * Formats the distance between two dates as a human-readable, internationalized string.\n *\n * The function automatically picks the most appropriate unit based on the distance between dates.\n * For example, if the distance is a few hours, it returns \"in X hours\". If the distance is a few\n * months, it returns \"in X months\".\n *\n * You can force a specific unit using the `options.unit` parameter.\n *\n * @param laterDate - The later date to compare\n * @param earlierDate - The earlier date to compare with\n * @param options - Formatting options\n * @returns The formatted distance string\n *\n * @example\n * ```typescript\n * const later = Temporal.Instant.from('2024-01-01T12:00:00Z');\n * const earlier = Temporal.Instant.from('2024-01-01T11:00:00Z');\n *\n * intlFormatDistance(later, earlier);\n * // => 'in 1 hour'\n *\n * intlFormatDistance(earlier, later);\n * // => '1 hour ago'\n * ```\n *\n * @example\n * ```typescript\n * // Force a specific unit\n * const later = Temporal.Instant.from('2025-01-01T00:00:00Z');\n * const earlier = Temporal.Instant.from('2024-01-01T00:00:00Z');\n *\n * intlFormatDistance(later, earlier, { unit: 'quarter' });\n * // => 'in 4 quarters'\n * ```\n *\n * @example\n * ```typescript\n * // Use a different locale\n * const later = Temporal.Instant.from('2024-01-01T12:00:00Z');\n * const earlier = Temporal.Instant.from('2024-01-01T11:00:00Z');\n *\n * intlFormatDistance(later, earlier, { locale: 'es' });\n * // => 'dentro de 1 hora'\n * ```\n *\n * @example\n * ```typescript\n * // Use numeric: 'always' to avoid special strings\n * const later = Temporal.Instant.from('2024-01-02T00:00:00Z');\n * const earlier = Temporal.Instant.from('2024-01-01T00:00:00Z');\n *\n * intlFormatDistance(later, earlier, { numeric: 'auto' });\n * // => 'tomorrow'\n *\n * intlFormatDistance(later, earlier, { numeric: 'always' });\n * // => 'in 1 day'\n * ```\n */\nexport function intlFormatDistance(\n laterDate: Temporal.Instant | Temporal.ZonedDateTime,\n earlierDate: Temporal.Instant | Temporal.ZonedDateTime,\n options?: IntlFormatDistanceOptions\n): string {\n const zoned1 = normalizeTemporalInput(laterDate);\n const zoned2 = normalizeTemporalInput(earlierDate);\n\n // Determine unit if not specified\n let unit = options?.unit;\n if (!unit) {\n const absSeconds = Math.abs(differenceInSeconds(zoned1, zoned2));\n const absMinutes = Math.abs(differenceInMinutes(zoned1, zoned2));\n const absHours = Math.abs(differenceInHours(zoned1, zoned2));\n const absDays = Math.abs(differenceInDays(zoned1, zoned2));\n const absWeeks = Math.abs(differenceInWeeks(zoned1, zoned2));\n const absMonths = Math.abs(differenceInMonths(zoned1, zoned2));\n\n if (absSeconds < 60) {\n unit = 'second';\n } else if (absMinutes < 60) {\n unit = 'minute';\n } else if (absHours < 24) {\n unit = 'hour';\n } else if (absDays < 7) {\n unit = 'day';\n } else if (absWeeks < 4) {\n unit = 'week';\n } else if (absMonths < 12) {\n unit = 'month';\n } else {\n unit = 'year';\n }\n }\n\n // Calculate value for the selected unit\n let value: number;\n switch (unit) {\n case 'second':\n value = Math.round(differenceInSeconds(zoned1, zoned2));\n break;\n case 'minute':\n value = Math.round(differenceInMinutes(zoned1, zoned2));\n break;\n case 'hour':\n value = Math.round(differenceInHours(zoned1, zoned2));\n break;\n case 'day':\n value = Math.round(differenceInDays(zoned1, zoned2));\n break;\n case 'week':\n value = Math.round(differenceInWeeks(zoned1, zoned2));\n break;\n case 'month':\n value = Math.round(differenceInMonths(zoned1, zoned2));\n break;\n case 'quarter':\n value = Math.round(differenceInMonths(zoned1, zoned2) / 3);\n break;\n case 'year':\n value = Math.round(differenceInYears(zoned1, zoned2));\n break;\n default:\n // For any other unit type, try to use it directly\n value = Math.round(differenceInSeconds(zoned1, zoned2));\n }\n\n // Format using Intl.RelativeTimeFormat\n const formatter = new Intl.RelativeTimeFormat(options?.locale, {\n localeMatcher: options?.localeMatcher,\n numeric: options?.numeric ?? 'auto',\n style: options?.style,\n });\n\n return formatter.format(value, unit);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6FO,SAAS,mBACd,WACA,aACA,SACQ;AACR,QAAM,SAAS,uBAAuB,SAAS;AAC/C,QAAM,SAAS,uBAAuB,WAAW;AAGjD,MAAI,OAAO,SAAS;AACpB,MAAI,CAAC,MAAM;AACT,UAAM,aAAa,KAAK,IAAI,oBAAoB,QAAQ,MAAM,CAAC;AAC/D,UAAM,aAAa,KAAK,IAAI,oBAAoB,QAAQ,MAAM,CAAC;AAC/D,UAAM,WAAW,KAAK,IAAI,kBAAkB,QAAQ,MAAM,CAAC;AAC3D,UAAM,UAAU,KAAK,IAAI,iBAAiB,QAAQ,MAAM,CAAC;AACzD,UAAM,WAAW,KAAK,IAAI,kBAAkB,QAAQ,MAAM,CAAC;AAC3D,UAAM,YAAY,KAAK,IAAI,mBAAmB,QAAQ,MAAM,CAAC;AAE7D,QAAI,aAAa,IAAI;AACnB,aAAO;AAAA,IACT,WAAW,aAAa,IAAI;AAC1B,aAAO;AAAA,IACT,WAAW,WAAW,IAAI;AACxB,aAAO;AAAA,IACT,WAAW,UAAU,GAAG;AACtB,aAAO;AAAA,IACT,WAAW,WAAW,GAAG;AACvB,aAAO;AAAA,IACT,WAAW,YAAY,IAAI;AACzB,aAAO;AAAA,IACT,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAGA,MAAI;AACJ,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,cAAQ,KAAK,MAAM,oBAAoB,QAAQ,MAAM,CAAC;AACtD;AAAA,IACF,KAAK;AACH,cAAQ,KAAK,MAAM,oBAAoB,QAAQ,MAAM,CAAC;AACtD;AAAA,IACF,KAAK;AACH,cAAQ,KAAK,MAAM,kBAAkB,QAAQ,MAAM,CAAC;AACpD;AAAA,IACF,KAAK;AACH,cAAQ,KAAK,MAAM,iBAAiB,QAAQ,MAAM,CAAC;AACnD;AAAA,IACF,KAAK;AACH,cAAQ,KAAK,MAAM,kBAAkB,QAAQ,MAAM,CAAC;AACpD;AAAA,IACF,KAAK;AACH,cAAQ,KAAK,MAAM,mBAAmB,QAAQ,MAAM,CAAC;AACrD;AAAA,IACF,KAAK;AACH,cAAQ,KAAK,MAAM,mBAAmB,QAAQ,MAAM,IAAI,CAAC;AACzD;AAAA,IACF,KAAK;AACH,cAAQ,KAAK,MAAM,kBAAkB,QAAQ,MAAM,CAAC;AACpD;AAAA,IACF;AAEE,cAAQ,KAAK,MAAM,oBAAoB,QAAQ,MAAM,CAAC;AAAA,EAC1D;AAGA,QAAM,YAAY,IAAI,KAAK,mBAAmB,SAAS,QAAQ;AAAA,IAC7D,eAAe,SAAS;AAAA,IACxB,SAAS,SAAS,WAAW;AAAA,IAC7B,OAAO,SAAS;AAAA,EAClB,CAAC;AAED,SAAO,UAAU,OAAO,OAAO,IAAI;AACrC;","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":[]}
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";
@@ -132,7 +132,7 @@ import {
132
132
  } from "./chunk-3A6X6WV5.js";
133
133
  import {
134
134
  intlFormatDistance
135
- } from "./chunk-ZJQS7ZY7.js";
135
+ } from "./chunk-5BYRBC7H.js";
136
136
  import {
137
137
  isAfter
138
138
  } from "./chunk-7VLSSOVC.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  intlFormatDistance
3
- } from "./chunk-ZJQS7ZY7.js";
3
+ } from "./chunk-5BYRBC7H.js";
4
4
  import "./chunk-BIAPE4MR.js";
5
5
  import "./chunk-QVOEXF46.js";
6
6
  import "./chunk-PVAOUYXF.js";
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.7.0",
3
+ "version": "2.8.1",
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":[]}