deno.land / x / lume@v2.1.4 / tests / date.test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { assert, assertStrictEquals as equals } from "../deps/assert.ts";import lume from "../mod.ts";import date from "../plugins/date.ts";import { gl } from "npm:date-fns/locale/gl";import { pt } from "npm:date-fns/locale/pt";
const date0 = new Date(0);
Deno.test("date plugin", () => { const site = lume(); site.use(date({ formats: { "CUSTOM": "yyyy_dd", }, }));
const { helpers } = site.renderer;
assert(helpers.has("date"));
const [format] = helpers.get("date")!;
equals(format(date0, "yyyy-MM-dd"), "1970-01-01"); equals(format("now", "yyyy"), new Date().getFullYear().toString()); equals(format(date0), "1970-01-01"); equals(format(date0, "ATOM"), "1970-01-01T00:00:00Z"); equals(format(date0, "DATE"), "1970-01-01"); equals(format(date0, "DATETIME"), "1970-01-01 00:00:00"); equals(format(date0, "TIME"), "00:00:00"); equals(format(date0, "HUMAN_DATE"), "January 1st, 1970"); equals( format(date0, "HUMAN_DATETIME"), "January 1st, 1970 at 12:00:00 AM GMT+0", ); equals(format(date0, "CUSTOM"), "1970_01");});
Deno.test("date plugin formats: HUMAN_SINCE and HUMAN_SINCE_STRICT", () => { const site = lume(); site.use(date());
const { helpers } = site.renderer; assert(helpers.has("date")); const [format] = helpers.get("date")!;
const aBitMoreThanAYearFromNow = new Date( Date.now() + 367 * 24 * 60 * 60 * 1000, ); // See https://date-fns.org/v3.6.0/docs/formatDistanceToNow equals(format(aBitMoreThanAYearFromNow, "HUMAN_SINCE"), "about 1 year"); // See https://date-fns.org/v3.6.0/docs/formatDistanceToNowStrict equals(format(aBitMoreThanAYearFromNow, "HUMAN_SINCE_STRICT"), "1 year");});
Deno.test("date plugin with custom locale", async () => { const site = lume(); site.use(date({ locales: { gl, pt }, }));
await site.dispatchEvent({ type: "beforeBuild" });
const { helpers } = site.renderer; const [format] = helpers.get("date")!;
equals(format(date0, "HUMAN_DATE"), "1 de xaneiro 1970"); equals(format(date0, "HUMAN_DATE", "pt"), "1 de janeiro de 1970"); equals( format(date0, "HUMAN_DATETIME"), "1 de xaneiro 1970 ás 00:00:00 GMT+0", ); equals( format(date0, "HUMAN_DATETIME", "pt"), "1 de janeiro de 1970 às 00:00:00 GMT+0", );});
Deno.test("date plugin with custom name", async () => { const site = lume(); site.use(date({ name: "dateify", locales: { gl, pt }, }));
await site.dispatchEvent({ type: "beforeBuild" });
const { helpers } = site.renderer; const [format] = helpers.get("dateify")!;
equals(format(date0, "HUMAN_DATE"), "1 de xaneiro 1970");});
lume

Version Info

Tagged at
7 months ago