@aurodesignsystem-dev/auro-datetime 0.0.0-pr82.0 → 0.0.0-pr82.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -131,6 +131,7 @@ class AuroDatetime extends i {
131
131
  _initializeDefaults() {
132
132
  this.weekday = "short";
133
133
  this.month = "short";
134
+ this.locale = "en-US";
134
135
 
135
136
  /**
136
137
  * @private
@@ -224,6 +225,16 @@ class AuroDatetime extends i {
224
225
  AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroDatetime);
225
226
  }
226
227
 
228
+ willUpdate(changedProperties) {
229
+ if (changedProperties.has('locale') && this.locale) {
230
+ try {
231
+ Intl.getCanonicalLocales(this.locale);
232
+ } catch {
233
+ this.locale = "en-US";
234
+ }
235
+ }
236
+ }
237
+
227
238
  firstUpdated() {
228
239
  // Add the tag name as an attribute if it is different than the component name
229
240
  this.runtimeUtils.handleComponentTagRename(this, "auro-datetime");
@@ -244,7 +255,7 @@ class AuroDatetime extends i {
244
255
  newDate = new Date(this.setDate);
245
256
  }
246
257
 
247
- return newDate.toLocaleString(this.locale || "en-us", this.dateTemplate);
258
+ return newDate.toLocaleString(this.locale, this.dateTemplate);
248
259
  }
249
260
 
250
261
  /**
@@ -280,7 +291,7 @@ class AuroDatetime extends i {
280
291
  this.template.weekday = this.template;
281
292
  }
282
293
 
283
- return newDate.toLocaleString(this.locale || "en-us", this.template);
294
+ return newDate.toLocaleString(this.locale, this.template);
284
295
  }
285
296
 
286
297
  /**
@@ -300,7 +311,7 @@ class AuroDatetime extends i {
300
311
  newDate = new Date(this.setDate);
301
312
  }
302
313
 
303
- return newDate.toLocaleString(this.locale || "en-us", this.dateTemplate);
314
+ return newDate.toLocaleString(this.locale, this.dateTemplate);
304
315
  }
305
316
 
306
317
  /**
@@ -320,12 +331,12 @@ class AuroDatetime extends i {
320
331
 
321
332
  if (this.cap) {
322
333
  return newTime
323
- .toLocaleString(this.locale || "en-us", this.timeTemplate)
334
+ .toLocaleString(this.locale, this.timeTemplate)
324
335
  .replace(/^0+/u, "");
325
336
  }
326
337
 
327
338
  return newTime
328
- .toLocaleString(this.locale || "en-us", this.timeTemplate)
339
+ .toLocaleString(this.locale, this.timeTemplate)
329
340
  .replace(/^0+/u, "")
330
341
  .toLowerCase();
331
342
  }
@@ -342,11 +353,11 @@ class AuroDatetime extends i {
342
353
  const newDateTime = new Date(scrubTimeZone);
343
354
 
344
355
  if (this.cap) {
345
- return newDateTime.toLocaleString(this.locale || "en-us", template).replace(/^0+/u, "");
356
+ return newDateTime.toLocaleString(this.locale, template).replace(/^0+/u, "");
346
357
  }
347
358
 
348
359
  return newDateTime
349
- .toLocaleString(this.locale || "en-us", template)
360
+ .toLocaleString(this.locale, template)
350
361
  .replace(/^0+/u, "")
351
362
  .replace("AM", "am")
352
363
  .replace("PM", "pm");
@@ -0,0 +1,6 @@
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,s=t&&t.closest(e))=>t&&t!==document&&t!==window?s||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}}class s extends e{constructor(){super(),this._initializeDefaults()}_initializeDefaults(){this.weekday="short",this.month="short",this.locale="en-US",this.runtimeUtils=new a}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit",timeZone:this.timeZone},this.template={}}static get properties(){return{cap:{type:Boolean},locale:{type:String},month:{type:String},setDate:{type:String},timeZone:{type:String},type:{type:String},utc:{type:String},weekday:{type:String}}}static register(e="auro-datetime"){a.prototype.registerComponent(e,s)}willUpdate(e){if(e.has("locale")&&this.locale)try{Intl.getCanonicalLocales(this.locale)}catch{this.locale="en-US"}}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}humanDate(){let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString(this.locale,this.dateTemplate)}humanDateConversion(){let e=new Date;switch(this.utc?(this.template.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.type){case"day":this.template.day="numeric";break;case"month":this.template.month=this.month;break;case"year":this.template.year="numeric";break;case"weekday":this.template.weekday=this.weekday;break;default:this.template.weekday=this.template}return e.toLocaleString(this.locale,this.template)}numericDate(){this.dateTemplate.month="numeric",Reflect.deleteProperty(this.dateTemplate,"weekday");let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString(this.locale,this.dateTemplate)}humanTime(){let e=new Date;return this.utc?(this.timeTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.cap?e.toLocaleString(this.locale,this.timeTemplate).replace(/^0+/u,""):e.toLocaleString(this.locale,this.timeTemplate).replace(/^0+/u,"").toLowerCase()}tzTime(e){const t=this.setDate.slice(0,-6),a=new Date(t);return this.cap?a.toLocaleString(this.locale,e).replace(/^0+/u,""):a.toLocaleString(this.locale,e).replace(/^0+/u,"").replace("AM","am").replace("PM","pm")}whichDate(){let e="";switch(this.type){case"date":e=this.humanDate();break;case"tzDate":e=this.tzTime(this.dateTemplate);break;case"tzTime":e=this.tzTime(this.timeTemplate);break;case"time":e=this.humanTime();break;case"year":case"month":case"weekday":case"day":e=this.humanDateConversion();break;case"numeric":e=this.numericDate();break;default:this.humanDate()}return this.setDate&&!this.type||this.utc&&!this.type?this.humanDate():e}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{s as A};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{A as AuroDatetime}from"./auro-datetime-BobtS5w7.js";import"lit";
1
+ export{A as AuroDatetime}from"./auro-datetime-DxCkU1MY.js";import"lit";
@@ -1 +1 @@
1
- import{A as r}from"./auro-datetime-BobtS5w7.js";import"lit";r.register();
1
+ import{A as r}from"./auro-datetime-DxCkU1MY.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.0",
10
+ "version": "0.0.0-pr82.1",
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,s=t&&t.closest(e))=>t&&t!==document&&t!==window?s||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}}class s extends e{constructor(){super(),this._initializeDefaults()}_initializeDefaults(){this.weekday="short",this.month="short",this.runtimeUtils=new a}connectedCallback(){super.connectedCallback(),this.dateTemplate={weekday:this.weekday,year:"numeric",month:this.month,day:"numeric"},this.timeTemplate={hour:"2-digit",minute:"2-digit",timeZone:this.timeZone},this.template={}}static get properties(){return{cap:{type:Boolean},locale:{type:String},month:{type:String},setDate:{type:String},timeZone:{type:String},type:{type:String},utc:{type:String},weekday:{type:String}}}static register(e="auro-datetime"){a.prototype.registerComponent(e,s)}firstUpdated(){this.runtimeUtils.handleComponentTagRename(this,"auro-datetime")}humanDate(){let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString(this.locale||"en-us",this.dateTemplate)}humanDateConversion(){let e=new Date;switch(this.utc?(this.template.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.type){case"day":this.template.day="numeric";break;case"month":this.template.month=this.month;break;case"year":this.template.year="numeric";break;case"weekday":this.template.weekday=this.weekday;break;default:this.template.weekday=this.template}return e.toLocaleString(this.locale||"en-us",this.template)}numericDate(){this.dateTemplate.month="numeric",Reflect.deleteProperty(this.dateTemplate,"weekday");let e=new Date;return this.utc?(this.dateTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),e.toLocaleString(this.locale||"en-us",this.dateTemplate)}humanTime(){let e=new Date;return this.utc?(this.timeTemplate.timeZone="UTC",e=new Date(this.utc)):this.setDate&&(e=new Date(this.setDate)),this.cap?e.toLocaleString(this.locale||"en-us",this.timeTemplate).replace(/^0+/u,""):e.toLocaleString(this.locale||"en-us",this.timeTemplate).replace(/^0+/u,"").toLowerCase()}tzTime(e){const t=this.setDate.slice(0,-6),a=new Date(t);return this.cap?a.toLocaleString(this.locale||"en-us",e).replace(/^0+/u,""):a.toLocaleString(this.locale||"en-us",e).replace(/^0+/u,"").replace("AM","am").replace("PM","pm")}whichDate(){let e="";switch(this.type){case"date":e=this.humanDate();break;case"tzDate":e=this.tzTime(this.dateTemplate);break;case"tzTime":e=this.tzTime(this.timeTemplate);break;case"time":e=this.humanTime();break;case"year":case"month":case"weekday":case"day":e=this.humanDateConversion();break;case"numeric":e=this.numericDate();break;default:this.humanDate()}return this.setDate&&!this.type||this.utc&&!this.type?this.humanDate():e}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{s as A};