@aurodesignsystem-dev/auro-datetime 0.0.0-pr83.0 → 0.0.0-pr89.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/demo/api.md +128 -55
- package/demo/auro-datetime.min.js +325 -122
- package/dist/auro-datetime-39FU0ZIU.js +6 -0
- package/dist/index.d.ts +145 -69
- package/dist/index.js +1 -1
- package/dist/registered.js +1 -1
- package/package.json +4 -4
- package/dist/auro-datetime-jIlTbbhr.js +0 -6
|
@@ -86,31 +86,34 @@ class AuroLibraryRuntimeUtils {
|
|
|
86
86
|
* Copyright 2019 Google LLC
|
|
87
87
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
88
88
|
*/
|
|
89
|
-
const t$1=globalThis,e$2=t$1.ShadowRoot&&(void 0===t$1.ShadyCSS||t$1.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$3=new WeakMap;let n$2 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$2&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$2=t=>new n$2("string"==typeof t?t:t+"",void 0,s$2),S$1=(s,o)=>{if(e$2)s.adoptedStyleSheets=o.map(
|
|
89
|
+
const t$1=globalThis,e$2=t$1.ShadowRoot&&(void 0===t$1.ShadyCSS||t$1.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s$2=Symbol(),o$3=new WeakMap;let n$2 = class n{constructor(t,e,o){if(this._$cssResult$=true,o!==s$2)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e;}get styleSheet(){let t=this.o;const s=this.t;if(e$2&&void 0===t){const e=void 0!==s&&1===s.length;e&&(t=o$3.get(s)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),e&&o$3.set(s,t));}return t}toString(){return this.cssText}};const r$2=t=>new n$2("string"==typeof t?t:t+"",void 0,s$2),S$1=(s,o)=>{if(e$2)s.adoptedStyleSheets=o.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const e of o){const o=document.createElement("style"),n=t$1.litNonce;void 0!==n&&o.setAttribute("nonce",n),o.textContent=e.cssText,s.appendChild(o);}},c$2=e$2?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return r$2(e)})(t):t;
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* @license
|
|
93
93
|
* Copyright 2017 Google LLC
|
|
94
94
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
95
|
-
*/const{is:i$2,defineProperty:e$1,getOwnPropertyDescriptor:h$1,getOwnPropertyNames:r$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$1}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$2(t,s),b={attribute:true,type:String,converter:u$1,reflect:false,useDefault:false,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let y$1 = class y extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=b){if(s.state&&(s.attribute=false),this._$Ei(),this.prototype.hasOwnProperty(t)&&((s=Object.create(s)).wrapped=true),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),h=this.getPropertyDescriptor(t,i,s);void 0!==h&&e$1(this.prototype,t,h);}}static getPropertyDescriptor(t,s,i){const{get:e,set:r}=h$1(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get:e,set(s){const h=e?.call(this);r?.call(this,s),this.requestUpdate(t,h,i);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??b}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$1(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=true,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...r$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return false===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=false,this.hasUpdated=false,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise(
|
|
95
|
+
*/const{is:i$2,defineProperty:e$1,getOwnPropertyDescriptor:h$1,getOwnPropertyNames:r$1,getOwnPropertySymbols:o$2,getPrototypeOf:n$1}=Object,a$1=globalThis,c$1=a$1.trustedTypes,l$1=c$1?c$1.emptyScript:"",p$1=a$1.reactiveElementPolyfillSupport,d$1=(t,s)=>t,u$1={toAttribute(t,s){switch(s){case Boolean:t=t?l$1:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t);}return t},fromAttribute(t,s){let i=t;switch(s){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t);}catch(t){i=null;}}return i}},f$1=(t,s)=>!i$2(t,s),b$1={attribute:true,type:String,converter:u$1,reflect:false,useDefault:false,hasChanged:f$1};Symbol.metadata??=Symbol("metadata"),a$1.litPropertyMetadata??=new WeakMap;let y$1 = class y extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t);}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,s=b$1){if(s.state&&(s.attribute=false),this._$Ei(),this.prototype.hasOwnProperty(t)&&((s=Object.create(s)).wrapped=true),this.elementProperties.set(t,s),!s.noAccessor){const i=Symbol(),h=this.getPropertyDescriptor(t,i,s);void 0!==h&&e$1(this.prototype,t,h);}}static getPropertyDescriptor(t,s,i){const{get:e,set:r}=h$1(this.prototype,t)??{get(){return this[s]},set(t){this[s]=t;}};return {get:e,set(s){const h=e?.call(this);r?.call(this,s),this.requestUpdate(t,h,i);},configurable:true,enumerable:true}}static getPropertyOptions(t){return this.elementProperties.get(t)??b$1}static _$Ei(){if(this.hasOwnProperty(d$1("elementProperties")))return;const t=n$1(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties);}static finalize(){if(this.hasOwnProperty(d$1("finalized")))return;if(this.finalized=true,this._$Ei(),this.hasOwnProperty(d$1("properties"))){const t=this.properties,s=[...r$1(t),...o$2(t)];for(const i of s)this.createProperty(i,t[i]);}const t=this[Symbol.metadata];if(null!==t){const s=litPropertyMetadata.get(t);if(void 0!==s)for(const[t,i]of s)this.elementProperties.set(t,i);}this._$Eh=new Map;for(const[t,s]of this.elementProperties){const i=this._$Eu(t,s);void 0!==i&&this._$Eh.set(i,t);}this.elementStyles=this.finalizeStyles(this.styles);}static finalizeStyles(s){const i=[];if(Array.isArray(s)){const e=new Set(s.flat(1/0).reverse());for(const s of e)i.unshift(c$2(s));}else void 0!==s&&i.push(c$2(s));return i}static _$Eu(t,s){const i=s.attribute;return false===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=false,this.hasUpdated=false,this._$Em=null,this._$Ev();}_$Ev(){this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this));}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.();}removeController(t){this._$EO?.delete(t);}_$E_(){const t=new Map,s=this.constructor.elementProperties;for(const i of s.keys())this.hasOwnProperty(i)&&(t.set(i,this[i]),delete this[i]);t.size>0&&(this._$Ep=t);}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return S$1(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(true),this._$EO?.forEach(t=>t.hostConnected?.());}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.());}attributeChangedCallback(t,s,i){this._$AK(t,i);}_$ET(t,s){const i=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,i);if(void 0!==e&&true===i.reflect){const h=(void 0!==i.converter?.toAttribute?i.converter:u$1).toAttribute(s,i.type);this._$Em=t,null==h?this.removeAttribute(e):this.setAttribute(e,h),this._$Em=null;}}_$AK(t,s){const i=this.constructor,e=i._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=i.getPropertyOptions(e),h="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:u$1;this._$Em=e;const r=h.fromAttribute(s,t.type);this[e]=r??this._$Ej?.get(e)??r,this._$Em=null;}}requestUpdate(t,s,i,e=false,h){if(void 0!==t){const r=this.constructor;if(false===e&&(h=this[t]),i??=r.getPropertyOptions(t),!((i.hasChanged??f$1)(h,s)||i.useDefault&&i.reflect&&h===this._$Ej?.get(t)&&!this.hasAttribute(r._$Eu(t,i))))return;this.C(t,s,i);} false===this.isUpdatePending&&(this._$ES=this._$EP());}C(t,s,{useDefault:i,reflect:e,wrapped:h},r){i&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,r??s??this[t]),true!==h||void 0!==r)||(this._$AL.has(t)||(this.hasUpdated||i||(s=void 0),this._$AL.set(t,s)),true===e&&this._$Em!==t&&(this._$Eq??=new Set).add(t));}async _$EP(){this.isUpdatePending=true;try{await this._$ES;}catch(t){Promise.reject(t);}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,s]of this._$Ep)this[t]=s;this._$Ep=void 0;}const t=this.constructor.elementProperties;if(t.size>0)for(const[s,i]of t){const{wrapped:t}=i,e=this[s];true!==t||this._$AL.has(s)||void 0===e||this.C(s,void 0,i,e);}}let t=false;const s=this._$AL;try{t=this.shouldUpdate(s),t?(this.willUpdate(s),this._$EO?.forEach(t=>t.hostUpdate?.()),this.update(s)):this._$EM();}catch(s){throw t=false,this._$EM(),s}t&&this._$AE(s);}willUpdate(t){}_$AE(t){this._$EO?.forEach(t=>t.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=true,this.firstUpdated(t)),this.updated(t);}_$EM(){this._$AL=new Map,this.isUpdatePending=false;}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return true}update(t){this._$Eq&&=this._$Eq.forEach(t=>this._$ET(t,this[t])),this._$EM();}updated(t){}firstUpdated(t){}};y$1.elementStyles=[],y$1.shadowRootOptions={mode:"open"},y$1[d$1("elementProperties")]=new Map,y$1[d$1("finalized")]=new Map,p$1?.({ReactiveElement:y$1}),(a$1.reactiveElementVersions??=[]).push("2.1.2");
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* @license
|
|
99
99
|
* Copyright 2017 Google LLC
|
|
100
100
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
101
101
|
*/
|
|
102
|
-
const t=globalThis,i$1=t
|
|
102
|
+
const t=globalThis,i$1=t=>t,s$1=t.trustedTypes,e=s$1?s$1.createPolicy("lit-html",{createHTML:t=>t}):void 0,h="$lit$",o$1=`lit$${Math.random().toFixed(9).slice(2)}$`,n="?"+o$1,r=`<${n}>`,l=document,c=()=>l.createComment(""),a=t=>null===t||"object"!=typeof t&&"function"!=typeof t,u=Array.isArray,d=t=>u(t)||"function"==typeof t?.[Symbol.iterator],f="[ \t\n\f\r]",v=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,_=/-->/g,m=/>/g,p=RegExp(`>|${f}(?:([^\\s"'>=/]+)(${f}*=${f}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),g=/'/g,$=/"/g,y=/^(?:script|style|textarea|title)$/i,x=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),b=x(1),E=Symbol.for("lit-noChange"),A=Symbol.for("lit-nothing"),C=new WeakMap,P=l.createTreeWalker(l,129);function V(t,i){if(!u(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==e?e.createHTML(i):i}const N=(t,i)=>{const s=t.length-1,e=[];let n,l=2===i?"<svg>":3===i?"<math>":"",c=v;for(let i=0;i<s;i++){const s=t[i];let a,u,d=-1,f=0;for(;f<s.length&&(c.lastIndex=f,u=c.exec(s),null!==u);)f=c.lastIndex,c===v?"!--"===u[1]?c=_:void 0!==u[1]?c=m:void 0!==u[2]?(y.test(u[2])&&(n=RegExp("</"+u[2],"g")),c=p):void 0!==u[3]&&(c=p):c===p?">"===u[0]?(c=n??v,d=-1):void 0===u[1]?d=-2:(d=c.lastIndex-u[2].length,a=u[1],c=void 0===u[3]?p:'"'===u[3]?$:g):c===$||c===g?c=p:c===_||c===m?c=v:(c=p,n=void 0);const x=c===p&&t[i+1].startsWith("/>")?" ":"";l+=c===v?s+r:d>=0?(e.push(a),s.slice(0,d)+h+s.slice(d)+o$1+x):s+o$1+(-2===d?i:x);}return [V(t,l+(t[s]||"<?>")+(2===i?"</svg>":3===i?"</math>":"")),e]};class S{constructor({strings:t,_$litType$:i},e){let r;this.parts=[];let l=0,a=0;const u=t.length-1,d=this.parts,[f,v]=N(t,i);if(this.el=S.createElement(f,e),P.currentNode=this.el.content,2===i||3===i){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes);}for(;null!==(r=P.nextNode())&&d.length<u;){if(1===r.nodeType){if(r.hasAttributes())for(const t of r.getAttributeNames())if(t.endsWith(h)){const i=v[a++],s=r.getAttribute(t).split(o$1),e=/([.?@])?(.*)/.exec(i);d.push({type:1,index:l,name:e[2],strings:s,ctor:"."===e[1]?I:"?"===e[1]?L:"@"===e[1]?z:H}),r.removeAttribute(t);}else t.startsWith(o$1)&&(d.push({type:6,index:l}),r.removeAttribute(t));if(y.test(r.tagName)){const t=r.textContent.split(o$1),i=t.length-1;if(i>0){r.textContent=s$1?s$1.emptyScript:"";for(let s=0;s<i;s++)r.append(t[s],c()),P.nextNode(),d.push({type:2,index:++l});r.append(t[i],c());}}}else if(8===r.nodeType)if(r.data===n)d.push({type:2,index:l});else {let t=-1;for(;-1!==(t=r.data.indexOf(o$1,t+1));)d.push({type:7,index:l}),t+=o$1.length-1;}l++;}}static createElement(t,i){const s=l.createElement("template");return s.innerHTML=t,s}}function M(t,i,s=t,e){if(i===E)return i;let h=void 0!==e?s._$Co?.[e]:s._$Cl;const o=a(i)?void 0:i._$litDirective$;return h?.constructor!==o&&(h?._$AO?.(false),void 0===o?h=void 0:(h=new o(t),h._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=h:s._$Cl=h),void 0!==h&&(i=M(t,h._$AS(t,i.values),h,e)),i}class R{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i;}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??l).importNode(i,true);P.currentNode=e;let h=P.nextNode(),o=0,n=0,r=s[0];for(;void 0!==r;){if(o===r.index){let i;2===r.type?i=new k(h,h.nextSibling,this,t):1===r.type?i=new r.ctor(h,r.name,r.strings,this,t):6===r.type&&(i=new Z(h,this,t)),this._$AV.push(i),r=s[++n];}o!==r?.index&&(h=P.nextNode(),o++);}return P.currentNode=l,e}p(t){let i=0;for(const s of this._$AV) void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++;}}class k{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=A,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??true;}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=M(this,t,i),a(t)?t===A||null==t||""===t?(this._$AH!==A&&this._$AR(),this._$AH=A):t!==this._$AH&&t!==E&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):d(t)?this.k(t):this._(t);}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t));}_(t){this._$AH!==A&&a(this._$AH)?this._$AA.nextSibling.data=t:this.T(l.createTextNode(t)),this._$AH=t;}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=S.createElement(V(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else {const t=new R(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t;}}_$AC(t){let i=C.get(t.strings);return void 0===i&&C.set(t.strings,i=new S(t)),i}k(t){u(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const h of t)e===i.length?i.push(s=new k(this.O(c()),this.O(c()),this,this.options)):s=i[e],s._$AI(h),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e);}_$AR(t=this._$AA.nextSibling,s){for(this._$AP?.(false,true,s);t!==this._$AB;){const s=i$1(t).nextSibling;i$1(t).remove(),t=s;}}setConnected(t){ void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t));}}class H{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,h){this.type=1,this._$AH=A,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=h,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=A;}_$AI(t,i=this,s,e){const h=this.strings;let o=false;if(void 0===h)t=M(this,t,i,0),o=!a(t)||t!==this._$AH&&t!==E,o&&(this._$AH=t);else {const e=t;let n,r;for(t=h[0],n=0;n<h.length-1;n++)r=M(this,e[s+n],i,n),r===E&&(r=this._$AH[n]),o||=!a(r)||r!==this._$AH[n],r===A?t=A:t!==A&&(t+=(r??"")+h[n+1]),this._$AH[n]=r;}o&&!e&&this.j(t);}j(t){t===A?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"");}}class I extends H{constructor(){super(...arguments),this.type=3;}j(t){this.element[this.name]=t===A?void 0:t;}}class L extends H{constructor(){super(...arguments),this.type=4;}j(t){this.element.toggleAttribute(this.name,!!t&&t!==A);}}class z extends H{constructor(t,i,s,e,h){super(t,i,s,e,h),this.type=5;}_$AI(t,i=this){if((t=M(this,t,i,0)??A)===E)return;const s=this._$AH,e=t===A&&s!==A||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,h=t!==A&&(s===A||e);e&&this.element.removeEventListener(this.name,this,s),h&&this.element.addEventListener(this.name,this,t),this._$AH=t;}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t);}}class Z{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s;}get _$AU(){return this._$AM._$AU}_$AI(t){M(this,t);}}const B=t.litHtmlPolyfillSupport;B?.(S,k),(t.litHtmlVersions??=[]).push("3.3.2");const D=(t,i,s)=>{const e=s?.renderBefore??i;let h=e._$litPart$;if(void 0===h){const t=s?.renderBefore??null;e._$litPart$=h=new k(i.insertBefore(c(),t),t,void 0,s??{});}return h._$AI(t),h};
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* @license
|
|
106
106
|
* Copyright 2017 Google LLC
|
|
107
107
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
108
|
-
*/const s=globalThis;class i extends y$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const r=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=
|
|
108
|
+
*/const s=globalThis;class i extends y$1{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0;}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const r=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=D(r,this.renderRoot,this.renderOptions);}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(true);}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(false);}render(){return E}}i._$litElement$=true,i["finalized"]=true,s.litElementHydrateSupport?.({LitElement:i});const o=s.litElementPolyfillSupport;o?.({LitElement:i});(s.litElementVersions??=[]).push("4.2.2");
|
|
109
109
|
|
|
110
110
|
// Copyright (c) 2020 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
|
|
111
111
|
// See LICENSE in the project root for license information.
|
|
112
112
|
|
|
113
113
|
|
|
114
|
+
const ISO_8601_REGEX =
|
|
115
|
+
/^(\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?)(Z|[+-]\d{2}:\d{2})?$/u;
|
|
116
|
+
|
|
114
117
|
// See https://git.io/JJ6SJ for "How to document your components using JSDoc"
|
|
115
118
|
/**
|
|
116
119
|
* The `auro-datetime` element is for the purposes of providing an easy to use date and time API.
|
|
@@ -131,6 +134,38 @@ class AuroDatetime extends i {
|
|
|
131
134
|
_initializeDefaults() {
|
|
132
135
|
this.weekday = "short";
|
|
133
136
|
this.month = "short";
|
|
137
|
+
this.locale = "en-US";
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Tracks invalid locale inputs already warned about, so a parent that
|
|
141
|
+
* re-renders with the same bad value doesn't flood the console.
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
this._warnedLocales = new Set();
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Tracks invalid timeZone inputs already warned about. Same dedup
|
|
148
|
+
* pattern as `_warnedLocales`.
|
|
149
|
+
* @private
|
|
150
|
+
*/
|
|
151
|
+
this._warnedTimeZones = new Set();
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Tracks invalid value inputs already warned about. Same dedup
|
|
155
|
+
* pattern as `_warnedLocales`.
|
|
156
|
+
* @private
|
|
157
|
+
*/
|
|
158
|
+
this._warnedValues = new Set();
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
this._effectiveLocale = this._resolveLocale(this.locale);
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
this._effectiveTimeZone = this._resolveTimeZone(this.timezone);
|
|
134
169
|
|
|
135
170
|
/**
|
|
136
171
|
* @private
|
|
@@ -138,6 +173,72 @@ class AuroDatetime extends i {
|
|
|
138
173
|
this.runtimeUtils = new AuroLibraryRuntimeUtils();
|
|
139
174
|
}
|
|
140
175
|
|
|
176
|
+
/**
|
|
177
|
+
* Validate and canonicalize a BCP 47 locale tag. Falls back to "en-US"
|
|
178
|
+
* for empty or invalid input. The first invalid value seen per element
|
|
179
|
+
* is logged via `console.warn`; subsequent identical inputs are silent.
|
|
180
|
+
*
|
|
181
|
+
* @private
|
|
182
|
+
* @param {string} input - User-supplied locale tag.
|
|
183
|
+
* @returns {string} Canonical locale tag (e.g. "en-GB"), or "en-US" on fallback.
|
|
184
|
+
*/
|
|
185
|
+
_resolveLocale(input) {
|
|
186
|
+
if (!input) {
|
|
187
|
+
return "en-US";
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
return Intl.getCanonicalLocales(input)[0];
|
|
191
|
+
} catch {
|
|
192
|
+
if (this._warnedLocales && !this._warnedLocales.has(input)) {
|
|
193
|
+
this._warnedLocales.add(input);
|
|
194
|
+
console.warn(
|
|
195
|
+
`auro-datetime: "${input}" is not a valid BCP 47 locale tag. Falling back to "en-US".`,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
return "en-US";
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Validate an IANA timezone identifier. Invalid input warns once per
|
|
204
|
+
* unique value per element and resolves to `undefined`, which makes
|
|
205
|
+
* the rest of `_resolveInputDate` behave as if `timezone` was never
|
|
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.
|
|
217
|
+
*
|
|
218
|
+
* @private
|
|
219
|
+
* @param {string | undefined} input - Consumer-supplied timezone.
|
|
220
|
+
* @returns {string | undefined} Valid timezone, or undefined on fallback.
|
|
221
|
+
*/
|
|
222
|
+
_resolveTimeZone(input) {
|
|
223
|
+
if (!input) {
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
// Constructing the formatter is enough to surface a RangeError;
|
|
228
|
+
// we don't need to format anything yet.
|
|
229
|
+
new Intl.DateTimeFormat(undefined, { timeZone: input });
|
|
230
|
+
return input;
|
|
231
|
+
} catch {
|
|
232
|
+
if (this._warnedTimeZones && !this._warnedTimeZones.has(input)) {
|
|
233
|
+
this._warnedTimeZones.add(input);
|
|
234
|
+
console.warn(
|
|
235
|
+
`auro-datetime: "${input}" is not a valid IANA timezone. Falling back to viewer-local.`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
141
242
|
connectedCallback() {
|
|
142
243
|
super.connectedCallback();
|
|
143
244
|
|
|
@@ -151,10 +252,7 @@ class AuroDatetime extends i {
|
|
|
151
252
|
this.timeTemplate = {
|
|
152
253
|
hour: "2-digit",
|
|
153
254
|
minute: "2-digit",
|
|
154
|
-
timeZone: this.timeZone,
|
|
155
255
|
};
|
|
156
|
-
|
|
157
|
-
this.template = {};
|
|
158
256
|
}
|
|
159
257
|
|
|
160
258
|
// function to define props used within the scope of this component
|
|
@@ -163,9 +261,11 @@ class AuroDatetime extends i {
|
|
|
163
261
|
// ...super.properties,
|
|
164
262
|
|
|
165
263
|
/**
|
|
166
|
-
*
|
|
264
|
+
* BCP 47 language tag for locale-aware date/time formatting (e.g. 'en-GB', 'de-DE', 'ja-JP').
|
|
265
|
+
* @type {string}
|
|
266
|
+
* @default 'en-US'
|
|
167
267
|
*/
|
|
168
|
-
|
|
268
|
+
locale: { type: String },
|
|
169
269
|
|
|
170
270
|
/**
|
|
171
271
|
* Defines format of month
|
|
@@ -175,25 +275,29 @@ class AuroDatetime extends i {
|
|
|
175
275
|
month: { type: String },
|
|
176
276
|
|
|
177
277
|
/**
|
|
178
|
-
* Pass in string to
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Pass in string to define [timeZone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
278
|
+
* Pass in string to define [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
279
|
+
* When set, the moment described by `value` is converted into this IANA zone for display.
|
|
280
|
+
* When unset, the wall-clock time from the input string is rendered as-is.
|
|
184
281
|
*/
|
|
185
|
-
|
|
282
|
+
timezone: { type: String },
|
|
186
283
|
|
|
187
284
|
/**
|
|
188
285
|
* Defines type of data to render
|
|
189
|
-
* @type {'date' | 'time' | 'year' | 'month' | 'weekday' | 'day' | 'numeric'
|
|
286
|
+
* @type {'date' | 'time' | 'year' | 'month' | 'weekday' | 'day' | 'numeric'}
|
|
190
287
|
*/
|
|
191
288
|
type: { type: String },
|
|
192
289
|
|
|
193
290
|
/**
|
|
194
|
-
*
|
|
291
|
+
* ISO 8601 date or date-time string. Examples:
|
|
292
|
+
* - `2022-07-14T08:00:00-07:00` (with offset)
|
|
293
|
+
* - `2022-07-14T08:00:00Z` (UTC)
|
|
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.
|
|
195
299
|
*/
|
|
196
|
-
|
|
300
|
+
value: { type: String },
|
|
197
301
|
|
|
198
302
|
/**
|
|
199
303
|
* Defines format of weekday
|
|
@@ -216,176 +320,275 @@ class AuroDatetime extends i {
|
|
|
216
320
|
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroDatetime);
|
|
217
321
|
}
|
|
218
322
|
|
|
323
|
+
willUpdate(changedProperties) {
|
|
324
|
+
if (changedProperties.has("locale")) {
|
|
325
|
+
this._effectiveLocale = this._resolveLocale(this.locale);
|
|
326
|
+
}
|
|
327
|
+
if (changedProperties.has("timezone")) {
|
|
328
|
+
this._effectiveTimeZone = this._resolveTimeZone(this.timezone);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
219
332
|
firstUpdated() {
|
|
220
333
|
// Add the tag name as an attribute if it is different than the component name
|
|
221
334
|
this.runtimeUtils.handleComponentTagRename(this, "auro-datetime");
|
|
222
335
|
}
|
|
223
336
|
|
|
224
337
|
/**
|
|
225
|
-
*
|
|
338
|
+
* Construct a UTC Date that, when displayed in the given IANA timezone,
|
|
339
|
+
* shows the supplied wall-clock components. Used when `value` has no
|
|
340
|
+
* offset but `timeZone` is set — the wall-clock is interpreted as being
|
|
341
|
+
* in the target zone rather than the viewer's local zone.
|
|
342
|
+
*
|
|
343
|
+
* Algorithm: parse the wall-clock as if it were UTC (a "naive" Date),
|
|
344
|
+
* ask Intl what that moment looks like in the target zone, and use the
|
|
345
|
+
* delta between the two to recover the true UTC moment.
|
|
346
|
+
*
|
|
226
347
|
* @private
|
|
227
|
-
* @
|
|
348
|
+
* @param {string} localISO - ISO string with no offset, e.g. "2022-07-14T08:00:00".
|
|
349
|
+
* @param {string} timeZone - IANA zone, e.g. "US/Eastern".
|
|
350
|
+
* @returns {Date}
|
|
228
351
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
352
|
+
_zonedWallClockToUtc(localISO, timeZone) {
|
|
353
|
+
const naiveUtc = new Date(`${localISO}Z`);
|
|
354
|
+
const parts = new Intl.DateTimeFormat("en-US", {
|
|
355
|
+
timeZone,
|
|
356
|
+
hourCycle: "h23",
|
|
357
|
+
year: "numeric",
|
|
358
|
+
month: "2-digit",
|
|
359
|
+
day: "2-digit",
|
|
360
|
+
hour: "2-digit",
|
|
361
|
+
minute: "2-digit",
|
|
362
|
+
second: "2-digit",
|
|
363
|
+
}).formatToParts(naiveUtc);
|
|
364
|
+
const lookup = Object.fromEntries(
|
|
365
|
+
parts.filter((p) => p.type !== "literal").map((p) => [p.type, p.value]),
|
|
366
|
+
);
|
|
367
|
+
const seenInZone = new Date(
|
|
368
|
+
`${lookup.year}-${lookup.month}-${lookup.day}T${lookup.hour}:${lookup.minute}:${lookup.second}Z`,
|
|
369
|
+
);
|
|
370
|
+
const offsetMs = naiveUtc.getTime() - seenInZone.getTime();
|
|
371
|
+
return new Date(naiveUtc.getTime() + offsetMs);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Resolve the `value` and `timezone` attributes into a Date and an optional
|
|
376
|
+
* timeZone option for `Intl.DateTimeFormat`.
|
|
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.
|
|
393
|
+
*
|
|
394
|
+
* @private
|
|
395
|
+
* @returns {{ date: Date | null, timeZoneOption: string | undefined }}
|
|
396
|
+
*/
|
|
397
|
+
_resolveInputDate() {
|
|
398
|
+
const resolvedTz = this._effectiveTimeZone;
|
|
399
|
+
|
|
400
|
+
// Only true "omitted" inputs (null/undefined) get the today's-date
|
|
401
|
+
// treatment. Empty string falls through to ISO validation, which will
|
|
402
|
+
// fail and produce the documented warn + empty render.
|
|
403
|
+
if (this.value == null) {
|
|
404
|
+
return { date: new Date(), timeZoneOption: resolvedTz };
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const match = this.value.match(ISO_8601_REGEX);
|
|
408
|
+
if (!match) {
|
|
409
|
+
if (!this._warnedValues.has(this.value)) {
|
|
410
|
+
this._warnedValues.add(this.value);
|
|
411
|
+
console.warn(
|
|
412
|
+
`auro-datetime: "${this.value}" is not a valid ISO 8601 string.`,
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
return { date: null, timeZoneOption: undefined };
|
|
416
|
+
}
|
|
231
417
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
418
|
+
const localPart = match[1];
|
|
419
|
+
const hasOffset = Boolean(match[2]);
|
|
420
|
+
|
|
421
|
+
// The regex permits an offset/Z suffix on a bare date (e.g. "2020-09-22Z"
|
|
422
|
+
// or "2020-09-22-07:00"). Those forms are not valid ISO 8601 — an offset
|
|
423
|
+
// is only meaningful with a time component — and the wall-clock branch
|
|
424
|
+
// would silently drop the offset, producing surprising output. Reject
|
|
425
|
+
// them up front so the consumer sees a warning.
|
|
426
|
+
if (hasOffset && !localPart.includes("T")) {
|
|
427
|
+
if (!this._warnedValues.has(this.value)) {
|
|
428
|
+
this._warnedValues.add(this.value);
|
|
429
|
+
console.warn(
|
|
430
|
+
`auro-datetime: "${this.value}" is not a valid ISO 8601 string (offset/Z requires a time component).`,
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
return { date: null, timeZoneOption: undefined };
|
|
237
434
|
}
|
|
238
435
|
|
|
239
|
-
|
|
436
|
+
const normalized = localPart.includes("T")
|
|
437
|
+
? localPart
|
|
438
|
+
: `${localPart}T00:00:00`;
|
|
439
|
+
|
|
440
|
+
// The regex only validates string shape, not value ranges — "2022-99-99"
|
|
441
|
+
// matches but produces an Invalid Date. Detect that and treat it like
|
|
442
|
+
// any other malformed input so render falls back to the documented
|
|
443
|
+
// empty output instead of "Invalid Date" or a thrown RangeError from
|
|
444
|
+
// downstream Intl calls.
|
|
445
|
+
const buildDate = () => {
|
|
446
|
+
if (resolvedTz && !hasOffset) {
|
|
447
|
+
return this._zonedWallClockToUtc(normalized, resolvedTz);
|
|
448
|
+
}
|
|
449
|
+
if (resolvedTz && hasOffset) {
|
|
450
|
+
return new Date(this.value);
|
|
451
|
+
}
|
|
452
|
+
// Wall-clock: keep the components in the input verbatim. JS parses
|
|
453
|
+
// bare "YYYY-MM-DD" as UTC midnight, which shifts the date in the
|
|
454
|
+
// viewer's timezone; appending a time forces local-time parsing.
|
|
455
|
+
return new Date(normalized);
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
const date = buildDate();
|
|
459
|
+
if (Number.isNaN(date.getTime())) {
|
|
460
|
+
if (!this._warnedValues.has(this.value)) {
|
|
461
|
+
this._warnedValues.add(this.value);
|
|
462
|
+
console.warn(
|
|
463
|
+
`auro-datetime: "${this.value}" is not a valid ISO 8601 date.`,
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
return { date: null, timeZoneOption: undefined };
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return { date, timeZoneOption: resolvedTz };
|
|
240
470
|
}
|
|
241
471
|
|
|
242
472
|
/**
|
|
243
|
-
* Internal function to
|
|
473
|
+
* Internal function to generate full date string.
|
|
244
474
|
* @private
|
|
245
475
|
* @returns {string} - Date string.
|
|
246
476
|
*/
|
|
247
|
-
|
|
248
|
-
|
|
477
|
+
humanDate() {
|
|
478
|
+
const { date, timeZoneOption } = this._resolveInputDate();
|
|
479
|
+
if (!date) {
|
|
480
|
+
return "";
|
|
481
|
+
}
|
|
482
|
+
const template = { ...this.dateTemplate };
|
|
483
|
+
if (timeZoneOption) {
|
|
484
|
+
template.timeZone = timeZoneOption;
|
|
485
|
+
}
|
|
486
|
+
return date.toLocaleString(this._effectiveLocale, template);
|
|
487
|
+
}
|
|
249
488
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
489
|
+
/**
|
|
490
|
+
* Internal function to format a single date part (year/month/weekday/day).
|
|
491
|
+
* @private
|
|
492
|
+
* @returns {string} - Date string.
|
|
493
|
+
*/
|
|
494
|
+
humanDateConversion() {
|
|
495
|
+
const { date, timeZoneOption } = this._resolveInputDate();
|
|
496
|
+
if (!date) {
|
|
497
|
+
return "";
|
|
498
|
+
}
|
|
499
|
+
const template = {};
|
|
500
|
+
if (timeZoneOption) {
|
|
501
|
+
template.timeZone = timeZoneOption;
|
|
255
502
|
}
|
|
256
503
|
|
|
257
504
|
switch (this.type) {
|
|
258
505
|
case "day":
|
|
259
|
-
|
|
506
|
+
template.day = "numeric";
|
|
260
507
|
break;
|
|
261
508
|
case "month":
|
|
262
|
-
|
|
509
|
+
template.month = this.month;
|
|
263
510
|
break;
|
|
264
511
|
case "year":
|
|
265
|
-
|
|
512
|
+
template.year = "numeric";
|
|
266
513
|
break;
|
|
267
514
|
case "weekday":
|
|
268
|
-
|
|
515
|
+
template.weekday = this.weekday;
|
|
269
516
|
break;
|
|
270
|
-
|
|
271
|
-
default:
|
|
272
|
-
this.template.weekday = this.template;
|
|
273
517
|
}
|
|
274
518
|
|
|
275
|
-
return
|
|
519
|
+
return date.toLocaleString(this._effectiveLocale, template);
|
|
276
520
|
}
|
|
277
521
|
|
|
278
522
|
/**
|
|
279
|
-
* Internal function generate numeric date string
|
|
523
|
+
* Internal function to generate numeric date string MM/DD/YYYY.
|
|
280
524
|
* @private
|
|
281
525
|
* @returns {string} - Date string.
|
|
282
526
|
*/
|
|
283
527
|
numericDate() {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (this.utc) {
|
|
289
|
-
this.dateTemplate.timeZone = "UTC";
|
|
290
|
-
newDate = new Date(this.utc);
|
|
291
|
-
} else if (this.setDate) {
|
|
292
|
-
newDate = new Date(this.setDate);
|
|
528
|
+
const { date, timeZoneOption } = this._resolveInputDate();
|
|
529
|
+
if (!date) {
|
|
530
|
+
return "";
|
|
293
531
|
}
|
|
294
|
-
|
|
295
|
-
|
|
532
|
+
const template = { ...this.dateTemplate, month: "numeric" };
|
|
533
|
+
Reflect.deleteProperty(template, "weekday");
|
|
534
|
+
if (timeZoneOption) {
|
|
535
|
+
template.timeZone = timeZoneOption;
|
|
536
|
+
}
|
|
537
|
+
return date.toLocaleString(this._effectiveLocale, template);
|
|
296
538
|
}
|
|
297
539
|
|
|
298
540
|
/**
|
|
299
|
-
* Internal function generate standard time string.
|
|
541
|
+
* Internal function to generate standard time string.
|
|
300
542
|
* @private
|
|
301
543
|
* @returns {string} - Time string.
|
|
302
544
|
*/
|
|
303
545
|
humanTime() {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this.timeTemplate.timeZone = "UTC";
|
|
308
|
-
newTime = new Date(this.utc);
|
|
309
|
-
} else if (this.setDate) {
|
|
310
|
-
newTime = new Date(this.setDate);
|
|
546
|
+
const { date, timeZoneOption } = this._resolveInputDate();
|
|
547
|
+
if (!date) {
|
|
548
|
+
return "";
|
|
311
549
|
}
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
|
|
315
|
-
.toLocaleString("en-us", this.timeTemplate)
|
|
316
|
-
.replace(/^0+/u, "");
|
|
550
|
+
const template = { ...this.timeTemplate };
|
|
551
|
+
if (timeZoneOption) {
|
|
552
|
+
template.timeZone = timeZoneOption;
|
|
317
553
|
}
|
|
318
554
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
*/
|
|
331
|
-
tzTime(template) {
|
|
332
|
-
const scrubNumber = -6;
|
|
333
|
-
const scrubTimeZone = this.setDate.slice(0, scrubNumber);
|
|
334
|
-
const newDateTime = new Date(scrubTimeZone);
|
|
335
|
-
|
|
336
|
-
if (this.cap) {
|
|
337
|
-
return newDateTime.toLocaleString("en-us", template).replace(/^0+/u, "");
|
|
555
|
+
const formatted = date.toLocaleString(this._effectiveLocale, template);
|
|
556
|
+
|
|
557
|
+
// Detect a 12-hour rendered output by the presence of a Latin-script
|
|
558
|
+
// period marker. The pattern matches `am`, `pm`, `a.m.`, `p.m.`
|
|
559
|
+
// (case-insensitive), so it catches en-US (`PM`), en-AU/hi-IN (`pm`),
|
|
560
|
+
// and en-CA/es-MX (`p.m.`) alike. Non-Latin period markers (ko `오후`,
|
|
561
|
+
// 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 …) also
|
|
563
|
+
// fall through, preserving their leading zeros.
|
|
564
|
+
if (!/[ap]\.?m\.?/iu.test(formatted)) {
|
|
565
|
+
return formatted;
|
|
338
566
|
}
|
|
339
567
|
|
|
340
|
-
return
|
|
341
|
-
.toLocaleString("en-us", template)
|
|
342
|
-
.replace(/^0+/u, "")
|
|
343
|
-
.replace("AM", "am")
|
|
344
|
-
.replace("PM", "pm");
|
|
568
|
+
return formatted.replace(/^0+/u, "").toLowerCase();
|
|
345
569
|
}
|
|
346
570
|
|
|
347
571
|
/**
|
|
348
572
|
* Internal function UI decision.
|
|
349
573
|
* @private
|
|
350
|
-
* @returns {
|
|
574
|
+
* @returns {string} - String determined by `type` (or full date if no type set).
|
|
351
575
|
*/
|
|
352
576
|
whichDate() {
|
|
353
|
-
let result = "";
|
|
354
|
-
|
|
355
577
|
switch (this.type) {
|
|
356
578
|
case "date":
|
|
357
|
-
|
|
358
|
-
break;
|
|
359
|
-
case "tzDate":
|
|
360
|
-
result = this.tzTime(this.dateTemplate);
|
|
361
|
-
break;
|
|
362
|
-
case "tzTime":
|
|
363
|
-
result = this.tzTime(this.timeTemplate);
|
|
364
|
-
break;
|
|
579
|
+
return this.humanDate();
|
|
365
580
|
case "time":
|
|
366
|
-
|
|
367
|
-
break;
|
|
581
|
+
return this.humanTime();
|
|
368
582
|
case "year":
|
|
369
583
|
case "month":
|
|
370
584
|
case "weekday":
|
|
371
585
|
case "day":
|
|
372
|
-
|
|
373
|
-
break;
|
|
586
|
+
return this.humanDateConversion();
|
|
374
587
|
case "numeric":
|
|
375
|
-
|
|
376
|
-
break;
|
|
588
|
+
return this.numericDate();
|
|
377
589
|
default:
|
|
378
|
-
this.humanDate();
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
if (this.setDate && !this.type) {
|
|
382
|
-
return this.humanDate();
|
|
383
|
-
}
|
|
384
|
-
if (this.utc && !this.type) {
|
|
385
|
-
return this.humanDate();
|
|
590
|
+
return this.humanDate();
|
|
386
591
|
}
|
|
387
|
-
|
|
388
|
-
return result;
|
|
389
592
|
}
|
|
390
593
|
|
|
391
594
|
// When using auroElement, use the following attribute and function when hiding content from screen readers.
|
|
@@ -393,7 +596,7 @@ class AuroDatetime extends i {
|
|
|
393
596
|
|
|
394
597
|
// function that renders the HTML and CSS into the scope of the component
|
|
395
598
|
render() {
|
|
396
|
-
return
|
|
599
|
+
return b`
|
|
397
600
|
<slot name="pre"></slot>
|
|
398
601
|
<span class="yield">${this.whichDate()}</span>
|
|
399
602
|
<slot name="post"></slot>
|