@prairielearn/formatter 1.3.14 → 1.4.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @prairielearn/formatter
2
2
 
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 678b48a: Upgrade all JavaScript dependencies
8
+
9
+ ## 1.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 74b5cac: Add friendly date formatters and tests, and additional supporting utilities
14
+
3
15
  ## 1.3.14
4
16
 
5
17
  ### Patch Changes
package/dist/date.d.ts CHANGED
@@ -35,3 +35,73 @@ export declare function formatDateYMDHM(date: Date, timeZone: string): string;
35
35
  * @returns Human-readable string representing the time zone.
36
36
  */
37
37
  export declare function formatTz(timeZone: string): string;
38
+ /**
39
+ * Format a date to a human-readable string like '14:27:00 (CDT)'.
40
+ *
41
+ * @param date The date to format.
42
+ * @param timeZone The time zone to use for formatting.
43
+ * @param param2.includeTz Whether to include the time zone in the output (default true).
44
+ * @returns Human-readable string representing the date.
45
+ */
46
+ export declare function formatDateHMS(date: Date, timeZone: string, { includeTz }?: {
47
+ includeTz?: boolean;
48
+ }): string;
49
+ /**
50
+ * Format a date to a human-readable string like '18:23' or 'May 2, 07:12',
51
+ * where the precision is determined by the range.
52
+ *
53
+ * @param date The date to format.
54
+ * @param rangeStart The start of the range.
55
+ * @param rangeEnd The end of the range.
56
+ * @param timeZone The time zone to use for formatting.
57
+ * @returns Human-readable string representing the date.
58
+ */
59
+ export declare function formatDateWithinRange(date: Date, rangeStart: Date, rangeEnd: Date, timeZone: string): string;
60
+ /**
61
+ * Format a date to a string like:
62
+ * - 'today, 3pm'
63
+ * - 'tomorrow, 10:30am'
64
+ * - 'yesterday, 11:45pm'
65
+ * - 'Mon, Mar 20, 8:15am' (if within 180 days of the base date)
66
+ * - 'Wed, Jan 1, 2020, 12pm'
67
+ * - `today, 3pm (CDT)` (if `includeTz` is true)
68
+ * - `3pm today` (if `timeFirst` is true)
69
+ * - 'today' (if `dateOnly` is true)
70
+ *
71
+ * If using this within a sentence like `... at ${formatDateFriendlyString()}`,
72
+ * use `timeFirst: true` to improve readability.
73
+ *
74
+ * @param date The date to format.
75
+ * @param timezone The time zone to use for formatting.
76
+ * @param param.baseDate The base date to use for comparison (default is the current date).
77
+ * @param param.includeTz Whether to include the time zone in the output (default true).
78
+ * @param param.timeFirst If true, the time is shown before the date (default false).
79
+ * @param param.dateOnly If true, only the date is shown (default false).
80
+ * @param param.timeOnly If true, only the time is shown (default false).
81
+ * @returns Human-readable string representing the date and time.
82
+ */
83
+ export declare function formatDateFriendly(date: Date, timezone: string, { baseDate, includeTz, timeFirst, dateOnly, timeOnly, }?: {
84
+ baseDate?: Date;
85
+ includeTz?: boolean;
86
+ timeFirst?: boolean;
87
+ dateOnly?: boolean;
88
+ timeOnly?: boolean;
89
+ }): string;
90
+ /**
91
+ * Format a datetime range to a string like:
92
+ * - 'today, 10am'
93
+ * - 'today, 3pm to 5pm'
94
+ * - 'today, 3pm to tomorrow, 5pm'
95
+ * - 'today, 3pm to 5pm (CDT)' (if `includeTz` is true)
96
+ * - '3pm today to 5pm tomorrow' (if `timeFirst` is true)
97
+ * - 'today to tomorrow' (if `dateOnly` is true)
98
+ *
99
+ * This uses `formatDateFriendlyString()` to format the individual dates and times.
100
+ *
101
+ * @param start The start date and time.
102
+ * @param end The end date and time.
103
+ * @param timezone The time zone to use for formatting.
104
+ * @param options Additional options for formatting the displayed date, taken from `formatDateFriendlyString()`.
105
+ * @returns Human-readable string representing the datetime range.
106
+ */
107
+ export declare function formatDateRangeFriendly(start: Date, end: Date, timezone: string, { baseDate, includeTz, timeFirst, dateOnly, }?: Parameters<typeof formatDateFriendly>[2]): string;
package/dist/date.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { toTemporalInstant } from '@js-temporal/polyfill';
1
2
  import keyBy from 'lodash/keyBy.js';
