@aurodesignsystem-dev/auro-datetime 0.0.0-pr110.0 → 0.0.0-pr112.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.
- package/README.md +30 -41
- package/custom-elements.json +373 -0
- package/demo/api.md +198 -153
- package/demo/api.min.js +125 -136
- package/demo/index.md +14 -11
- package/demo/index.min.js +125 -136
- package/demo/readme.md +21 -20
- package/dist/auro-datetime-CRsYbYbt.js +6 -0
- package/dist/index.d.ts +75 -71
- package/dist/index.js +1 -1
- package/dist/registered.js +1 -1
- package/package.json +8 -6
- package/dist/auro-datetime-39FU0ZIU.js +0 -6
package/demo/api.min.js
CHANGED
|
@@ -114,16 +114,29 @@ const t=globalThis,i$1=t=>t,s$1=t.trustedTypes,e=s$1?s$1.createPolicy("lit-html"
|
|
|
114
114
|
const ISO_8601_REGEX =
|
|
115
115
|
/^(\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?)(Z|[+-]\d{2}:\d{2})?$/u;
|
|
116
116
|
|
|
117
|
-
// See https://git.io/JJ6SJ for "How to document your components using JSDoc"
|
|
118
117
|
/**
|
|
119
|
-
*
|
|
118
|
+
* Shows a date or time as text, formatted for a language and region you choose and, optionally, a specific time zone.
|
|
119
|
+
*
|
|
120
|
+
* **Key capabilities**
|
|
121
|
+
* - **What to show**: `type` picks the full date, the time, a numeric date, or a single part, such as the year or weekday.
|
|
122
|
+
* - **Date and time to show**: `value` takes an ISO 8601 date or date-time; without it, the element shows the current date and time.
|
|
123
|
+
* - **Language formatting**: `locale` formats month names, separators, and the 12- or 24-hour clock for a language, such as `de-DE`.
|
|
124
|
+
* - **Time zones**: `timezone` shows the moment in a time zone, such as `America/Los_Angeles`.
|
|
125
|
+
* - **Name length**: `month="long"` and `weekday="long"` spell out the month and weekday names.
|
|
126
|
+
*
|
|
127
|
+
* **Example**
|
|
128
|
+
* ```html
|
|
129
|
+
* <auro-datetime type="date" value="2022-07-14T08:00:00"></auro-datetime>
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @summary Date or time text formatted by language and time zone, with full, numeric, and single-part formats.
|
|
120
133
|
* @customElement auro-datetime
|
|
121
134
|
*
|
|
122
|
-
* @slot pre - Content
|
|
123
|
-
* @slot post - Content
|
|
135
|
+
* @slot pre - Content shown before the date or time, such as "Departs". The element doesn't currently let content sit right against the date or time: this content, or text right before the element, always shows with a space between it and the date or time. {@category ui}
|
|
136
|
+
* @slot post - Content shown after the date or time, such as "local time". The element doesn't currently let content sit right against the date or time: this content, or text right after the element, always shows with a space between them, so a period or comma can't follow the date or time directly. {@category ui}
|
|
137
|
+
* @slot - Content shown after the `post` slot's content, such as the end of a sentence that includes the date. {@category ui}
|
|
124
138
|
*/
|
|
125
139
|
|
|
126
|
-
// build the component class
|
|
127
140
|
class AuroDatetime extends i {
|
|
128
141
|
constructor() {
|
|
129
142
|
super();
|
|
@@ -131,6 +144,11 @@ class AuroDatetime extends i {
|
|
|
131
144
|
this._initializeDefaults();
|
|
132
145
|
}
|
|
133
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Sets the element's default values.
|
|
149
|
+
* @private
|
|
150
|
+
* @returns {void}
|
|
151
|
+
*/
|
|
134
152
|
_initializeDefaults() {
|
|
135
153
|
this.weekday = "short";
|
|
136
154
|
this.month = "short";
|
|
@@ -144,15 +162,15 @@ class AuroDatetime extends i {
|
|
|
144
162
|
this._warnedLocales = new Set();
|
|
145
163
|
|
|
146
164
|
/**
|
|
147
|
-
* Tracks invalid
|
|
148
|
-
*
|
|
165
|
+
* Tracks invalid `timezone` values this element has already warned
|
|
166
|
+
* about, so the same bad value logs only one warning.
|
|
149
167
|
* @private
|
|
150
168
|
*/
|
|
151
169
|
this._warnedTimeZones = new Set();
|
|
152
170
|
|
|
153
171
|
/**
|
|
154
|
-
* Tracks invalid value inputs already warned about
|
|
155
|
-
*
|
|
172
|
+
* Tracks invalid `value` inputs this element has already warned about,
|
|
173
|
+
* so the same bad value logs only one warning.
|
|
156
174
|
* @private
|
|
157
175
|
*/
|
|
158
176
|
this._warnedValues = new Set();
|
|
@@ -174,13 +192,13 @@ class AuroDatetime extends i {
|
|
|
174
192
|
}
|
|
175
193
|
|
|
176
194
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
195
|
+
* Checks a BCP 47 locale tag and returns its canonical form. Empty or invalid
|
|
196
|
+
* input falls back to "en-US". Each invalid value logs a console warning the
|
|
197
|
+
* first time this element sees it.
|
|
180
198
|
*
|
|
181
199
|
* @private
|
|
182
|
-
* @param {string} input -
|
|
183
|
-
* @returns {string}
|
|
200
|
+
* @param {string} input - The locale tag set on the element.
|
|
201
|
+
* @returns {string} The canonical locale tag, such as "en-GB", or "en-US" for empty or invalid input.
|
|
184
202
|
*/
|
|
185
203
|
_resolveLocale(input) {
|
|
186
204
|
if (!input) {
|
|
@@ -200,121 +218,92 @@ class AuroDatetime extends i {
|
|
|
200
218
|
}
|
|
201
219
|
|
|
202
220
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* specified — i.e. wall-clock display from the input components.
|
|
207
|
-
*
|
|
208
|
-
* Without this guard, a typo like `"US/Pacfic"` would cause
|
|
209
|
-
* `Intl.DateTimeFormat` / `toLocaleString` to throw `RangeError` at
|
|
210
|
-
* render time and crash the component.
|
|
211
|
-
*
|
|
212
|
-
* Note: when `value` is also unset, the wall-clock branch resolves to
|
|
213
|
-
* "today's date in the viewer's machine zone," which is viewer-
|
|
214
|
-
* dependent. This narrow case is the only scenario where two viewers
|
|
215
|
-
* see different output for the same component; the warning surfaces
|
|
216
|
-
* the typo so the developer can fix it.
|
|
221
|
+
* Checks an IANA time zone name. An invalid name logs a console warning
|
|
222
|
+
* the first time this element sees it and returns `undefined`, so the
|
|
223
|
+
* element acts as if `timezone` isn't set.
|
|
217
224
|
*
|
|
218
225
|
* @private
|
|
219
|
-
* @param {string | undefined} input -
|
|
220
|
-
* @returns {string | undefined}
|
|
226
|
+
* @param {string | undefined} input - The time zone name set on the element.
|
|
227
|
+
* @returns {string | undefined} The time zone name if it's valid; otherwise, `undefined`.
|
|
221
228
|
*/
|
|
222
229
|
_resolveTimeZone(input) {
|
|
223
230
|
if (!input) {
|
|
224
231
|
return undefined;
|
|
225
232
|
}
|
|
226
233
|
try {
|
|
227
|
-
//
|
|
228
|
-
//
|
|
234
|
+
// Creating the formatter is enough to catch an invalid name. Without
|
|
235
|
+
// this check, a typo such as "America/Los_Angles" makes
|
|
236
|
+
// Intl.DateTimeFormat and toLocaleString throw a RangeError at render
|
|
237
|
+
// time.
|
|
229
238
|
new Intl.DateTimeFormat(undefined, { timeZone: input });
|
|
230
239
|
return input;
|
|
231
240
|
} catch {
|
|
232
241
|
if (this._warnedTimeZones && !this._warnedTimeZones.has(input)) {
|
|
233
242
|
this._warnedTimeZones.add(input);
|
|
234
243
|
console.warn(
|
|
235
|
-
`auro-datetime: "${input}" is not a valid IANA timezone.
|
|
244
|
+
`auro-datetime: "${input}" is not a valid IANA timezone. Ignoring it.`,
|
|
236
245
|
);
|
|
237
246
|
}
|
|
238
247
|
return undefined;
|
|
239
248
|
}
|
|
240
249
|
}
|
|
241
250
|
|
|
242
|
-
connectedCallback() {
|
|
243
|
-
super.connectedCallback();
|
|
244
|
-
|
|
245
|
-
this.dateTemplate = {
|
|
246
|
-
weekday: this.weekday,
|
|
247
|
-
year: "numeric",
|
|
248
|
-
month: this.month,
|
|
249
|
-
day: "numeric",
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
this.timeTemplate = {
|
|
253
|
-
hour: "2-digit",
|
|
254
|
-
minute: "2-digit",
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// function to define props used within the scope of this component
|
|
259
251
|
static get properties() {
|
|
260
252
|
return {
|
|
261
|
-
// ...super.properties,
|
|
262
|
-
|
|
263
253
|
/**
|
|
264
|
-
*
|
|
254
|
+
* Sets the language and region used to format the date or time, such as `en-GB`, `de-DE`, or `ja-JP` (a BCP 47 language tag). It changes month and weekday names, separators, and whether times use a 12- or 24-hour clock, but not the time zone. A malformed tag logs a console warning and falls back to `en-US`; a well-formed tag the browser doesn't support, such as `zz-ZZ`, uses the browser's default language instead, with no warning.
|
|
265
255
|
* @type {string}
|
|
266
|
-
* @default
|
|
256
|
+
* @default "en-US"
|
|
257
|
+
* @category ui
|
|
267
258
|
*/
|
|
268
259
|
locale: { type: String },
|
|
269
260
|
|
|
270
261
|
/**
|
|
271
|
-
*
|
|
272
|
-
* @type {
|
|
273
|
-
* @default
|
|
262
|
+
* Sets how the month name is written: `short`, such as "Jul", or `long`, such as "July". It applies to the full date and to `type="month"`.
|
|
263
|
+
* @type {"short" | "long"}
|
|
264
|
+
* @default "short"
|
|
265
|
+
* @category ui
|
|
274
266
|
*/
|
|
275
267
|
month: { type: String },
|
|
276
268
|
|
|
277
269
|
/**
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
270
|
+
* Sets the time zone to show the date or time in, such as `America/Los_Angeles` or `UTC` (an IANA time zone name). When `value` has an offset or `Z`, the element converts that moment into this zone; when it has none, the element reads `value` as a time already in this zone. Without it, or with an invalid name, which logs a console warning, the element shows the date and time in `value` as written, or the current date and time in the viewer's own time zone when `value` isn't set.
|
|
271
|
+
* @type {string}
|
|
272
|
+
* @category behavior
|
|
281
273
|
*/
|
|
282
274
|
timezone: { type: String },
|
|
283
275
|
|
|
284
276
|
/**
|
|
285
|
-
*
|
|
286
|
-
* @type {
|
|
277
|
+
* Sets which part of the date or time to show: `date` for the full date, such as "Thu, Jul 14, 2022", `numeric` for a numeric date, such as "7/14/2022", `time` for the hour and minute, such as "8:00 am", or `year`, `month`, `weekday`, or `day` for that part alone. Without it, or with any other value, the element shows the full date.
|
|
278
|
+
* @type {"date" | "time" | "year" | "month" | "weekday" | "day" | "numeric"}
|
|
279
|
+
* @category ui
|
|
287
280
|
*/
|
|
288
281
|
type: { type: String },
|
|
289
282
|
|
|
290
283
|
/**
|
|
291
|
-
* ISO 8601 date or date-time
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* - `2022-07-14T08:00:00` (no offset)
|
|
295
|
-
* - `2022-07-14` (date only)
|
|
296
|
-
*
|
|
297
|
-
* When omitted, the component renders today's date.
|
|
298
|
-
* Invalid input is logged as a warning and renders nothing.
|
|
284
|
+
* Sets the date or time to show, as an ISO 8601 date or date-time, such as `2022-07-14`, `2022-07-14T08:00:00`, or `2022-07-14T08:00:00-07:00`. Without it, the element shows the current date and time from when it last rendered; it doesn't currently update as time passes. Invalid input, including an empty value, logs a console warning and shows nothing.
|
|
285
|
+
* @type {string}
|
|
286
|
+
* @category behavior
|
|
299
287
|
*/
|
|
300
288
|
value: { type: String },
|
|
301
289
|
|
|
302
290
|
/**
|
|
303
|
-
*
|
|
304
|
-
* @type {
|
|
305
|
-
* @default
|
|
291
|
+
* Sets how the weekday name is written: `short`, such as "Thu", or `long`, such as "Thursday". It applies to the full date and to `type="weekday"`.
|
|
292
|
+
* @type {"short" | "long"}
|
|
293
|
+
* @default "short"
|
|
294
|
+
* @category ui
|
|
306
295
|
*/
|
|
307
296
|
weekday: { type: String },
|
|
308
297
|
};
|
|
309
298
|
}
|
|
310
299
|
|
|
311
300
|
/**
|
|
312
|
-
*
|
|
313
|
-
* @param {string} [name="auro-datetime"] - The name
|
|
301
|
+
* Registers the element with the browser under a tag name. Use a custom name to run more than one version of the element on the same page. If the tag name is already registered, it does nothing.
|
|
302
|
+
* @param {string} [name="auro-datetime"] - The tag name to register the element under, such as `custom-datetime`.
|
|
303
|
+
* @returns {void}
|
|
314
304
|
*
|
|
315
305
|
* @example
|
|
316
|
-
* AuroDatetime.register("custom-datetime") //
|
|
317
|
-
*
|
|
306
|
+
* AuroDatetime.register("custom-datetime"); // registers <custom-datetime>
|
|
318
307
|
*/
|
|
319
308
|
static register(name = "auro-datetime") {
|
|
320
309
|
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroDatetime);
|
|
@@ -330,24 +319,24 @@ class AuroDatetime extends i {
|
|
|
330
319
|
}
|
|
331
320
|
|
|
332
321
|
firstUpdated() {
|
|
333
|
-
//
|
|
322
|
+
// Adds the tag name as an attribute when it differs from auro-datetime.
|
|
334
323
|
this.runtimeUtils.handleComponentTagRename(this, "auro-datetime");
|
|
335
324
|
}
|
|
336
325
|
|
|
337
326
|
/**
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
* offset
|
|
341
|
-
* in
|
|
327
|
+
* Creates a Date that shows the given wall-clock time when displayed in
|
|
328
|
+
* the given IANA time zone. `_resolveInputDate` uses it when `value` has
|
|
329
|
+
* no offset and `timezone` is set, so the time is read as already being
|
|
330
|
+
* in that zone rather than the viewer's.
|
|
342
331
|
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
332
|
+
* It parses the wall-clock time as if it were UTC, asks `Intl` what that
|
|
333
|
+
* moment looks like in the target zone, and uses the difference between
|
|
334
|
+
* the two to find the real moment.
|
|
346
335
|
*
|
|
347
336
|
* @private
|
|
348
|
-
* @param {string} localISO - ISO
|
|
349
|
-
* @param {string} timeZone - IANA zone,
|
|
350
|
-
* @returns {Date}
|
|
337
|
+
* @param {string} localISO - The ISO 8601 date-time with no offset, such as "2022-07-14T08:00:00".
|
|
338
|
+
* @param {string} timeZone - The IANA time zone name, such as "America/New_York".
|
|
339
|
+
* @returns {Date} The moment that reads as `localISO` in `timeZone`.
|
|
351
340
|
*/
|
|
352
341
|
_zonedWallClockToUtc(localISO, timeZone) {
|
|
353
342
|
const naiveUtc = new Date(`${localISO}Z`);
|
|
@@ -372,34 +361,33 @@ class AuroDatetime extends i {
|
|
|
372
361
|
}
|
|
373
362
|
|
|
374
363
|
/**
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* Behavior:
|
|
379
|
-
* - `value` omitted (null/undefined): returns today's date. `timezone`
|
|
380
|
-
* (if any) is honored.
|
|
381
|
-
* - `value` invalid (including empty string ""): warns and returns
|
|
382
|
-
* `{ date: null }`. Empty is *not* the same as omitted — Lit reflects
|
|
383
|
-
* `value=""` as the empty string, which is not a valid ISO 8601
|
|
384
|
-
* form, so we surface it as a typo rather than silently rendering
|
|
385
|
-
* today's date.
|
|
386
|
-
* - `timezone` set + input has offset/Z: parses as an absolute moment
|
|
387
|
-
* (offset honored) and asks `toLocaleString` to convert into the target zone.
|
|
388
|
-
* - `timezone` set + input has no offset: interprets the wall-clock as
|
|
389
|
-
* being in the target zone, so display in that zone matches the input
|
|
390
|
-
* verbatim. This is viewer-independent.
|
|
391
|
-
* - Default (no `timezone`): strips the offset/Z from the input and treats
|
|
392
|
-
* the remaining wall-clock components as local time, so they render verbatim.
|
|
364
|
+
* Gets the Date to show and the `timeZone` option for `Intl.DateTimeFormat`,
|
|
365
|
+
* from `value` and `timezone`. Returns `{ date: null }` for invalid input,
|
|
366
|
+
* including an empty string.
|
|
393
367
|
*
|
|
394
368
|
* @private
|
|
395
|
-
* @returns {{ date: Date | null, timeZoneOption: string | undefined }}
|
|
369
|
+
* @returns {{ date: Date | null, timeZoneOption: string | undefined }} The Date to show, or `null` for invalid input, and the `timeZone` option to format it with.
|
|
396
370
|
*/
|
|
397
371
|
_resolveInputDate() {
|
|
372
|
+
// How each case resolves:
|
|
373
|
+
// - `value` not set (null or undefined): the current date and time, in
|
|
374
|
+
// `timezone` if it's set.
|
|
375
|
+
// - `value` invalid, including an empty string: logs a warning and
|
|
376
|
+
// returns { date: null }. An empty string isn't the same as not set:
|
|
377
|
+
// Lit gives value="" as an empty string, which isn't valid ISO 8601,
|
|
378
|
+
// so it's reported as a likely mistake instead of showing the
|
|
379
|
+
// current date.
|
|
380
|
+
// - `timezone` set and `value` has an offset or Z: reads `value` as an
|
|
381
|
+
// exact moment and has toLocaleString convert it into `timezone`.
|
|
382
|
+
// - `timezone` set and `value` has no offset: reads `value` as a time
|
|
383
|
+
// already in `timezone`, so every viewer sees it as written.
|
|
384
|
+
// - `timezone` not set: drops any offset or Z and reads the rest as
|
|
385
|
+
// local time, so it shows as written.
|
|
398
386
|
const resolvedTz = this._effectiveTimeZone;
|
|
399
387
|
|
|
400
|
-
// Only true "omitted" inputs (null/undefined) get the
|
|
401
|
-
// treatment. Empty string falls through to ISO validation, which
|
|
402
|
-
//
|
|
388
|
+
// Only true "omitted" inputs (null/undefined) get the current-date
|
|
389
|
+
// treatment. Empty string falls through to ISO validation, which
|
|
390
|
+
// fails and produces the documented warning and empty output.
|
|
403
391
|
if (this.value == null) {
|
|
404
392
|
return { date: new Date(), timeZoneOption: resolvedTz };
|
|
405
393
|
}
|
|
@@ -418,9 +406,9 @@ class AuroDatetime extends i {
|
|
|
418
406
|
const localPart = match[1];
|
|
419
407
|
const hasOffset = Boolean(match[2]);
|
|
420
408
|
|
|
421
|
-
// The regex permits an offset/Z suffix on a bare date (
|
|
422
|
-
// or "2020-09-22-07:00"). Those forms are not valid ISO 8601
|
|
423
|
-
// is only meaningful with a time component
|
|
409
|
+
// The regex permits an offset/Z suffix on a bare date (such as "2020-09-22Z"
|
|
410
|
+
// or "2020-09-22-07:00"). Those forms are not valid ISO 8601: an offset
|
|
411
|
+
// is only meaningful with a time component, and the wall-clock branch
|
|
424
412
|
// would silently drop the offset, producing surprising output. Reject
|
|
425
413
|
// them up front so the consumer sees a warning.
|
|
426
414
|
if (hasOffset && !localPart.includes("T")) {
|
|
@@ -437,7 +425,7 @@ class AuroDatetime extends i {
|
|
|
437
425
|
? localPart
|
|
438
426
|
: `${localPart}T00:00:00`;
|
|
439
427
|
|
|
440
|
-
// The regex only validates string shape, not value ranges
|
|
428
|
+
// The regex only validates string shape, not value ranges: "2022-99-99"
|
|
441
429
|
// matches but produces an Invalid Date. Detect that and treat it like
|
|
442
430
|
// any other malformed input so render falls back to the documented
|
|
443
431
|
// empty output instead of "Invalid Date" or a thrown RangeError from
|
|
@@ -470,16 +458,22 @@ class AuroDatetime extends i {
|
|
|
470
458
|
}
|
|
471
459
|
|
|
472
460
|
/**
|
|
473
|
-
*
|
|
461
|
+
* Formats the full date, such as "Thu, Jul 14, 2022", with the current `month` and `weekday` settings.
|
|
474
462
|
* @private
|
|
475
|
-
* @returns {string}
|
|
463
|
+
* @returns {string} The formatted date, or an empty string when `value` is invalid.
|
|
476
464
|
*/
|
|
477
465
|
humanDate() {
|
|
478
466
|
const { date, timeZoneOption } = this._resolveInputDate();
|
|
479
467
|
if (!date) {
|
|
480
468
|
return "";
|
|
481
469
|
}
|
|
482
|
-
|
|
470
|
+
// Read month and weekday on every render so later changes show up.
|
|
471
|
+
const template = {
|
|
472
|
+
weekday: this.weekday || "short",
|
|
473
|
+
year: "numeric",
|
|
474
|
+
month: this.month || "short",
|
|
475
|
+
day: "numeric",
|
|
476
|
+
};
|
|
483
477
|
if (timeZoneOption) {
|
|
484
478
|
template.timeZone = timeZoneOption;
|
|
485
479
|
}
|
|
@@ -487,9 +481,9 @@ class AuroDatetime extends i {
|
|
|
487
481
|
}
|
|
488
482
|
|
|
489
483
|
/**
|
|
490
|
-
*
|
|
484
|
+
* Formats the single date part that `type` names: the year, month, weekday, or day.
|
|
491
485
|
* @private
|
|
492
|
-
* @returns {string}
|
|
486
|
+
* @returns {string} The formatted date, or an empty string when `value` is invalid.
|
|
493
487
|
*/
|
|
494
488
|
humanDateConversion() {
|
|
495
489
|
const { date, timeZoneOption } = this._resolveInputDate();
|
|
@@ -506,13 +500,13 @@ class AuroDatetime extends i {
|
|
|
506
500
|
template.day = "numeric";
|
|
507
501
|
break;
|
|
508
502
|
case "month":
|
|
509
|
-
template.month = this.month;
|
|
503
|
+
template.month = this.month || "short";
|
|
510
504
|
break;
|
|
511
505
|
case "year":
|
|
512
506
|
template.year = "numeric";
|
|
513
507
|
break;
|
|
514
508
|
case "weekday":
|
|
515
|
-
template.weekday = this.weekday;
|
|
509
|
+
template.weekday = this.weekday || "short";
|
|
516
510
|
break;
|
|
517
511
|
}
|
|
518
512
|
|
|
@@ -520,17 +514,16 @@ class AuroDatetime extends i {
|
|
|
520
514
|
}
|
|
521
515
|
|
|
522
516
|
/**
|
|
523
|
-
*
|
|
517
|
+
* Formats the date in numbers, in the order and with the separators `locale` uses, such as "7/14/2022" for `en-US`.
|
|
524
518
|
* @private
|
|
525
|
-
* @returns {string}
|
|
519
|
+
* @returns {string} The formatted date, or an empty string when `value` is invalid.
|
|
526
520
|
*/
|
|
527
521
|
numericDate() {
|
|
528
522
|
const { date, timeZoneOption } = this._resolveInputDate();
|
|
529
523
|
if (!date) {
|
|
530
524
|
return "";
|
|
531
525
|
}
|
|
532
|
-
const template = {
|
|
533
|
-
Reflect.deleteProperty(template, "weekday");
|
|
526
|
+
const template = { year: "numeric", month: "numeric", day: "numeric" };
|
|
534
527
|
if (timeZoneOption) {
|
|
535
528
|
template.timeZone = timeZoneOption;
|
|
536
529
|
}
|
|
@@ -538,16 +531,16 @@ class AuroDatetime extends i {
|
|
|
538
531
|
}
|
|
539
532
|
|
|
540
533
|
/**
|
|
541
|
-
*
|
|
534
|
+
* Formats the hour and minute. When the time ends in AM or PM, it lowercases the period and drops a leading zero.
|
|
542
535
|
* @private
|
|
543
|
-
* @returns {string}
|
|
536
|
+
* @returns {string} The formatted time, or an empty string when `value` is invalid.
|
|
544
537
|
*/
|
|
545
538
|
humanTime() {
|
|
546
539
|
const { date, timeZoneOption } = this._resolveInputDate();
|
|
547
540
|
if (!date) {
|
|
548
541
|
return "";
|
|
549
542
|
}
|
|
550
|
-
const template = {
|
|
543
|
+
const template = { hour: "2-digit", minute: "2-digit" };
|
|
551
544
|
if (timeZoneOption) {
|
|
552
545
|
template.timeZone = timeZoneOption;
|
|
553
546
|
}
|
|
@@ -559,8 +552,8 @@ class AuroDatetime extends i {
|
|
|
559
552
|
// (case-insensitive), so it catches en-US (`PM`), en-AU/hi-IN (`pm`),
|
|
560
553
|
// and en-CA/es-MX (`p.m.`) alike. Non-Latin period markers (ko `오후`,
|
|
561
554
|
// ar `م`, zh-TW `下午`) have no ASCII a/p+m chars and correctly fall
|
|
562
|
-
// through unchanged. 24h locales (en-GB, de-DE, fr-FR, ja-JP
|
|
563
|
-
// fall through, preserving their leading zeros.
|
|
555
|
+
// through unchanged. 24h locales (en-GB, de-DE, fr-FR, ja-JP, and
|
|
556
|
+
// others) also fall through, preserving their leading zeros.
|
|
564
557
|
if (!/[ap]\.?m\.?/iu.test(formatted)) {
|
|
565
558
|
return formatted;
|
|
566
559
|
}
|
|
@@ -569,9 +562,9 @@ class AuroDatetime extends i {
|
|
|
569
562
|
}
|
|
570
563
|
|
|
571
564
|
/**
|
|
572
|
-
*
|
|
565
|
+
* Gets the text to show for the current `type`.
|
|
573
566
|
* @private
|
|
574
|
-
* @returns {string}
|
|
567
|
+
* @returns {string} The formatted text; the full date when `type` isn't set or isn't recognized.
|
|
575
568
|
*/
|
|
576
569
|
whichDate() {
|
|
577
570
|
switch (this.type) {
|
|
@@ -591,10 +584,6 @@ class AuroDatetime extends i {
|
|
|
591
584
|
}
|
|
592
585
|
}
|
|
593
586
|
|
|
594
|
-
// When using auroElement, use the following attribute and function when hiding content from screen readers.
|
|
595
|
-
// aria-hidden="${this.hideAudible(this.hiddenAudible)}"
|
|
596
|
-
|
|
597
|
-
// function that renders the HTML and CSS into the scope of the component
|
|
598
587
|
render() {
|
|
599
588
|
return b`
|
|
600
589
|
<slot name="pre"></slot>
|
package/demo/index.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
THIS PAGE'S CONTENT SHOULD BE KEPT MINIMAL.
|
|
3
|
-
ONLY ADD EXAMPLES THAT ARE TRULY NECESSARY FOR THE INDEX PAGE
|
|
3
|
+
ONLY ADD EXAMPLES THAT ARE TRULY NECESSARY FOR THE INDEX PAGE. THE BASIC EXAMPLE IS USUALLY ENOUGH.
|
|
4
4
|
ALL OTHER EXAMPLES SHOULD GO IN THE API DOCUMENTATION.
|
|
5
5
|
-->
|
|
6
6
|
|
|
@@ -8,19 +8,23 @@
|
|
|
8
8
|
|
|
9
9
|
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/description.md) -->
|
|
10
10
|
<!-- The below content is automatically added from ./../docs/partials/description.md -->
|
|
11
|
-
The `<auro-datetime>`
|
|
11
|
+
The `<auro-datetime>` element shows a date or time as text, formatted for a language and region you choose and, optionally, a specific time zone. Set `type` to choose the full date, the time, a numeric date, or a single part, such as the weekday.
|
|
12
12
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
13
13
|
|
|
14
|
-
## Use
|
|
14
|
+
## Use cases
|
|
15
15
|
|
|
16
16
|
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../docs/partials/useCases.md) -->
|
|
17
17
|
<!-- The below content is automatically added from ./../docs/partials/useCases.md -->
|
|
18
|
-
|
|
18
|
+
Use `<auro-datetime>` to:
|
|
19
19
|
|
|
20
|
-
*
|
|
20
|
+
* Show a date or time, such as a departure date or arrival time.
|
|
21
|
+
* Show a time in a specific time zone, such as a flight's local time at its airport.
|
|
22
|
+
* Format a date for a language and region, such as `de-DE` or `ja-JP`.
|
|
21
23
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
22
24
|
|
|
23
|
-
##
|
|
25
|
+
## Examples
|
|
26
|
+
|
|
27
|
+
### Basic
|
|
24
28
|
|
|
25
29
|
<div class="exampleWrapper">
|
|
26
30
|
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../apiExamples/basic.html) -->
|
|
@@ -33,11 +37,11 @@ The `<auro-datetime>` element should be used in situations where users may:
|
|
|
33
37
|
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../apiExamples/basic.html) -->
|
|
34
38
|
<!-- The below code snippet is automatically added from ./../apiExamples/basic.html -->
|
|
35
39
|
|
|
36
|
-
<pre class="language-html"><code class="language-html"><auro-datetime type="date"></auro-datetime></code></pre>
|
|
40
|
+
<pre class="language-html"><code class="language-html"><auro-datetime type="date"></auro-datetime></code></pre>
|
|
37
41
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
38
42
|
</auro-accordion>
|
|
39
43
|
|
|
40
|
-
|
|
44
|
+
### Time
|
|
41
45
|
|
|
42
46
|
<div class="exampleWrapper">
|
|
43
47
|
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../apiExamples/basic-time.html) -->
|
|
@@ -50,7 +54,6 @@ The `<auro-datetime>` element should be used in situations where users may:
|
|
|
50
54
|
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../apiExamples/basic-time.html) -->
|
|
51
55
|
<!-- The below code snippet is automatically added from ./../apiExamples/basic-time.html -->
|
|
52
56
|
|
|
53
|
-
<pre class="language-html"><code class="language-html"><auro-datetime type="time"></auro-datetime></code></pre>
|
|
57
|
+
<pre class="language-html"><code class="language-html"><auro-datetime type="time"></auro-datetime></code></pre>
|
|
54
58
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
55
|
-
</auro-accordion>
|
|
56
|
-
|
|
59
|
+
</auro-accordion>
|