Skip to content

Commit 71391db

Browse files
committed
maint(pat display time): Document preference of setting the language as lang attribute.
1 parent bbf7a6c commit 71391db

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/pat/display-time/display-time.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ describe("pat-display-time tests", () => {
5959
expect(el.textContent).toBe("April Donnerstag 22. 2021, 4:00:00");
6060
});
6161

62+
it("Example setting the output format explicitly in German using the lang attribute", async () => {
63+
document.body.innerHTML = `
64+
<time
65+
class="pat-display-time"
66+
datetime="2021-04-22T23:00Z"
67+
lang="de"
68+
data-pat-display-time="output-format: MMMM dddd Do YYYY, h:mm:ss">
69+
</time>
70+
`;
71+
const el = document.querySelector(".pat-display-time");
72+
73+
Pattern.init(el);
74+
await utils.timeout(1); // wait a tick for async to settle.
75+
76+
expect(el.textContent).toBe("April Donnerstag 22. 2021, 4:00:00");
77+
});
78+
6279
it("Example setting the output format in German due containment in German container", async () => {
6380
document.body.innerHTML = `
6481
<section lang="de">
@@ -139,6 +156,23 @@ describe("pat-display-time tests", () => {
139156
expect(el.textContent.indexOf("Jahre") >= 0).toBe(true);
140157
});
141158

159+
it("Output formatted as 'from now' with no suffix in german using the lang attribute", async () => {
160+
document.body.innerHTML = `
161+
<time
162+
class="pat-display-time"
163+
datetime="2000-04-22T10:00Z"
164+
lang="de"
165+
data-pat-display-time="from-now: true; no-suffix: true">
166+
</time>
167+
`;
168+
const el = document.querySelector(".pat-display-time");
169+
170+
Pattern.init(el);
171+
await utils.timeout(1); // wait a tick for async to settle.
172+
173+
expect(el.textContent.indexOf("Jahre") >= 0).toBe(true);
174+
});
175+
142176
it("Formating empty datetime clears the display.", async () => {
143177
document.body.innerHTML = `
144178
<time class="pat-display-time">

src/pat/display-time/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ <h3>Code</h3>
162162
&lt;time
163163
class="pat-display-time"
164164
datetime="2015-01-20T08:00Z"
165-
data-pat-display-time="from-now: true; no-suffix: true; locale: de"&gt;
165+
lang="de"
166+
data-pat-display-time="from-now: true; no-suffix: true"
167+
&gt;
166168
20 January 2015, 08:00
167169
&lt;/time&gt;
168170
</pre>
@@ -173,7 +175,8 @@ <h3>Output</h3>
173175
<time
174176
class="pat-display-time"
175177
datetime="2015-01-20T08:00Z"
176-
data-pat-display-time="from-now: true; no-suffix: true; locale: de"
178+
lang="de"
179+
data-pat-display-time="from-now: true; no-suffix: true"
177180
>
178181
20 January 2015, 08:00
179182
</time>

0 commit comments

Comments
 (0)