@aurodesignsystem-dev/auro-datetime 0.0.0-pr82.8 → 0.0.0-pr82.9
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/demo/api.md +9 -9
- package/demo/auro-datetime.min.js +17 -9
- package/dist/auro-datetime-39FU0ZIU.js +6 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/registered.js +1 -1
- package/package.json +1 -1
- package/dist/auro-datetime-KR9bjDcR.js +0 -6
package/demo/api.md
CHANGED
|
@@ -11,7 +11,7 @@ The `auro-datetime` element is for the purposes of providing an easy to use date
|
|
|
11
11
|
| ---------- | ---------- | --------- | ------------------------------------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
12
12
|
| locale | locale | | string | `en-US` | BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP'). |
|
|
13
13
|
| month | month | | `short` \| `long` | `short` | Defines format of month |
|
|
14
|
-
|
|
|
14
|
+
| timezone | timezone | | string | | Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).<br>When set, the moment described by `value` is converted into this IANA zone for display.<br>When unset, the wall-clock time from the input string is rendered as-is. |
|
|
15
15
|
| type | type | | `date` \| `time` \| `year` \| `month` \| `weekday` \| `day` \| `numeric` | | Defines type of data to render |
|
|
16
16
|
| value | value | | string | | ISO 8601 date or date-time string. Examples:<br>- `2022-07-14T08:00:00-07:00` (with offset)<br>- `2022-07-14T08:00:00Z` (UTC)<br>- `2022-07-14T08:00:00` (no offset)<br>- `2022-07-14` (date only)<br><br>When omitted, the component renders today's date.<br>Invalid input is logged as a warning and renders nothing. |
|
|
17
17
|
| weekday | weekday | | `short` \| `long` | `short` | Defines format of weekday |
|
|
@@ -229,7 +229,7 @@ Using the `auro-datetime` element with `type=numeric` will return the **current
|
|
|
229
229
|
|
|
230
230
|
#### Wall-clock display from offset
|
|
231
231
|
|
|
232
|
-
When the `value` attribute contains a timezone offset (or `Z`) and no `
|
|
232
|
+
When the `value` attribute contains a timezone offset (or `Z`) and no `timezone` attribute is set, the component renders the **wall-clock** components from the input verbatim. This is the right behavior for displaying local airport time on a flight schedule, where the offset describes the location of the flight rather than the viewer.
|
|
233
233
|
|
|
234
234
|
Example using `2022-07-13T21:35:00-07:00`. The same string is rendered identically regardless of the viewer's location.
|
|
235
235
|
|
|
@@ -254,7 +254,7 @@ Example using `2022-07-13T21:35:00-07:00`. The same string is rendered identical
|
|
|
254
254
|
|
|
255
255
|
### UTC (Zulu) input
|
|
256
256
|
|
|
257
|
-
The `value` attribute also accepts ISO 8601 strings ending in the `Z` designator. Without a `
|
|
257
|
+
The `value` attribute also accepts ISO 8601 strings ending in the `Z` designator. Without a `timezone` attribute, the wall-clock components are rendered as written. To convert into a viewer-meaningful timezone, also set `timezone` (see the timezone example).
|
|
258
258
|
|
|
259
259
|
<div class="exampleWrapper">
|
|
260
260
|
<!-- AURO-GENERATED-CONTENT:START (FILE:src=../apiExamples/utc.html) -->
|
|
@@ -277,19 +277,19 @@ The `value` attribute also accepts ISO 8601 strings ending in the `Z` designator
|
|
|
277
277
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
278
278
|
</auro-accordion>
|
|
279
279
|
|
|
280
|
-
### Combining `value` and `
|
|
280
|
+
### Combining `value` and `timezone`
|
|
281
281
|
|
|
282
|
-
How the `
|
|
282
|
+
How the `timezone` attribute composes with the input depends on whether `value` carries an offset:
|
|
283
283
|
|
|
284
|
-
- **`value` has an offset (or `Z`):** the offset anchors the absolute moment; `
|
|
285
|
-
- **`value` has no offset:** the wall-clock is interpreted as being in `
|
|
284
|
+
- **`value` has an offset (or `Z`):** the offset anchors the absolute moment; `timezone` is the display zone. Example: `value="2022-07-14T08:00:00-04:00" timezone="US/Pacific"` renders as `5:00 am` (8am Eastern → 5am Pacific).
|
|
285
|
+
- **`value` has no offset:** the wall-clock is interpreted as being in `timezone`, so display in that same zone matches the input verbatim. Example: `value="2022-07-14T08:00:00" timezone="US/Eastern"` renders as `8:00 am` regardless of where the viewer is. This is the recommended shape when consumers know the source zone but don't have an offset readily available (e.g. flight-schedule data keyed by airport).
|
|
286
286
|
|
|
287
|
-
#### Invalid `
|
|
287
|
+
#### Invalid `timezone` and `locale` values
|
|
288
288
|
|
|
289
289
|
Both attributes are validated up-front. Invalid inputs do **not** crash the component — they fall back gracefully and log a `console.warn` (deduplicated per element):
|
|
290
290
|
|
|
291
291
|
- **Invalid `locale`** (e.g. `"xx-INVALID-tag"`) → falls back to `"en-US"`.
|
|
292
|
-
- **Invalid `
|
|
292
|
+
- **Invalid `timezone`** (e.g. `"US/Pacfic"` typo) → falls back to behaving as if `timezone` was not specified. With `value` set, that means wall-clock display from the input components — visually the same string for every viewer. With `value` unset, that means the current time in the viewer's machine zone. The warning surfaces the typo so the developer can fix it.
|
|
293
293
|
|
|
294
294
|
## Slot Examples
|
|
295
295
|
|
|
@@ -162,6 +162,11 @@ class AuroDatetime extends i {
|
|
|
162
162
|
*/
|
|
163
163
|
this._effectiveLocale = this._resolveLocale(this.locale);
|
|
164
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
this._effectiveTimeZone = this._resolveTimeZone(this.timezone);
|
|
169
|
+
|
|
165
170
|
/**
|
|
166
171
|
* @private
|
|
167
172
|
*/
|
|
@@ -197,7 +202,7 @@ class AuroDatetime extends i {
|
|
|
197
202
|
/**
|
|
198
203
|
* Validate an IANA timezone identifier. Invalid input warns once per
|
|
199
204
|
* unique value per element and resolves to `undefined`, which makes
|
|
200
|
-
* the rest of `_resolveInputDate` behave as if `
|
|
205
|
+
* the rest of `_resolveInputDate` behave as if `timezone` was never
|
|
201
206
|
* specified — i.e. wall-clock display from the input components.
|
|
202
207
|
*
|
|
203
208
|
* Without this guard, a typo like `"US/Pacfic"` would cause
|
|
@@ -270,11 +275,11 @@ class AuroDatetime extends i {
|
|
|
270
275
|
month: { type: String },
|
|
271
276
|
|
|
272
277
|
/**
|
|
273
|
-
* Pass in string to define [
|
|
278
|
+
* Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
274
279
|
* When set, the moment described by `value` is converted into this IANA zone for display.
|
|
275
280
|
* When unset, the wall-clock time from the input string is rendered as-is.
|
|
276
281
|
*/
|
|
277
|
-
|
|
282
|
+
timezone: { type: String },
|
|
278
283
|
|
|
279
284
|
/**
|
|
280
285
|
* Defines type of data to render
|
|
@@ -319,6 +324,9 @@ class AuroDatetime extends i {
|
|
|
319
324
|
if (changedProperties.has("locale")) {
|
|
320
325
|
this._effectiveLocale = this._resolveLocale(this.locale);
|
|
321
326
|
}
|
|
327
|
+
if (changedProperties.has("timezone")) {
|
|
328
|
+
this._effectiveTimeZone = this._resolveTimeZone(this.timezone);
|
|
329
|
+
}
|
|
322
330
|
}
|
|
323
331
|
|
|
324
332
|
firstUpdated() {
|
|
@@ -364,30 +372,30 @@ class AuroDatetime extends i {
|
|
|
364
372
|
}
|
|
365
373
|
|
|
366
374
|
/**
|
|
367
|
-
* Resolve the `value` and `
|
|
375
|
+
* Resolve the `value` and `timezone` attributes into a Date and an optional
|
|
368
376
|
* timeZone option for `Intl.DateTimeFormat`.
|
|
369
377
|
*
|
|
370
378
|
* Behavior:
|
|
371
|
-
* - `value` omitted (null/undefined): returns today's date. `
|
|
379
|
+
* - `value` omitted (null/undefined): returns today's date. `timezone`
|
|
372
380
|
* (if any) is honored.
|
|
373
381
|
* - `value` invalid (including empty string ""): warns and returns
|
|
374
382
|
* `{ date: null }`. Empty is *not* the same as omitted — Lit reflects
|
|
375
383
|
* `value=""` as the empty string, which is not a valid ISO 8601
|
|
376
384
|
* form, so we surface it as a typo rather than silently rendering
|
|
377
385
|
* today's date.
|
|
378
|
-
* - `
|
|
386
|
+
* - `timezone` set + input has offset/Z: parses as an absolute moment
|
|
379
387
|
* (offset honored) and asks `toLocaleString` to convert into the target zone.
|
|
380
|
-
* - `
|
|
388
|
+
* - `timezone` set + input has no offset: interprets the wall-clock as
|
|
381
389
|
* being in the target zone, so display in that zone matches the input
|
|
382
390
|
* verbatim. This is viewer-independent.
|
|
383
|
-
* - Default (no `
|
|
391
|
+
* - Default (no `timezone`): strips the offset/Z from the input and treats
|
|
384
392
|
* the remaining wall-clock components as local time, so they render verbatim.
|
|
385
393
|
*
|
|
386
394
|
* @private
|
|
387
395
|
* @returns {{ date: Date | null, timeZoneOption: string | undefined }}
|
|
388
396
|
*/
|
|
389
397
|
_resolveInputDate() {
|
|
390
|
-
const resolvedTz = this.
|
|
398
|
+
const resolvedTz = this._effectiveTimeZone;
|
|
391
399
|
|
|
392
400
|
// Only true "omitted" inputs (null/undefined) get the today's-date
|
|
393
401
|
// treatment. Empty string falls through to ISO validation, which will
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{LitElement as e,html as t}from"lit";class i{registerComponent(e,t){customElements.get(e)||customElements.define(e,class extends t{})}closestElement(e,t=this,i=(t,a=t&&t.closest(e))=>t&&t!==document&&t!==window?a||i(t.getRootNode().host):null){return i(t)}handleComponentTagRename(e,t){const i=t.toLowerCase();e.tagName.toLowerCase()!==i&&e.setAttribute(i,!0)}elementMatch(e,t){const i=t.toLowerCase();return e.tagName.toLowerCase()===i||e.hasAttribute(i)}getSlotText(e,t){const i=e.shadowRoot?.querySelector(`slot[name="${t}"]`);return(i?.assignedNodes({flatten:!0})||[]).map(e=>e.textContent?.trim()).join(" ").trim()||null}}const a=/^(\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?)(Z|[+-]\d{2}:\d{2})?$/u;class n extends e{constructor(){super(),this._initializeDefaults()}_initializeDefaults(){this.weekday="short",this.month="short",this.locale="en-US",this._warnedLocales=new Set,this._warnedTimeZones=new Set,this._warnedValues=new Set,this._effectiveLocale=this._resolveLocale(this.locale),this._effectiveTimeZone=this._resolveTimeZone(this.timezone),this.runtimeUtils=new i}_resolveLocale(e){if(!e)return"en-US";try{return Intl.getCanonicalLocales(e)[0]}catch{return this._warnedLocales&&!this._warnedLocales.has(e)&&(this._warnedLocales.add(e),console.warn(`auro-datetime: "${e}" is not a valid BCP 47 locale tag. Falling back to "en-US".`)),"en-US"}}_resolveTimeZone(e){if(e)try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),e}catch{return void(this._warnedTimeZones&&!this._warnedTimeZones.has(e)&&(this._warnedTimeZones.add(e),console.warn(`auro-datetime: "${e}" is not a valid IANA timezone. Falling back to viewer-local.`)))}}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit"}}static get properties(){return{locale:{type:String},month:{type:String},timezone:{type:String},type:{type:String},value:{type:String},weekday:{type:String}}}static register(e="auro-datetime"){i.prototype.registerComponent(e,n)}willUpdate(e){e.has("locale")&&(this._effectiveLocale=this._resolveLocale(this.locale)),e.has("timezone")&&(this._effectiveTimeZone=this._resolveTimeZone(this.timezone))}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}_zonedWallClockToUtc(e,t){const i=new Date(`${e}Z`),a=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(i),n=Object.fromEntries(a.filter(e=>"literal"!==e.type).map(e=>[e.type,e.value])),o=new Date(`${n.year}-${n.month}-${n.day}T${n.hour}:${n.minute}:${n.second}Z`),s=i.getTime()-o.getTime();return new Date(i.getTime()+s)}_resolveInputDate(){const e=this._effectiveTimeZone;if(null==this.value)return{date:new Date,timeZoneOption:e};const t=this.value.match(a);if(!t)return this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 string.`)),{date:null,timeZoneOption:void 0};const i=t[1],n=Boolean(t[2]);if(n&&!i.includes("T"))return this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 string (offset/Z requires a time component).`)),{date:null,timeZoneOption:void 0};const o=i.includes("T")?i:`${i}T00:00:00`,s=(()=>e&&!n?this._zonedWallClockToUtc(o,e):e&&n?new Date(this.value):new Date(o))();return Number.isNaN(s.getTime())?(this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 date.`)),{date:null,timeZoneOption:void 0}):{date:s,timeZoneOption:e}}humanDate(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const i={...this.dateTemplate};return t&&(i.timeZone=t),e.toLocaleString(this._effectiveLocale,i)}humanDateConversion(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const i={};switch(t&&(i.timeZone=t),this.type){case"day":i.day="numeric";break;case"month":i.month=this.month;break;case"year":i.year="numeric";break;case"weekday":i.weekday=this.weekday}return e.toLocaleString(this._effectiveLocale,i)}numericDate(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const i={...this.dateTemplate,month:"numeric"};return Reflect.deleteProperty(i,"weekday"),t&&(i.timeZone=t),e.toLocaleString(this._effectiveLocale,i)}humanTime(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const i={...this.timeTemplate};t&&(i.timeZone=t);const a=e.toLocaleString(this._effectiveLocale,i);return/[ap]\.?m\.?/iu.test(a)?a.replace(/^0+/u,"").toLowerCase():a}whichDate(){switch(this.type){case"date":default:return this.humanDate();case"time":return this.humanTime();case"year":case"month":case"weekday":case"day":return this.humanDateConversion();case"numeric":return this.numericDate()}}render(){return t`
|
|
2
|
+
<slot name="pre"></slot>
|
|
3
|
+
<span class="yield">${this.whichDate()}</span>
|
|
4
|
+
<slot name="post"></slot>
|
|
5
|
+
<slot></slot>
|
|
6
|
+
`}}export{n as A};
|
package/dist/index.d.ts
CHANGED
|
@@ -77,10 +77,10 @@ export type AuroDatetimeProps = {
|
|
|
77
77
|
locale?: AuroDatetime["locale"];
|
|
78
78
|
/** Defines format of month */
|
|
79
79
|
month?: AuroDatetime["month"];
|
|
80
|
-
/** Pass in string to define [
|
|
80
|
+
/** Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
81
81
|
When set, the moment described by `value` is converted into this IANA zone for display.
|
|
82
82
|
When unset, the wall-clock time from the input string is rendered as-is. */
|
|
83
|
-
|
|
83
|
+
timezone?: AuroDatetime["timezone"];
|
|
84
84
|
/** Defines type of data to render */
|
|
85
85
|
type?: AuroDatetime["type"];
|
|
86
86
|
/** ISO 8601 date or date-time string. Examples:
|
|
@@ -101,10 +101,10 @@ export type AuroDatetimeSolidJsProps = {
|
|
|
101
101
|
"prop:locale"?: AuroDatetime["locale"];
|
|
102
102
|
/** Defines format of month */
|
|
103
103
|
"prop:month"?: AuroDatetime["month"];
|
|
104
|
-
/** Pass in string to define [
|
|
104
|
+
/** Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
105
105
|
When set, the moment described by `value` is converted into this IANA zone for display.
|
|
106
106
|
When unset, the wall-clock time from the input string is rendered as-is. */
|
|
107
|
-
"prop:
|
|
107
|
+
"prop:timezone"?: AuroDatetime["timezone"];
|
|
108
108
|
/** Defines type of data to render */
|
|
109
109
|
"prop:type"?: AuroDatetime["type"];
|
|
110
110
|
/** ISO 8601 date or date-time string. Examples:
|
|
@@ -135,7 +135,7 @@ export type CustomElements = {
|
|
|
135
135
|
*
|
|
136
136
|
* - `locale`: BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
137
137
|
* - `month`: Defines format of month
|
|
138
|
-
* - `
|
|
138
|
+
* - `timezone`: Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
139
139
|
* When set, the moment described by `value` is converted into this IANA zone for display.
|
|
140
140
|
* When unset, the wall-clock time from the input string is rendered as-is.
|
|
141
141
|
* - `type`: Defines type of data to render
|
|
@@ -178,7 +178,7 @@ export type CustomElementsSolidJs = {
|
|
|
178
178
|
*
|
|
179
179
|
* - `locale`: BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
180
180
|
* - `month`: Defines format of month
|
|
181
|
-
* - `
|
|
181
|
+
* - `timezone`: Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
182
182
|
* When set, the moment described by `value` is converted into this IANA zone for display.
|
|
183
183
|
* When unset, the wall-clock time from the input string is rendered as-is.
|
|
184
184
|
* - `type`: Defines type of data to render
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{A as AuroDatetime}from"./auro-datetime-
|
|
1
|
+
export{A as AuroDatetime}from"./auro-datetime-39FU0ZIU.js";import"lit";
|
package/dist/registered.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as r}from"./auro-datetime-
|
|
1
|
+
import{A as r}from"./auro-datetime-39FU0ZIU.js";import"lit";r.register();
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"================================================================================"
|
|
8
8
|
],
|
|
9
9
|
"name": "@aurodesignsystem-dev/auro-datetime",
|
|
10
|
-
"version": "0.0.0-pr82.
|
|
10
|
+
"version": "0.0.0-pr82.9",
|
|
11
11
|
"description": "auro-datetime HTML custom element",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{LitElement as e,html as t}from"lit";class a{registerComponent(e,t){customElements.get(e)||customElements.define(e,class extends t{})}closestElement(e,t=this,a=(t,n=t&&t.closest(e))=>t&&t!==document&&t!==window?n||a(t.getRootNode().host):null){return a(t)}handleComponentTagRename(e,t){const a=t.toLowerCase();e.tagName.toLowerCase()!==a&&e.setAttribute(a,!0)}elementMatch(e,t){const a=t.toLowerCase();return e.tagName.toLowerCase()===a||e.hasAttribute(a)}getSlotText(e,t){const a=e.shadowRoot?.querySelector(`slot[name="${t}"]`);return(a?.assignedNodes({flatten:!0})||[]).map(e=>e.textContent?.trim()).join(" ").trim()||null}}const n=/^(\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?)(Z|[+-]\d{2}:\d{2})?$/u;class i extends e{constructor(){super(),this._initializeDefaults()}_initializeDefaults(){this.weekday="short",this.month="short",this.locale="en-US",this._warnedLocales=new Set,this._warnedTimeZones=new Set,this._warnedValues=new Set,this._effectiveLocale=this._resolveLocale(this.locale),this.runtimeUtils=new a}_resolveLocale(e){if(!e)return"en-US";try{return Intl.getCanonicalLocales(e)[0]}catch{return this._warnedLocales&&!this._warnedLocales.has(e)&&(this._warnedLocales.add(e),console.warn(`auro-datetime: "${e}" is not a valid BCP 47 locale tag. Falling back to "en-US".`)),"en-US"}}_resolveTimeZone(e){if(e)try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),e}catch{return void(this._warnedTimeZones&&!this._warnedTimeZones.has(e)&&(this._warnedTimeZones.add(e),console.warn(`auro-datetime: "${e}" is not a valid IANA timezone. Falling back to viewer-local.`)))}}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit"}}static get properties(){return{locale:{type:String},month:{type:String},timeZone:{type:String},type:{type:String},value:{type:String},weekday:{type:String}}}static register(e="auro-datetime"){a.prototype.registerComponent(e,i)}willUpdate(e){e.has("locale")&&(this._effectiveLocale=this._resolveLocale(this.locale))}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}_zonedWallClockToUtc(e,t){const a=new Date(`${e}Z`),n=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(a),i=Object.fromEntries(n.filter(e=>"literal"!==e.type).map(e=>[e.type,e.value])),o=new Date(`${i.year}-${i.month}-${i.day}T${i.hour}:${i.minute}:${i.second}Z`),s=a.getTime()-o.getTime();return new Date(a.getTime()+s)}_resolveInputDate(){const e=this._resolveTimeZone(this.timeZone);if(null==this.value)return{date:new Date,timeZoneOption:e};const t=this.value.match(n);if(!t)return this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 string.`)),{date:null,timeZoneOption:void 0};const a=t[1],i=Boolean(t[2]);if(i&&!a.includes("T"))return this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 string (offset/Z requires a time component).`)),{date:null,timeZoneOption:void 0};const o=a.includes("T")?a:`${a}T00:00:00`,s=(()=>e&&!i?this._zonedWallClockToUtc(o,e):e&&i?new Date(this.value):new Date(o))();return Number.isNaN(s.getTime())?(this._warnedValues.has(this.value)||(this._warnedValues.add(this.value),console.warn(`auro-datetime: "${this.value}" is not a valid ISO 8601 date.`)),{date:null,timeZoneOption:void 0}):{date:s,timeZoneOption:e}}humanDate(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const a={...this.dateTemplate};return t&&(a.timeZone=t),e.toLocaleString(this._effectiveLocale,a)}humanDateConversion(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const a={};switch(t&&(a.timeZone=t),this.type){case"day":a.day="numeric";break;case"month":a.month=this.month;break;case"year":a.year="numeric";break;case"weekday":a.weekday=this.weekday}return e.toLocaleString(this._effectiveLocale,a)}numericDate(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const a={...this.dateTemplate,month:"numeric"};return Reflect.deleteProperty(a,"weekday"),t&&(a.timeZone=t),e.toLocaleString(this._effectiveLocale,a)}humanTime(){const{date:e,timeZoneOption:t}=this._resolveInputDate();if(!e)return"";const a={...this.timeTemplate};t&&(a.timeZone=t);const n=e.toLocaleString(this._effectiveLocale,a);return/[ap]\.?m\.?/iu.test(n)?n.replace(/^0+/u,"").toLowerCase():n}whichDate(){switch(this.type){case"date":default:return this.humanDate();case"time":return this.humanTime();case"year":case"month":case"weekday":case"day":return this.humanDateConversion();case"numeric":return this.numericDate()}}render(){return t`
|
|
2
|
-
<slot name="pre"></slot>
|
|
3
|
-
<span class="yield">${this.whichDate()}</span>
|
|
4
|
-
<slot name="post"></slot>
|
|
5
|
-
<slot></slot>
|
|
6
|
-
`}}export{i as A};
|