@gobrand/tiempo 2.8.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.
|
@@ -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-
|
|
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;
|
|
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;AA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