draft
This commit is contained in:
parent
65671ab7ba
commit
9c3ac133e3
23 changed files with 330 additions and 273 deletions
|
@ -0,0 +1,34 @@
|
|||
class TimeFormatted extends HTMLElement {
|
||||
|
||||
render() {
|
||||
let date = new Date(this.getAttribute('datetime') || Date.now());
|
||||
|
||||
this.innerHTML = new Intl.DateTimeFormat("default", {
|
||||
year: this.getAttribute('year') || undefined,
|
||||
month: this.getAttribute('month') || undefined,
|
||||
day: this.getAttribute('day') || undefined,
|
||||
hour: this.getAttribute('hour') || undefined,
|
||||
minute: this.getAttribute('minute') || undefined,
|
||||
second: this.getAttribute('second') || undefined,
|
||||
timeZoneName: this.getAttribute('time-zone-name') || undefined,
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
if (!this.rendered) {
|
||||
this.render();
|
||||
this.rendered = true;
|
||||
}
|
||||
}
|
||||
|
||||
static get observedAttributes() {
|
||||
return ['datetime', 'year', 'month', 'day', 'hour', 'minute', 'second', 'time-zone-name'];
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldValue, newValue) {
|
||||
this.render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
customElements.define("time-formatted", TimeFormatted);
|
Loading…
Add table
Add a link
Reference in a new issue