mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
* Fix time and date-time 12h formats (#16692) - am/pm check possible for other languages - adjusted date format gallery page for consistency - added gallery pages for date-time and time formats * Fix typo in am/pm check (#16692)
This commit is contained in:
parent
baaa012101
commit
922e95b895
24
gallery/src/data/date-options.ts
Normal file
24
gallery/src/data/date-options.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import type { ControlSelectOption } from "../../../src/components/ha-control-select";
|
||||||
|
|
||||||
|
export const timeOptions: ControlSelectOption[] = [
|
||||||
|
{
|
||||||
|
value: "now",
|
||||||
|
label: "Now",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "00:15:30",
|
||||||
|
label: "12:15:30 AM",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "06:15:30",
|
||||||
|
label: "06:15:30 AM",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "12:15:30",
|
||||||
|
label: "12:15:30 PM",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "18:15:30",
|
||||||
|
label: "06:15:30 PM",
|
||||||
|
},
|
||||||
|
];
|
7
gallery/src/pages/date-time/date-time-numeric.markdown
Normal file
7
gallery/src/pages/date-time/date-time-numeric.markdown
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: Date-Time Format (Numeric)
|
||||||
|
---
|
||||||
|
|
||||||
|
This pages lists all supported languages with their available date-time formats.
|
||||||
|
|
||||||
|
Formatting function: `const formatDateTimeNumeric: (dateObj: Date, locale: FrontendLocaleData) => string`
|
136
gallery/src/pages/date-time/date-time-numeric.ts
Normal file
136
gallery/src/pages/date-time/date-time-numeric.ts
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { html, css, LitElement } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import "../../../../src/components/ha-control-select";
|
||||||
|
import { translationMetadata } from "../../../../src/resources/translations-metadata";
|
||||||
|
import { formatDateTimeNumeric } from "../../../../src/common/datetime/format_date_time";
|
||||||
|
import { timeOptions } from "../../data/date-options";
|
||||||
|
import { demoConfig } from "../../../../src/fake_data/demo_config";
|
||||||
|
import {
|
||||||
|
FrontendLocaleData,
|
||||||
|
NumberFormat,
|
||||||
|
TimeFormat,
|
||||||
|
DateFormat,
|
||||||
|
FirstWeekday,
|
||||||
|
TimeZone,
|
||||||
|
} from "../../../../src/data/translation";
|
||||||
|
|
||||||
|
@customElement("demo-date-time-date-time-numeric")
|
||||||
|
export class DemoDateTimeDateTimeNumeric extends LitElement {
|
||||||
|
@state() private selection?: string = "now";
|
||||||
|
|
||||||
|
@state() private date: Date = new Date();
|
||||||
|
|
||||||
|
handleValueChanged(e: CustomEvent) {
|
||||||
|
this.selection = e.detail.value as string;
|
||||||
|
this.date = new Date();
|
||||||
|
if (this.selection !== "now") {
|
||||||
|
const [hours, minutes, seconds] = this.selection.split(":").map(Number);
|
||||||
|
this.date.setHours(hours);
|
||||||
|
this.date.setMinutes(minutes);
|
||||||
|
this.date.setSeconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const defaultLocale: FrontendLocaleData = {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
date_format: DateFormat.language,
|
||||||
|
first_weekday: FirstWeekday.language,
|
||||||
|
time_zone: TimeZone.local,
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<ha-control-select
|
||||||
|
.value=${this.selection}
|
||||||
|
.options=${timeOptions}
|
||||||
|
@value-changed=${this.handleValueChanged}
|
||||||
|
>
|
||||||
|
</ha-control-select>
|
||||||
|
<mwc-list>
|
||||||
|
<div class="container header">
|
||||||
|
<div>Language</div>
|
||||||
|
<div class="center">Default (lang)</div>
|
||||||
|
<div class="center">12 Hours</div>
|
||||||
|
<div class="center">24 Hours</div>
|
||||||
|
</div>
|
||||||
|
${Object.entries(translationMetadata.translations)
|
||||||
|
.filter(([key, _]) => key !== "test")
|
||||||
|
.map(
|
||||||
|
([key, value]) => html`
|
||||||
|
<div class="container">
|
||||||
|
<div>${value.nativeName}</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTimeNumeric(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTimeNumeric(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTimeNumeric(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles() {
|
||||||
|
return css`
|
||||||
|
ha-control-select {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 12px auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-date-time-date-time-numeric": DemoDateTimeDateTimeNumeric;
|
||||||
|
}
|
||||||
|
}
|
7
gallery/src/pages/date-time/date-time-seconds.markdown
Normal file
7
gallery/src/pages/date-time/date-time-seconds.markdown
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: Date-Time Format (Seconds)
|
||||||
|
---
|
||||||
|
|
||||||
|
This pages lists all supported languages with their available date-time formats.
|
||||||
|
|
||||||
|
Formatting function: `const formatDateTimeWithSeconds: (dateObj: Date, locale: FrontendLocaleData) => string`
|
136
gallery/src/pages/date-time/date-time-seconds.ts
Normal file
136
gallery/src/pages/date-time/date-time-seconds.ts
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { html, css, LitElement } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import "../../../../src/components/ha-control-select";
|
||||||
|
import { translationMetadata } from "../../../../src/resources/translations-metadata";
|
||||||
|
import { formatDateTimeWithSeconds } from "../../../../src/common/datetime/format_date_time";
|
||||||
|
import { timeOptions } from "../../data/date-options";
|
||||||
|
import { demoConfig } from "../../../../src/fake_data/demo_config";
|
||||||
|
import {
|
||||||
|
FrontendLocaleData,
|
||||||
|
NumberFormat,
|
||||||
|
TimeFormat,
|
||||||
|
DateFormat,
|
||||||
|
FirstWeekday,
|
||||||
|
TimeZone,
|
||||||
|
} from "../../../../src/data/translation";
|
||||||
|
|
||||||
|
@customElement("demo-date-time-date-time-seconds")
|
||||||
|
export class DemoDateTimeDateTimeSeconds extends LitElement {
|
||||||
|
@state() private selection?: string = "now";
|
||||||
|
|
||||||
|
@state() private date: Date = new Date();
|
||||||
|
|
||||||
|
handleValueChanged(e: CustomEvent) {
|
||||||
|
this.selection = e.detail.value as string;
|
||||||
|
this.date = new Date();
|
||||||
|
if (this.selection !== "now") {
|
||||||
|
const [hours, minutes, seconds] = this.selection.split(":").map(Number);
|
||||||
|
this.date.setHours(hours);
|
||||||
|
this.date.setMinutes(minutes);
|
||||||
|
this.date.setSeconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const defaultLocale: FrontendLocaleData = {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
date_format: DateFormat.language,
|
||||||
|
first_weekday: FirstWeekday.language,
|
||||||
|
time_zone: TimeZone.local,
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<ha-control-select
|
||||||
|
.value=${this.selection}
|
||||||
|
.options=${timeOptions}
|
||||||
|
@value-changed=${this.handleValueChanged}
|
||||||
|
>
|
||||||
|
</ha-control-select>
|
||||||
|
<mwc-list>
|
||||||
|
<div class="container header">
|
||||||
|
<div>Language</div>
|
||||||
|
<div class="center">Default (lang)</div>
|
||||||
|
<div class="center">12 Hours</div>
|
||||||
|
<div class="center">24 Hours</div>
|
||||||
|
</div>
|
||||||
|
${Object.entries(translationMetadata.translations)
|
||||||
|
.filter(([key, _]) => key !== "test")
|
||||||
|
.map(
|
||||||
|
([key, value]) => html`
|
||||||
|
<div class="container">
|
||||||
|
<div>${value.nativeName}</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTimeWithSeconds(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTimeWithSeconds(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTimeWithSeconds(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles() {
|
||||||
|
return css`
|
||||||
|
ha-control-select {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 12px auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-date-time-date-time-seconds": DemoDateTimeDateTimeSeconds;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: Date-Time Format (Short w/ Year)
|
||||||
|
---
|
||||||
|
|
||||||
|
This pages lists all supported languages with their available date-time formats.
|
||||||
|
|
||||||
|
Formatting function: `const formatShortDateTimeWithYear: (dateObj: Date, locale: FrontendLocaleData) => string`
|
136
gallery/src/pages/date-time/date-time-short-year.ts
Normal file
136
gallery/src/pages/date-time/date-time-short-year.ts
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { html, css, LitElement } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import "../../../../src/components/ha-control-select";
|
||||||
|
import { translationMetadata } from "../../../../src/resources/translations-metadata";
|
||||||
|
import { formatShortDateTimeWithYear } from "../../../../src/common/datetime/format_date_time";
|
||||||
|
import { timeOptions } from "../../data/date-options";
|
||||||
|
import { demoConfig } from "../../../../src/fake_data/demo_config";
|
||||||
|
import {
|
||||||
|
FrontendLocaleData,
|
||||||
|
NumberFormat,
|
||||||
|
TimeFormat,
|
||||||
|
DateFormat,
|
||||||
|
FirstWeekday,
|
||||||
|
TimeZone,
|
||||||
|
} from "../../../../src/data/translation";
|
||||||
|
|
||||||
|
@customElement("demo-date-time-date-time-short-year")
|
||||||
|
export class DemoDateTimeDateTimeShortYear extends LitElement {
|
||||||
|
@state() private selection?: string = "now";
|
||||||
|
|
||||||
|
@state() private date: Date = new Date();
|
||||||
|
|
||||||
|
handleValueChanged(e: CustomEvent) {
|
||||||
|
this.selection = e.detail.value as string;
|
||||||
|
this.date = new Date();
|
||||||
|
if (this.selection !== "now") {
|
||||||
|
const [hours, minutes, seconds] = this.selection.split(":").map(Number);
|
||||||
|
this.date.setHours(hours);
|
||||||
|
this.date.setMinutes(minutes);
|
||||||
|
this.date.setSeconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const defaultLocale: FrontendLocaleData = {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
date_format: DateFormat.language,
|
||||||
|
first_weekday: FirstWeekday.language,
|
||||||
|
time_zone: TimeZone.local,
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<ha-control-select
|
||||||
|
.value=${this.selection}
|
||||||
|
.options=${timeOptions}
|
||||||
|
@value-changed=${this.handleValueChanged}
|
||||||
|
>
|
||||||
|
</ha-control-select>
|
||||||
|
<mwc-list>
|
||||||
|
<div class="container header">
|
||||||
|
<div>Language</div>
|
||||||
|
<div class="center">Default (lang)</div>
|
||||||
|
<div class="center">12 Hours</div>
|
||||||
|
<div class="center">24 Hours</div>
|
||||||
|
</div>
|
||||||
|
${Object.entries(translationMetadata.translations)
|
||||||
|
.filter(([key, _]) => key !== "test")
|
||||||
|
.map(
|
||||||
|
([key, value]) => html`
|
||||||
|
<div class="container">
|
||||||
|
<div>${value.nativeName}</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatShortDateTimeWithYear(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatShortDateTimeWithYear(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatShortDateTimeWithYear(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles() {
|
||||||
|
return css`
|
||||||
|
ha-control-select {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 12px auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-date-time-date-time-short-year": DemoDateTimeDateTimeShortYear;
|
||||||
|
}
|
||||||
|
}
|
7
gallery/src/pages/date-time/date-time-short.markdown
Normal file
7
gallery/src/pages/date-time/date-time-short.markdown
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: Date-Time Format (Short)
|
||||||
|
---
|
||||||
|
|
||||||
|
This pages lists all supported languages with their available date-time formats.
|
||||||
|
|
||||||
|
Formatting function: `const formatShortDateTime: (dateObj: Date, locale: FrontendLocaleData) => string`
|
136
gallery/src/pages/date-time/date-time-short.ts
Normal file
136
gallery/src/pages/date-time/date-time-short.ts
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { html, css, LitElement } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import "../../../../src/components/ha-control-select";
|
||||||
|
import { translationMetadata } from "../../../../src/resources/translations-metadata";
|
||||||
|
import { formatShortDateTime } from "../../../../src/common/datetime/format_date_time";
|
||||||
|
import { timeOptions } from "../../data/date-options";
|
||||||
|
import { demoConfig } from "../../../../src/fake_data/demo_config";
|
||||||
|
import {
|
||||||
|
FrontendLocaleData,
|
||||||
|
NumberFormat,
|
||||||
|
TimeFormat,
|
||||||
|
DateFormat,
|
||||||
|
FirstWeekday,
|
||||||
|
TimeZone,
|
||||||
|
} from "../../../../src/data/translation";
|
||||||
|
|
||||||
|
@customElement("demo-date-time-date-time-short")
|
||||||
|
export class DemoDateTimeDateTimeShort extends LitElement {
|
||||||
|
@state() private selection?: string = "now";
|
||||||
|
|
||||||
|
@state() private date: Date = new Date();
|
||||||
|
|
||||||
|
handleValueChanged(e: CustomEvent) {
|
||||||
|
this.selection = e.detail.value as string;
|
||||||
|
this.date = new Date();
|
||||||
|
if (this.selection !== "now") {
|
||||||
|
const [hours, minutes, seconds] = this.selection.split(":").map(Number);
|
||||||
|
this.date.setHours(hours);
|
||||||
|
this.date.setMinutes(minutes);
|
||||||
|
this.date.setSeconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const defaultLocale: FrontendLocaleData = {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
date_format: DateFormat.language,
|
||||||
|
first_weekday: FirstWeekday.language,
|
||||||
|
time_zone: TimeZone.local,
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<ha-control-select
|
||||||
|
.value=${this.selection}
|
||||||
|
.options=${timeOptions}
|
||||||
|
@value-changed=${this.handleValueChanged}
|
||||||
|
>
|
||||||
|
</ha-control-select>
|
||||||
|
<mwc-list>
|
||||||
|
<div class="container header">
|
||||||
|
<div>Language</div>
|
||||||
|
<div class="center">Default (lang)</div>
|
||||||
|
<div class="center">12 Hours</div>
|
||||||
|
<div class="center">24 Hours</div>
|
||||||
|
</div>
|
||||||
|
${Object.entries(translationMetadata.translations)
|
||||||
|
.filter(([key, _]) => key !== "test")
|
||||||
|
.map(
|
||||||
|
([key, value]) => html`
|
||||||
|
<div class="container">
|
||||||
|
<div>${value.nativeName}</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatShortDateTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatShortDateTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatShortDateTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles() {
|
||||||
|
return css`
|
||||||
|
ha-control-select {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 12px auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-date-time-date-time-short": DemoDateTimeDateTimeShort;
|
||||||
|
}
|
||||||
|
}
|
7
gallery/src/pages/date-time/date-time.markdown
Normal file
7
gallery/src/pages/date-time/date-time.markdown
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: Date-Time Format
|
||||||
|
---
|
||||||
|
|
||||||
|
This pages lists all supported languages with their available date-time formats.
|
||||||
|
|
||||||
|
Formatting function: `const formatDateTime: (dateObj: Date, locale: FrontendLocaleData) => string`
|
136
gallery/src/pages/date-time/date-time.ts
Normal file
136
gallery/src/pages/date-time/date-time.ts
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { html, css, LitElement } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import "../../../../src/components/ha-control-select";
|
||||||
|
import { translationMetadata } from "../../../../src/resources/translations-metadata";
|
||||||
|
import { formatDateTime } from "../../../../src/common/datetime/format_date_time";
|
||||||
|
import { timeOptions } from "../../data/date-options";
|
||||||
|
import { demoConfig } from "../../../../src/fake_data/demo_config";
|
||||||
|
import {
|
||||||
|
FrontendLocaleData,
|
||||||
|
NumberFormat,
|
||||||
|
TimeFormat,
|
||||||
|
DateFormat,
|
||||||
|
FirstWeekday,
|
||||||
|
TimeZone,
|
||||||
|
} from "../../../../src/data/translation";
|
||||||
|
|
||||||
|
@customElement("demo-date-time-date-time")
|
||||||
|
export class DemoDateTimeDateTime extends LitElement {
|
||||||
|
@state() private selection?: string = "now";
|
||||||
|
|
||||||
|
@state() private date: Date = new Date();
|
||||||
|
|
||||||
|
handleValueChanged(e: CustomEvent) {
|
||||||
|
this.selection = e.detail.value as string;
|
||||||
|
this.date = new Date();
|
||||||
|
if (this.selection !== "now") {
|
||||||
|
const [hours, minutes, seconds] = this.selection.split(":").map(Number);
|
||||||
|
this.date.setHours(hours);
|
||||||
|
this.date.setMinutes(minutes);
|
||||||
|
this.date.setSeconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const defaultLocale: FrontendLocaleData = {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
date_format: DateFormat.language,
|
||||||
|
first_weekday: FirstWeekday.language,
|
||||||
|
time_zone: TimeZone.local,
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<ha-control-select
|
||||||
|
.value=${this.selection}
|
||||||
|
.options=${timeOptions}
|
||||||
|
@value-changed=${this.handleValueChanged}
|
||||||
|
>
|
||||||
|
</ha-control-select>
|
||||||
|
<mwc-list>
|
||||||
|
<div class="container header">
|
||||||
|
<div>Language</div>
|
||||||
|
<div class="center">Default (lang)</div>
|
||||||
|
<div class="center">12 Hours</div>
|
||||||
|
<div class="center">24 Hours</div>
|
||||||
|
</div>
|
||||||
|
${Object.entries(translationMetadata.translations)
|
||||||
|
.filter(([key, _]) => key !== "test")
|
||||||
|
.map(
|
||||||
|
([key, value]) => html`
|
||||||
|
<div class="container">
|
||||||
|
<div>${value.nativeName}</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatDateTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles() {
|
||||||
|
return css`
|
||||||
|
ha-control-select {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 900px;
|
||||||
|
margin: 12px auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-date-time-date-time": DemoDateTimeDateTime;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
title: (Numeric) Date Formatting
|
title: Date Format (Numeric)
|
||||||
---
|
---
|
||||||
|
|
||||||
This pages lists all supported languages with their available (numeric) date formats.
|
This pages lists all supported languages with their available (numeric) date formats.
|
||||||
|
7
gallery/src/pages/date-time/time-seconds.markdown
Normal file
7
gallery/src/pages/date-time/time-seconds.markdown
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: Time Format (Seconds)
|
||||||
|
---
|
||||||
|
|
||||||
|
This pages lists all supported languages with their available time formats.
|
||||||
|
|
||||||
|
Formatting function: `const formatTimeWithSeconds: (dateObj: Date, locale: FrontendLocaleData) => string`
|
135
gallery/src/pages/date-time/time-seconds.ts
Normal file
135
gallery/src/pages/date-time/time-seconds.ts
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
import { html, css, LitElement } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import { translationMetadata } from "../../../../src/resources/translations-metadata";
|
||||||
|
import { formatTimeWithSeconds } from "../../../../src/common/datetime/format_time";
|
||||||
|
import { timeOptions } from "../../data/date-options";
|
||||||
|
import { demoConfig } from "../../../../src/fake_data/demo_config";
|
||||||
|
import {
|
||||||
|
FrontendLocaleData,
|
||||||
|
NumberFormat,
|
||||||
|
TimeFormat,
|
||||||
|
DateFormat,
|
||||||
|
FirstWeekday,
|
||||||
|
TimeZone,
|
||||||
|
} from "../../../../src/data/translation";
|
||||||
|
|
||||||
|
@customElement("demo-date-time-time-seconds")
|
||||||
|
export class DemoDateTimeTimeSeconds extends LitElement {
|
||||||
|
@state() private selection?: string = "now";
|
||||||
|
|
||||||
|
@state() private date: Date = new Date();
|
||||||
|
|
||||||
|
handleValueChanged(e: CustomEvent) {
|
||||||
|
this.selection = e.detail.value as string;
|
||||||
|
this.date = new Date();
|
||||||
|
if (this.selection !== "now") {
|
||||||
|
const [hours, minutes, seconds] = this.selection.split(":").map(Number);
|
||||||
|
this.date.setHours(hours);
|
||||||
|
this.date.setMinutes(minutes);
|
||||||
|
this.date.setSeconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const defaultLocale: FrontendLocaleData = {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
date_format: DateFormat.language,
|
||||||
|
first_weekday: FirstWeekday.language,
|
||||||
|
time_zone: TimeZone.local,
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<ha-control-select
|
||||||
|
.value=${this.selection}
|
||||||
|
.options=${timeOptions}
|
||||||
|
@value-changed=${this.handleValueChanged}
|
||||||
|
>
|
||||||
|
</ha-control-select>
|
||||||
|
<mwc-list>
|
||||||
|
<div class="container header">
|
||||||
|
<div>Language</div>
|
||||||
|
<div class="center">Default (lang)</div>
|
||||||
|
<div class="center">12 Hours</div>
|
||||||
|
<div class="center">24 Hours</div>
|
||||||
|
</div>
|
||||||
|
${Object.entries(translationMetadata.translations)
|
||||||
|
.filter(([key, _]) => key !== "test")
|
||||||
|
.map(
|
||||||
|
([key, value]) => html`
|
||||||
|
<div class="container">
|
||||||
|
<div>${value.nativeName}</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTimeWithSeconds(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTimeWithSeconds(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTimeWithSeconds(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles() {
|
||||||
|
return css`
|
||||||
|
ha-control-select {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 12px auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-date-time-time-seconds": DemoDateTimeTimeSeconds;
|
||||||
|
}
|
||||||
|
}
|
7
gallery/src/pages/date-time/time-weekday.markdown
Normal file
7
gallery/src/pages/date-time/time-weekday.markdown
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: Time Format (Weekday)
|
||||||
|
---
|
||||||
|
|
||||||
|
This pages lists all supported languages with their available time formats.
|
||||||
|
|
||||||
|
Formatting function: `const formatTimeWeekday: (dateObj: Date, locale: FrontendLocaleData) => string`
|
135
gallery/src/pages/date-time/time-weekday.ts
Normal file
135
gallery/src/pages/date-time/time-weekday.ts
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
import { html, css, LitElement } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import { translationMetadata } from "../../../../src/resources/translations-metadata";
|
||||||
|
import { formatTimeWeekday } from "../../../../src/common/datetime/format_time";
|
||||||
|
import { timeOptions } from "../../data/date-options";
|
||||||
|
import { demoConfig } from "../../../../src/fake_data/demo_config";
|
||||||
|
import {
|
||||||
|
FrontendLocaleData,
|
||||||
|
NumberFormat,
|
||||||
|
TimeFormat,
|
||||||
|
DateFormat,
|
||||||
|
FirstWeekday,
|
||||||
|
TimeZone,
|
||||||
|
} from "../../../../src/data/translation";
|
||||||
|
|
||||||
|
@customElement("demo-date-time-time-weekday")
|
||||||
|
export class DemoDateTimeTimeWeekday extends LitElement {
|
||||||
|
@state() private selection?: string = "now";
|
||||||
|
|
||||||
|
@state() private date: Date = new Date();
|
||||||
|
|
||||||
|
handleValueChanged(e: CustomEvent) {
|
||||||
|
this.selection = e.detail.value as string;
|
||||||
|
this.date = new Date();
|
||||||
|
if (this.selection !== "now") {
|
||||||
|
const [hours, minutes, seconds] = this.selection.split(":").map(Number);
|
||||||
|
this.date.setHours(hours);
|
||||||
|
this.date.setMinutes(minutes);
|
||||||
|
this.date.setSeconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const defaultLocale: FrontendLocaleData = {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
date_format: DateFormat.language,
|
||||||
|
first_weekday: FirstWeekday.language,
|
||||||
|
time_zone: TimeZone.local,
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<ha-control-select
|
||||||
|
.value=${this.selection}
|
||||||
|
.options=${timeOptions}
|
||||||
|
@value-changed=${this.handleValueChanged}
|
||||||
|
>
|
||||||
|
</ha-control-select>
|
||||||
|
<mwc-list>
|
||||||
|
<div class="container header">
|
||||||
|
<div>Language</div>
|
||||||
|
<div class="center">Default (lang)</div>
|
||||||
|
<div class="center">12 Hours</div>
|
||||||
|
<div class="center">24 Hours</div>
|
||||||
|
</div>
|
||||||
|
${Object.entries(translationMetadata.translations)
|
||||||
|
.filter(([key, _]) => key !== "test")
|
||||||
|
.map(
|
||||||
|
([key, value]) => html`
|
||||||
|
<div class="container">
|
||||||
|
<div>${value.nativeName}</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTimeWeekday(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTimeWeekday(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTimeWeekday(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles() {
|
||||||
|
return css`
|
||||||
|
ha-control-select {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-date-time-time-weekday": DemoDateTimeTimeWeekday;
|
||||||
|
}
|
||||||
|
}
|
7
gallery/src/pages/date-time/time.markdown
Normal file
7
gallery/src/pages/date-time/time.markdown
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
title: Time Format
|
||||||
|
---
|
||||||
|
|
||||||
|
This pages lists all supported languages with their available time formats.
|
||||||
|
|
||||||
|
Formatting function: `const formatTime: (dateObj: Date, locale: FrontendLocaleData) => string`
|
136
gallery/src/pages/date-time/time.ts
Normal file
136
gallery/src/pages/date-time/time.ts
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
import { html, css, LitElement } from "lit";
|
||||||
|
import { customElement, state } from "lit/decorators";
|
||||||
|
import "../../../../src/components/ha-card";
|
||||||
|
import "../../../../src/components/ha-control-select";
|
||||||
|
import { translationMetadata } from "../../../../src/resources/translations-metadata";
|
||||||
|
import { formatTime } from "../../../../src/common/datetime/format_time";
|
||||||
|
import { timeOptions } from "../../data/date-options";
|
||||||
|
import { demoConfig } from "../../../../src/fake_data/demo_config";
|
||||||
|
import {
|
||||||
|
FrontendLocaleData,
|
||||||
|
NumberFormat,
|
||||||
|
TimeFormat,
|
||||||
|
DateFormat,
|
||||||
|
FirstWeekday,
|
||||||
|
TimeZone,
|
||||||
|
} from "../../../../src/data/translation";
|
||||||
|
|
||||||
|
@customElement("demo-date-time-time")
|
||||||
|
export class DemoDateTimeTime extends LitElement {
|
||||||
|
@state() private selection?: string = "now";
|
||||||
|
|
||||||
|
@state() private date: Date = new Date();
|
||||||
|
|
||||||
|
handleValueChanged(e: CustomEvent) {
|
||||||
|
this.selection = e.detail.value as string;
|
||||||
|
this.date = new Date();
|
||||||
|
if (this.selection !== "now") {
|
||||||
|
const [hours, minutes, seconds] = this.selection.split(":").map(Number);
|
||||||
|
this.date.setHours(hours);
|
||||||
|
this.date.setMinutes(minutes);
|
||||||
|
this.date.setSeconds(seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render() {
|
||||||
|
const defaultLocale: FrontendLocaleData = {
|
||||||
|
language: "en",
|
||||||
|
number_format: NumberFormat.language,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
date_format: DateFormat.language,
|
||||||
|
first_weekday: FirstWeekday.language,
|
||||||
|
time_zone: TimeZone.local,
|
||||||
|
};
|
||||||
|
return html`
|
||||||
|
<ha-control-select
|
||||||
|
.value=${this.selection}
|
||||||
|
.options=${timeOptions}
|
||||||
|
@value-changed=${this.handleValueChanged}
|
||||||
|
>
|
||||||
|
</ha-control-select>
|
||||||
|
<mwc-list>
|
||||||
|
<div class="container header">
|
||||||
|
<div>Language</div>
|
||||||
|
<div class="center">Default (lang)</div>
|
||||||
|
<div class="center">12 Hours</div>
|
||||||
|
<div class="center">24 Hours</div>
|
||||||
|
</div>
|
||||||
|
${Object.entries(translationMetadata.translations)
|
||||||
|
.filter(([key, _]) => key !== "test")
|
||||||
|
.map(
|
||||||
|
([key, value]) => html`
|
||||||
|
<div class="container">
|
||||||
|
<div>${value.nativeName}</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.language,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.am_pm,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div class="center">
|
||||||
|
${formatTime(
|
||||||
|
this.date,
|
||||||
|
{
|
||||||
|
...defaultLocale,
|
||||||
|
language: key,
|
||||||
|
time_format: TimeFormat.twenty_four,
|
||||||
|
},
|
||||||
|
demoConfig
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</mwc-list>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles() {
|
||||||
|
return css`
|
||||||
|
ha-control-select {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 12px auto;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 12px auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container > div {
|
||||||
|
flex-grow: 1;
|
||||||
|
width: 20%;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"demo-date-time-time": DemoDateTimeTime;
|
||||||
|
}
|
||||||
|
}
|
@ -15,20 +15,15 @@ export const formatDateTime = (
|
|||||||
|
|
||||||
const formatDateTimeMem = memoizeOne(
|
const formatDateTimeMem = memoizeOne(
|
||||||
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
||||||
new Intl.DateTimeFormat(
|
new Intl.DateTimeFormat(locale.language, {
|
||||||
locale.language === "en" && !useAmPm(locale)
|
year: "numeric",
|
||||||
? "en-u-hc-h23"
|
month: "long",
|
||||||
: locale.language,
|
day: "numeric",
|
||||||
{
|
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
||||||
year: "numeric",
|
minute: "2-digit",
|
||||||
month: "long",
|
hourCycle: useAmPm(locale) ? "h12" : "h23",
|
||||||
day: "numeric",
|
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
||||||
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
})
|
||||||
minute: "2-digit",
|
|
||||||
hour12: useAmPm(locale),
|
|
||||||
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Aug 9, 2021, 8:23 AM
|
// Aug 9, 2021, 8:23 AM
|
||||||
@ -40,20 +35,15 @@ export const formatShortDateTimeWithYear = (
|
|||||||
|
|
||||||
const formatShortDateTimeWithYearMem = memoizeOne(
|
const formatShortDateTimeWithYearMem = memoizeOne(
|
||||||
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
||||||
new Intl.DateTimeFormat(
|
new Intl.DateTimeFormat(locale.language, {
|
||||||
locale.language === "en" && !useAmPm(locale)
|
year: "numeric",
|
||||||
? "en-u-hc-h23"
|
month: "short",
|
||||||
: locale.language,
|
day: "numeric",
|
||||||
{
|
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
||||||
year: "numeric",
|
minute: "2-digit",
|
||||||
month: "short",
|
hourCycle: useAmPm(locale) ? "h12" : "h23",
|
||||||
day: "numeric",
|
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
||||||
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
})
|
||||||
minute: "2-digit",
|
|
||||||
hour12: useAmPm(locale),
|
|
||||||
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Aug 9, 8:23 AM
|
// Aug 9, 8:23 AM
|
||||||
@ -65,19 +55,14 @@ export const formatShortDateTime = (
|
|||||||
|
|
||||||
const formatShortDateTimeMem = memoizeOne(
|
const formatShortDateTimeMem = memoizeOne(
|
||||||
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
||||||
new Intl.DateTimeFormat(
|
new Intl.DateTimeFormat(locale.language, {
|
||||||
locale.language === "en" && !useAmPm(locale)
|
month: "short",
|
||||||
? "en-u-hc-h23"
|
day: "numeric",
|
||||||
: locale.language,
|
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
||||||
{
|
minute: "2-digit",
|
||||||
month: "short",
|
hourCycle: useAmPm(locale) ? "h12" : "h23",
|
||||||
day: "numeric",
|
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
||||||
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
})
|
||||||
minute: "2-digit",
|
|
||||||
hour12: useAmPm(locale),
|
|
||||||
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// August 9, 2021, 8:23:15 AM
|
// August 9, 2021, 8:23:15 AM
|
||||||
@ -89,21 +74,16 @@ export const formatDateTimeWithSeconds = (
|
|||||||
|
|
||||||
const formatDateTimeWithSecondsMem = memoizeOne(
|
const formatDateTimeWithSecondsMem = memoizeOne(
|
||||||
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
||||||
new Intl.DateTimeFormat(
|
new Intl.DateTimeFormat(locale.language, {
|
||||||
locale.language === "en" && !useAmPm(locale)
|
year: "numeric",
|
||||||
? "en-u-hc-h23"
|
month: "long",
|
||||||
: locale.language,
|
day: "numeric",
|
||||||
{
|
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
||||||
year: "numeric",
|
minute: "2-digit",
|
||||||
month: "long",
|
second: "2-digit",
|
||||||
day: "numeric",
|
hourCycle: useAmPm(locale) ? "h12" : "h23",
|
||||||
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
||||||
minute: "2-digit",
|
})
|
||||||
second: "2-digit",
|
|
||||||
hour12: useAmPm(locale),
|
|
||||||
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// 9/8/2021, 8:23 AM
|
// 9/8/2021, 8:23 AM
|
||||||
|
@ -13,17 +13,12 @@ export const formatTime = (
|
|||||||
|
|
||||||
const formatTimeMem = memoizeOne(
|
const formatTimeMem = memoizeOne(
|
||||||
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
||||||
new Intl.DateTimeFormat(
|
new Intl.DateTimeFormat(locale.language, {
|
||||||
locale.language === "en" && !useAmPm(locale)
|
hour: "numeric",
|
||||||
? "en-u-hc-h23"
|
minute: "2-digit",
|
||||||
: locale.language,
|
hourCycle: useAmPm(locale) ? "h12" : "h23",
|
||||||
{
|
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
||||||
hour: "numeric",
|
})
|
||||||
minute: "2-digit",
|
|
||||||
hour12: useAmPm(locale),
|
|
||||||
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// 9:15:24 PM || 21:15:24
|
// 9:15:24 PM || 21:15:24
|
||||||
@ -35,18 +30,13 @@ export const formatTimeWithSeconds = (
|
|||||||
|
|
||||||
const formatTimeWithSecondsMem = memoizeOne(
|
const formatTimeWithSecondsMem = memoizeOne(
|
||||||
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
||||||
new Intl.DateTimeFormat(
|
new Intl.DateTimeFormat(locale.language, {
|
||||||
locale.language === "en" && !useAmPm(locale)
|
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
||||||
? "en-u-hc-h23"
|
minute: "2-digit",
|
||||||
: locale.language,
|
second: "2-digit",
|
||||||
{
|
hourCycle: useAmPm(locale) ? "h12" : "h23",
|
||||||
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
||||||
minute: "2-digit",
|
})
|
||||||
second: "2-digit",
|
|
||||||
hour12: useAmPm(locale),
|
|
||||||
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Tuesday 7:00 PM || Tuesday 19:00
|
// Tuesday 7:00 PM || Tuesday 19:00
|
||||||
@ -58,18 +48,13 @@ export const formatTimeWeekday = (
|
|||||||
|
|
||||||
const formatTimeWeekdayMem = memoizeOne(
|
const formatTimeWeekdayMem = memoizeOne(
|
||||||
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
||||||
new Intl.DateTimeFormat(
|
new Intl.DateTimeFormat(locale.language, {
|
||||||
locale.language === "en" && !useAmPm(locale)
|
weekday: "long",
|
||||||
? "en-u-hc-h23"
|
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
||||||
: locale.language,
|
minute: "2-digit",
|
||||||
{
|
hourCycle: useAmPm(locale) ? "h12" : "h23",
|
||||||
weekday: "long",
|
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
||||||
hour: useAmPm(locale) ? "numeric" : "2-digit",
|
})
|
||||||
minute: "2-digit",
|
|
||||||
hour12: useAmPm(locale),
|
|
||||||
timeZone: locale.time_zone === "server" ? serverTimeZone : undefined,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// 21:15
|
// 21:15
|
||||||
|
@ -8,8 +8,10 @@ export const useAmPm = memoizeOne((locale: FrontendLocaleData): boolean => {
|
|||||||
) {
|
) {
|
||||||
const testLanguage =
|
const testLanguage =
|
||||||
locale.time_format === TimeFormat.language ? locale.language : undefined;
|
locale.time_format === TimeFormat.language ? locale.language : undefined;
|
||||||
const test = new Date().toLocaleString(testLanguage);
|
const test = new Date("January 1, 2023 22:00:00").toLocaleString(
|
||||||
return test.includes("AM") || test.includes("PM");
|
testLanguage
|
||||||
|
);
|
||||||
|
return test.includes("10");
|
||||||
}
|
}
|
||||||
|
|
||||||
return locale.time_format === TimeFormat.am_pm;
|
return locale.time_format === TimeFormat.am_pm;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user