2
3
  /**
3
4
  * Format a date to a human-readable string like '2020-03-27T12:34:56 (CDT)'.
@@ -84,4 +85,260 @@ export function formatTz(timeZone) {
84
85
  const tz = parts.find((p) => p.type === 'timeZoneName');
85
86
  return tz ? tz.value : timeZone;
86
87
  }
88
+ /**
89
+ * Format a date to a human-readable string like '14:27:00 (CDT)'.
90
+ *
91
+ * @param date The date to format.
92
+ * @param timeZone The time zone to use for formatting.
93
+ * @param param2.includeTz Whether to include the time zone in the output (default true).
94
+ * @returns Human-readable string representing the date.
95
+ */
96
+ export function formatDateHMS(date, timeZone, { includeTz = true } = {}) {
97
+ const options = {
98
+ timeZone,
99
+ hourCycle: 'h23',
100
+ hour: '2-digit',
101
+ minute: '2-digit',
102
+ second: '2-digit',
103
+ timeZoneName: 'short',
104
+ };
105
+ const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);
106
+ let dateFormatted = `${parts.hour.value}:${parts.minute.value}:${parts.second.value}`;
107
+ if (includeTz) {
108
+ dateFormatted = `${dateFormatted} (${parts.timeZoneName.value})`;
109
+ }
110
+ return dateFormatted;
111
+ }
112
+ /**
113
+ * Format a date to a human-readable string like '18:23' or 'May 2, 07:12',
114
+ * where the precision is determined by the range.
115
+ *
116
+ * @param date The date to format.
117
+ * @param rangeStart The start of the range.
118
+ * @param rangeEnd The end of the range.
119
+ * @param timeZone The time zone to use for formatting.
120
+ * @returns Human-readable string representing the date.
121
+ */
122
+ export function formatDateWithinRange(date, rangeStart, rangeEnd, timeZone) {
123
+ const options = {
124
+ timeZone,
125
+ hourCycle: 'h23',
126
+ year: 'numeric',
127
+ month: '2-digit',
128
+ day: '2-digit',
129
+ hour: '2-digit',
130
+ minute: '2-digit',
131
+ timeZoneName: 'short',
132
+ };
133
+ const dateParts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);
134
+ const startParts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(rangeStart), (x) => x.type);
135
+ const endParts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(rangeEnd), (x) => x.type);
136
+ // format the date (not time) parts
137
+ const dateYMD = `${dateParts.year.value}-${dateParts.month.value}-${dateParts.day.value}`;
138
+ const startYMD = `${startParts.year.value}-${startParts.month.value}-${startParts.day.value}`;
139
+ const endYMD = `${endParts.year.value}-${endParts.month.value}-${endParts.day.value}`;
140
+ if (dateYMD === startYMD && dateYMD === endYMD) {
141
+ // only show the time if the date is the same for all three
142
+ return `${dateParts.hour.value}:${dateParts.minute.value}`;
143
+ }
144
+ // format the year, but not the month or day
145
+ const dateY = `${dateParts.year.value}`;
146
+ const startY = `${startParts.year.value}`;
147
+ const endY = `${endParts.year.value}`;
148
+ // if the year is the same for all three, show the month, day, and time
149
+ if (dateY === startY && dateY === endY) {
150
+ const options = {
151
+ timeZone,
152
+ month: 'short',
153
+ day: 'numeric',
154
+ hour: '2-digit',
155
+ minute: '2-digit',
156
+ };
157
+ const dateParts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);
158
+ return `${dateParts.month.value} ${dateParts.day.value}, ${dateParts.hour.value}:${dateParts.minute.value}`;
159
+ }
160
+ // fall back to the full date
161
+ return `${dateParts.year.value}-${dateParts.month.value}-${dateParts.day.value} ${dateParts.hour.value}:${dateParts.minute.value}`;
162
+ }
163
+ /**
164
+ * Format a Date to date and time strings in the given time zone. The date is
165
+ * formatted like
166
+ * - 'today'
167
+ * - 'Mon, Mar 20' (if within 180 days of the base date)
168
+ * - 'Wed, Jan 1, 2020'
169
+ *
170
+ * The time format leaves off zero minutes and seconds, and uses 12-hour time,
171
+ * giving strings like
172
+ * - '3pm'
173
+ * - '3:34pm'
174
+ * - '3:34:17pm'
175
+ *
176
+ * @param date The date to format.
177
+ * @param timezone The time zone to use for formatting.
178
+ * @param baseDate The base date to use for comparison.
179
+ */
180
+ function formatDateFriendlyParts(date, timezone, baseDate) {
181
+ // compute the number of days from the base date (0 = today, 1 = tomorrow, etc.)
182
+ const baseZonedDateTime = toTemporalInstant.call(baseDate).toZonedDateTimeISO(timezone);
183
+ const zonedDateTime = toTemporalInstant.call(date).toZonedDateTimeISO(timezone);
184
+ const basePlainDate = baseZonedDateTime.toPlainDate();
185
+ const plainDate = zonedDateTime.toPlainDate();
186
+ const daysOffset = plainDate.since(basePlainDate, { largestUnit: 'day' }).days;
187
+ // format the parts of the date and time
188
+ const options = {
189
+ timeZone: timezone,
190
+ year: 'numeric',
191
+ month: 'short',
192
+ day: 'numeric',
193
+ weekday: 'short',
194
+ hourCycle: 'h12',
195
+ hour: 'numeric',
196
+ minute: '2-digit',
197
+ second: '2-digit',
198
+ timeZoneName: 'short',
199
+ };
200
+ const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);
201
+ // format the date string
202
+ let dateFormatted = '';
203
+ if (daysOffset === 0) {
204
+ dateFormatted = 'today';
205
+ }
206
+ else if (daysOffset === 1) {
207
+ dateFormatted = 'tomorrow';
208
+ }
209
+ else if (daysOffset === -1) {
210
+ dateFormatted = 'yesterday';
211
+ }
212
+ else if (Math.abs(daysOffset) <= 180) {
213
+ // non-breaking-space (\u00a0) is used between the month and day
214
+ dateFormatted = `${parts.weekday.value}, ${parts.month.value}\u00a0${parts.day.value}`;
215
+ }
216
+ else {
217
+ dateFormatted = `${parts.weekday.value}, ${parts.month.value}\u00a0${parts.day.value}, ${parts.year.value}`;
218
+ }
219
+ // format the time string
220
+ let timeFormatted = '';
221
+ if (parts.minute.value === '00' && parts.second.value === '00') {
222
+ timeFormatted = `${parts.hour.value}`;
223
+ }
224
+ else if (parts.second.value === '00') {
225
+ timeFormatted = `${parts.hour.value}:${parts.minute.value}`;
226
+ }
227
+ else {
228
+ timeFormatted = `${parts.hour.value}:${parts.minute.value}:${parts.second.value}`;
229
+ }
230
+ // add the am/pm part
231
+ timeFormatted = `${timeFormatted}${parts.dayPeriod.value.toLowerCase()}`;
232
+ // format the timezone
233
+ const timezoneFormatted = `(${parts.timeZoneName.value})`;
234
+ return {
235
+ dateFormatted,
236
+ timeFormatted,
237
+ timezoneFormatted,
238
+ };
239
+ }
240
+ /**
241
+ * Format a date to a string like:
242
+ * - 'today, 3pm'
243
+ * - 'tomorrow, 10:30am'
244
+ * - 'yesterday, 11:45pm'
245
+ * - 'Mon, Mar 20, 8:15am' (if within 180 days of the base date)
246
+ * - 'Wed, Jan 1, 2020, 12pm'
247
+ * - `today, 3pm (CDT)` (if `includeTz` is true)
248
+ * - `3pm today` (if `timeFirst` is true)
249
+ * - 'today' (if `dateOnly` is true)
250
+ *
251
+ * If using this within a sentence like `... at ${formatDateFriendlyString()}`,
252
+ * use `timeFirst: true` to improve readability.
253
+ *
254
+ * @param date The date to format.
255
+ * @param timezone The time zone to use for formatting.
256
+ * @param param.baseDate The base date to use for comparison (default is the current date).
257
+ * @param param.includeTz Whether to include the time zone in the output (default true).
258
+ * @param param.timeFirst If true, the time is shown before the date (default false).
259
+ * @param param.dateOnly If true, only the date is shown (default false).
260
+ * @param param.timeOnly If true, only the time is shown (default false).
261
+ * @returns Human-readable string representing the date and time.
262
+ */
263
+ export function formatDateFriendly(date, timezone, { baseDate = new Date(), includeTz = true, timeFirst = false, dateOnly = false, timeOnly = false, } = {}) {
264
+ const { dateFormatted, timeFormatted, timezoneFormatted } = formatDateFriendlyParts(date, timezone, baseDate);
265
+ let dateTimeFormatted = '';
266
+ if (dateOnly) {
267
+ dateTimeFormatted = dateFormatted;
268
+ }
269
+ else if (timeOnly) {
270
+ dateTimeFormatted = timeFormatted;
271
+ }
272
+ else {
273
+ if (timeFirst) {
274
+ dateTimeFormatted = `${timeFormatted} ${dateFormatted}`;
275
+ }
276
+ else {
277
+ dateTimeFormatted = `${dateFormatted}, ${timeFormatted}`;
278
+ }
279
+ }
280
+ if (includeTz) {
281
+ dateTimeFormatted = `${dateTimeFormatted} ${timezoneFormatted}`;
282
+ }
283
+ return dateTimeFormatted;
284
+ }
285
+ /**
286
+ * Format a datetime range to a string like:
287
+ * - 'today, 10am'
288
+ * - 'today, 3pm to 5pm'
289
+ * - 'today, 3pm to tomorrow, 5pm'
290
+ * - 'today, 3pm to 5pm (CDT)' (if `includeTz` is true)
291
+ * - '3pm today to 5pm tomorrow' (if `timeFirst` is true)
292
+ * - 'today to tomorrow' (if `dateOnly` is true)
293
+ *
294
+ * This uses `formatDateFriendlyString()` to format the individual dates and times.
295
+ *
296
+ * @param start The start date and time.
297
+ * @param end The end date and time.
298
+ * @param timezone The time zone to use for formatting.
299
+ * @param options Additional options for formatting the displayed date, taken from `formatDateFriendlyString()`.
300
+ * @returns Human-readable string representing the datetime range.
301
+ */
302
+ export function formatDateRangeFriendly(start, end, timezone, { baseDate = new Date(), includeTz = true, timeFirst = false, dateOnly = false, } = {}) {
303
+ const { dateFormatted: startDateFormatted, timeFormatted: startTimeFormatted, timezoneFormatted, } = formatDateFriendlyParts(start, timezone, baseDate);
304
+ const { dateFormatted: endDateFormatted, timeFormatted: endTimeFormatted } = formatDateFriendlyParts(end, timezone, baseDate);
305
+ let result;
306
+ if (dateOnly) {
307
+ if (startDateFormatted === endDateFormatted) {
308
+ result = startDateFormatted;
309
+ }
310
+ else {
311
+ result = `${startDateFormatted} to ${endDateFormatted}`;
312
+ }
313
+ }
314
+ else {
315
+ if (startDateFormatted === endDateFormatted) {
316
+ let timeRangeFormatted;
317
+ if (startTimeFormatted === endTimeFormatted) {
318
+ timeRangeFormatted = startTimeFormatted;
319
+ }
320
+ else {
321
+ timeRangeFormatted = `${startTimeFormatted} to ${endTimeFormatted}`;
322
+ }
323
+ if (timeFirst) {
324
+ result = `${timeRangeFormatted} ${startDateFormatted}`;
325
+ }
326
+ else {
327
+ result = `${startDateFormatted}, ${timeRangeFormatted}`;
328
+ }
329
+ }
330
+ else {
331
+ if (timeFirst) {
332
+ result = `${startTimeFormatted} ${startDateFormatted} to ${endTimeFormatted} ${endDateFormatted}`;
333
+ }
334
+ else {
335
+ result = `${startDateFormatted}, ${startTimeFormatted} to ${endDateFormatted}, ${endTimeFormatted}`;
336
+ }
337
+ }
338
+ }
339
+ if (includeTz) {
340
+ result = `${result} ${timezoneFormatted}`;
341
+ }
342
+ return result;
343
+ }
87
344
  //# sourceMappingURL=date.js.map
package/dist/date.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"date.js","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,iBAAiB,CAAC;AAEpC;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,IAAU,EACV,QAAgB,EAChB,EACE,SAAS,GAAG,IAAI,EAChB,MAAM,GAAG,KAAK,EACd,SAAS,GAAG,KAAK,MACiD,EAAE;IAEtE,MAAM,OAAO,GAA+B;QAC1C,QAAQ;QACR,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,SAAS;QACjB,sBAAsB,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS;QACjD,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;KACxC,CAAC;IACF,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAClG,IAAI,aAAa,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAClJ,IAAI,SAAS,EAAE,CAAC;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OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;AACjH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB;IACvC,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACxB,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;QAC7C,QAAQ;QACR,YAAY,EAAE,OAAO;KACtB,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACvB,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;IACxD,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClC,CAAC","sourcesContent":["import keyBy from 'lodash/keyBy.js';\n\n/**\n * Format a date to a human-readable string like '2020-03-27T12:34:56 (CDT)'.\n *\n * @param date The date to format.\n * @param timeZone The time zone to use for formatting.\n * @param param2.includeTz Whether to include the time zone in the output (default true).\n * @param param2.longTz Whether to use the long time zone name (default false).\n * @returns Human-readable string representing the date.\n */\nexport function formatDate(\n date: Date,\n timeZone: string,\n {\n includeTz = true,\n longTz = false,\n includeMs = false,\n }: { includeTz?: boolean; longTz?: boolean; includeMs?: boolean } = {},\n): string {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n fractionalSecondDigits: includeMs ? 3 : undefined,\n timeZoneName: longTz ? 'long' : 'short',\n };\n const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);\n let dateFormatted = `${parts.year.value}-${parts.month.value}-${parts.day.value} ${parts.hour.value}:${parts.minute.value}:${parts.second.value}`;\n if (includeMs) {\n dateFormatted = `${dateFormatted}.${parts.fractionalSecond.value}`;\n }\n if (includeTz) {\n dateFormatted = `${dateFormatted} (${parts.timeZoneName.value})`;\n }\n return dateFormatted;\n}\n\n/**\n * Format a date to a human-readable string like '2020-03-27'.\n *\n * @param date The date to format.\n * @param timeZone The time zone to use for formatting.\n * @returns Human-readable string representing the date.\n */\nexport function formatDateYMD(date: Date, timeZone: string): string {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n };\n const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);\n return `${parts.year.value}-${parts.month.value}-${parts.day.value}`;\n}\n\n/**\n * Format a date to a human-readable string like '2020-03-27 14:27'.\n *\n * @param date The date to format.\n * @param timeZone The time zone to use for formatting.\n * @returns Human-readable string representing the date.\n */\nexport function formatDateYMDHM(date: Date, timeZone: string): string {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n };\n const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);\n return `${parts.year.value}-${parts.month.value}-${parts.day.value} ${parts.hour.value}:${parts.minute.value}`;\n}\n\n/**\n * Format a time zone to a human-readable string like 'CDT'.\n *\n * @param timeZone The time zone to format.\n * @returns Human-readable string representing the time zone.\n */\nexport function formatTz(timeZone: string): string {\n const date = new Date();\n const parts = new Intl.DateTimeFormat('en-US', {\n timeZone,\n timeZoneName: 'short',\n }).formatToParts(date);\n const tz = parts.find((p) => p.type === 'timeZoneName');\n return tz ? tz.value : timeZone;\n}\n"]}
1
+ {"version":3,"file":"date.js","sourceRoot":"","sources":["../src/date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CAAC;YACN,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,GAAG,GAAG,kBAAkB,IAAI,kBAAkB,OAAO,gBAAgB,IAAI,gBAAgB,EAAE,CAAC;YACpG,CAAC;iBAAM,CAAC;gBACN,MAAM,GAAG,GAAG,kBAAkB,KAAK,kBAAkB,OAAO,gBAAgB,KAAK,gBAAgB,EAAE,CAAC;YACtG,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,GAAG,GAAG,MAAM,IAAI,iBAAiB,EAAE,CAAC;IAC5C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { toTemporalInstant } from '@js-temporal/polyfill';\nimport keyBy from 'lodash/keyBy.js';\n\n/**\n * Format a date to a human-readable string like '2020-03-27T12:34:56 (CDT)'.\n *\n * @param date The date to format.\n * @param timeZone The time zone to use for formatting.\n * @param param2.includeTz Whether to include the time zone in the output (default true).\n * @param param2.longTz Whether to use the long time zone name (default false).\n * @returns Human-readable string representing the date.\n */\nexport function formatDate(\n date: Date,\n timeZone: string,\n {\n includeTz = true,\n longTz = false,\n includeMs = false,\n }: { includeTz?: boolean; longTz?: boolean; includeMs?: boolean } = {},\n): string {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n fractionalSecondDigits: includeMs ? 3 : undefined,\n timeZoneName: longTz ? 'long' : 'short',\n };\n const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);\n let dateFormatted = `${parts.year.value}-${parts.month.value}-${parts.day.value} ${parts.hour.value}:${parts.minute.value}:${parts.second.value}`;\n if (includeMs) {\n dateFormatted = `${dateFormatted}.${parts.fractionalSecond.value}`;\n }\n if (includeTz) {\n dateFormatted = `${dateFormatted} (${parts.timeZoneName.value})`;\n }\n return dateFormatted;\n}\n\n/**\n * Format a date to a human-readable string like '2020-03-27'.\n *\n * @param date The date to format.\n * @param timeZone The time zone to use for formatting.\n * @returns Human-readable string representing the date.\n */\nexport function formatDateYMD(date: Date, timeZone: string): string {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n };\n const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);\n return `${parts.year.value}-${parts.month.value}-${parts.day.value}`;\n}\n\n/**\n * Format a date to a human-readable string like '2020-03-27 14:27'.\n *\n * @param date The date to format.\n * @param timeZone The time zone to use for formatting.\n * @returns Human-readable string representing the date.\n */\nexport function formatDateYMDHM(date: Date, timeZone: string): string {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n };\n const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);\n return `${parts.year.value}-${parts.month.value}-${parts.day.value} ${parts.hour.value}:${parts.minute.value}`;\n}\n\n/**\n * Format a time zone to a human-readable string like 'CDT'.\n *\n * @param timeZone The time zone to format.\n * @returns Human-readable string representing the time zone.\n */\nexport function formatTz(timeZone: string): string {\n const date = new Date();\n const parts = new Intl.DateTimeFormat('en-US', {\n timeZone,\n timeZoneName: 'short',\n }).formatToParts(date);\n const tz = parts.find((p) => p.type === 'timeZoneName');\n return tz ? tz.value : timeZone;\n}\n\n/**\n * Format a date to a human-readable string like '14:27:00 (CDT)'.\n *\n * @param date The date to format.\n * @param timeZone The time zone to use for formatting.\n * @param param2.includeTz Whether to include the time zone in the output (default true).\n * @returns Human-readable string representing the date.\n */\nexport function formatDateHMS(\n date: Date,\n timeZone: string,\n { includeTz = true }: { includeTz?: boolean } = {},\n): string {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n hourCycle: 'h23',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n timeZoneName: 'short',\n };\n const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);\n let dateFormatted = `${parts.hour.value}:${parts.minute.value}:${parts.second.value}`;\n if (includeTz) {\n dateFormatted = `${dateFormatted} (${parts.timeZoneName.value})`;\n }\n return dateFormatted;\n}\n\n/**\n * Format a date to a human-readable string like '18:23' or 'May 2, 07:12',\n * where the precision is determined by the range.\n *\n * @param date The date to format.\n * @param rangeStart The start of the range.\n * @param rangeEnd The end of the range.\n * @param timeZone The time zone to use for formatting.\n * @returns Human-readable string representing the date.\n */\nexport function formatDateWithinRange(\n date: Date,\n rangeStart: Date,\n rangeEnd: Date,\n timeZone: string,\n): string {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n hourCycle: 'h23',\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n timeZoneName: 'short',\n };\n const dateParts = keyBy(\n new Intl.DateTimeFormat('en-US', options).formatToParts(date),\n (x) => x.type,\n );\n const startParts = keyBy(\n new Intl.DateTimeFormat('en-US', options).formatToParts(rangeStart),\n (x) => x.type,\n );\n const endParts = keyBy(\n new Intl.DateTimeFormat('en-US', options).formatToParts(rangeEnd),\n (x) => x.type,\n );\n\n // format the date (not time) parts\n const dateYMD = `${dateParts.year.value}-${dateParts.month.value}-${dateParts.day.value}`;\n const startYMD = `${startParts.year.value}-${startParts.month.value}-${startParts.day.value}`;\n const endYMD = `${endParts.year.value}-${endParts.month.value}-${endParts.day.value}`;\n\n if (dateYMD === startYMD && dateYMD === endYMD) {\n // only show the time if the date is the same for all three\n return `${dateParts.hour.value}:${dateParts.minute.value}`;\n }\n\n // format the year, but not the month or day\n const dateY = `${dateParts.year.value}`;\n const startY = `${startParts.year.value}`;\n const endY = `${endParts.year.value}`;\n\n // if the year is the same for all three, show the month, day, and time\n if (dateY === startY && dateY === endY) {\n const options: Intl.DateTimeFormatOptions = {\n timeZone,\n month: 'short',\n day: 'numeric',\n hour: '2-digit',\n minute: '2-digit',\n };\n const dateParts = keyBy(\n new Intl.DateTimeFormat('en-US', options).formatToParts(date),\n (x) => x.type,\n );\n return `${dateParts.month.value} ${dateParts.day.value}, ${dateParts.hour.value}:${dateParts.minute.value}`;\n }\n\n // fall back to the full date\n return `${dateParts.year.value}-${dateParts.month.value}-${dateParts.day.value} ${dateParts.hour.value}:${dateParts.minute.value}`;\n}\n\n/**\n * Format a Date to date and time strings in the given time zone. The date is\n * formatted like\n * - 'today'\n * - 'Mon, Mar 20' (if within 180 days of the base date)\n * - 'Wed, Jan 1, 2020'\n *\n * The time format leaves off zero minutes and seconds, and uses 12-hour time,\n * giving strings like\n * - '3pm'\n * - '3:34pm'\n * - '3:34:17pm'\n *\n * @param date The date to format.\n * @param timezone The time zone to use for formatting.\n * @param baseDate The base date to use for comparison.\n */\nfunction formatDateFriendlyParts(\n date: Date,\n timezone: string,\n baseDate: Date,\n): { dateFormatted: string; timeFormatted: string; timezoneFormatted: string } {\n // compute the number of days from the base date (0 = today, 1 = tomorrow, etc.)\n\n const baseZonedDateTime = toTemporalInstant.call(baseDate).toZonedDateTimeISO(timezone);\n const zonedDateTime = toTemporalInstant.call(date).toZonedDateTimeISO(timezone);\n\n const basePlainDate = baseZonedDateTime.toPlainDate();\n const plainDate = zonedDateTime.toPlainDate();\n\n const daysOffset = plainDate.since(basePlainDate, { largestUnit: 'day' }).days;\n\n // format the parts of the date and time\n\n const options: Intl.DateTimeFormatOptions = {\n timeZone: timezone,\n year: 'numeric',\n month: 'short',\n day: 'numeric',\n weekday: 'short',\n hourCycle: 'h12',\n hour: 'numeric',\n minute: '2-digit',\n second: '2-digit',\n timeZoneName: 'short',\n };\n const parts = keyBy(new Intl.DateTimeFormat('en-US', options).formatToParts(date), (x) => x.type);\n\n // format the date string\n\n let dateFormatted = '';\n if (daysOffset === 0) {\n dateFormatted = 'today';\n } else if (daysOffset === 1) {\n dateFormatted = 'tomorrow';\n } else if (daysOffset === -1) {\n dateFormatted = 'yesterday';\n } else if (Math.abs(daysOffset) <= 180) {\n // non-breaking-space (\\u00a0) is used between the month and day\n dateFormatted = `${parts.weekday.value}, ${parts.month.value}\\u00a0${parts.day.value}`;\n } else {\n dateFormatted = `${parts.weekday.value}, ${parts.month.value}\\u00a0${parts.day.value}, ${parts.year.value}`;\n }\n\n // format the time string\n\n let timeFormatted = '';\n if (parts.minute.value === '00' && parts.second.value === '00') {\n timeFormatted = `${parts.hour.value}`;\n } else if (parts.second.value === '00') {\n timeFormatted = `${parts.hour.value}:${parts.minute.value}`;\n } else {\n timeFormatted = `${parts.hour.value}:${parts.minute.value}:${parts.second.value}`;\n }\n // add the am/pm part\n timeFormatted = `${timeFormatted}${parts.dayPeriod.value.toLowerCase()}`;\n\n // format the timezone\n\n const timezoneFormatted = `(${parts.timeZoneName.value})`;\n\n return {\n dateFormatted,\n timeFormatted,\n timezoneFormatted,\n };\n}\n\n/**\n * Format a date to a string like:\n * - 'today, 3pm'\n * - 'tomorrow, 10:30am'\n * - 'yesterday, 11:45pm'\n * - 'Mon, Mar 20, 8:15am' (if within 180 days of the base date)\n * - 'Wed, Jan 1, 2020, 12pm'\n * - `today, 3pm (CDT)` (if `includeTz` is true)\n * - `3pm today` (if `timeFirst` is true)\n * - 'today' (if `dateOnly` is true)\n *\n * If using this within a sentence like `... at ${formatDateFriendlyString()}`,\n * use `timeFirst: true` to improve readability.\n *\n * @param date The date to format.\n * @param timezone The time zone to use for formatting.\n * @param param.baseDate The base date to use for comparison (default is the current date).\n * @param param.includeTz Whether to include the time zone in the output (default true).\n * @param param.timeFirst If true, the time is shown before the date (default false).\n * @param param.dateOnly If true, only the date is shown (default false).\n * @param param.timeOnly If true, only the time is shown (default false).\n * @returns Human-readable string representing the date and time.\n */\nexport function formatDateFriendly(\n date: Date,\n timezone: string,\n {\n baseDate = new Date(),\n includeTz = true,\n timeFirst = false,\n dateOnly = false,\n timeOnly = false,\n }: {\n baseDate?: Date;\n includeTz?: boolean;\n timeFirst?: boolean;\n dateOnly?: boolean;\n timeOnly?: boolean;\n } = {},\n): string {\n const { dateFormatted, timeFormatted, timezoneFormatted } = formatDateFriendlyParts(\n date,\n timezone,\n baseDate,\n );\n\n let dateTimeFormatted = '';\n if (dateOnly) {\n dateTimeFormatted = dateFormatted;\n } else if (timeOnly) {\n dateTimeFormatted = timeFormatted;\n } else {\n if (timeFirst) {\n dateTimeFormatted = `${timeFormatted} ${dateFormatted}`;\n } else {\n dateTimeFormatted = `${dateFormatted}, ${timeFormatted}`;\n }\n }\n if (includeTz) {\n dateTimeFormatted = `${dateTimeFormatted} ${timezoneFormatted}`;\n }\n return dateTimeFormatted;\n}\n\n/**\n * Format a datetime range to a string like:\n * - 'today, 10am'\n * - 'today, 3pm to 5pm'\n * - 'today, 3pm to tomorrow, 5pm'\n * - 'today, 3pm to 5pm (CDT)' (if `includeTz` is true)\n * - '3pm today to 5pm tomorrow' (if `timeFirst` is true)\n * - 'today to tomorrow' (if `dateOnly` is true)\n *\n * This uses `formatDateFriendlyString()` to format the individual dates and times.\n *\n * @param start The start date and time.\n * @param end The end date and time.\n * @param timezone The time zone to use for formatting.\n * @param options Additional options for formatting the displayed date, taken from `formatDateFriendlyString()`.\n * @returns Human-readable string representing the datetime range.\n */\nexport function formatDateRangeFriendly(\n start: Date,\n end: Date,\n timezone: string,\n {\n baseDate = new Date(),\n includeTz = true,\n timeFirst = false,\n dateOnly = false,\n }: Parameters<typeof formatDateFriendly>[2] = {},\n): string {\n const {\n dateFormatted: startDateFormatted,\n timeFormatted: startTimeFormatted,\n timezoneFormatted,\n } = formatDateFriendlyParts(start, timezone, baseDate);\n const { dateFormatted: endDateFormatted, timeFormatted: endTimeFormatted } =\n formatDateFriendlyParts(end, timezone, baseDate);\n\n let result: string | undefined;\n if (dateOnly) {\n if (startDateFormatted === endDateFormatted) {\n result = startDateFormatted;\n } else {\n result = `${startDateFormatted} to ${endDateFormatted}`;\n }\n } else {\n if (startDateFormatted === endDateFormatted) {\n let timeRangeFormatted: string | undefined;\n if (startTimeFormatted === endTimeFormatted) {\n timeRangeFormatted = startTimeFormatted;\n } else {\n timeRangeFormatted = `${startTimeFormatted} to ${endTimeFormatted}`;\n }\n if (timeFirst) {\n result = `${timeRangeFormatted} ${startDateFormatted}`;\n } else {\n result = `${startDateFormatted}, ${timeRangeFormatted}`;\n }\n } else {\n if (timeFirst) {\n result = `${startTimeFormatted} ${startDateFormatted} to ${endTimeFormatted} ${endDateFormatted}`;\n } else {\n result = `${startDateFormatted}, ${startTimeFormatted} to ${endDateFormatted}, ${endTimeFormatted}`;\n }\n }\n }\n if (includeTz) {\n result = `${result} ${timezoneFormatted}`;\n }\n return result;\n}\n"]}