deno.land / std@0.224.0 / datetime / format_test.ts

format_test.ts
View Documentation
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals } from "../assert/mod.ts";import { format } from "./format.ts";
Deno.test({ name: "format()", fn: () => { // 00 hours assertEquals( "00:00:00", format(new Date("2019-01-01T00:00:00"), "HH:mm:ss"), ); assertEquals( "01:00:00", format(new Date("2019-01-01T01:00:00"), "HH:mm:ss"), ); assertEquals( "13:00:00", format(new Date("2019-01-01T13:00:00"), "HH:mm:ss"), );
// 12 hours assertEquals( "12:00:00", format(new Date("2019-01-01T00:00:00"), "hh:mm:ss"), ); assertEquals( "01:00:00", format(new Date("2019-01-01T01:00:00"), "hh:mm:ss"), ); assertEquals( "01:00:00", format(new Date("2019-01-01T13:00:00"), "hh:mm:ss"), );
// milliseconds assertEquals( "13:00:00.000", format(new Date("2019-01-01T13:00:00"), "HH:mm:ss.SSS"), ); assertEquals( "13:00:00.000", format(new Date("2019-01-01T13:00:00.000"), "HH:mm:ss.SSS"), ); assertEquals( "13:00:00.123", format(new Date("2019-01-01T13:00:00.123"), "HH:mm:ss.SSS"), );
// day period assertEquals( "00:00:00 AM", format(new Date("2019-01-01T00:00:00"), "HH:mm:ss a"), ); assertEquals( "12:00:00 AM", format(new Date("2019-01-01T00:00:00"), "hh:mm:ss a"), ); assertEquals( "01:00:00 AM", format(new Date("2019-01-01T01:00:00"), "HH:mm:ss a"), ); assertEquals( "01:00:00 AM", format(new Date("2019-01-01T01:00:00"), "hh:mm:ss a"), ); assertEquals( "01:00:00 PM", format(new Date("2019-01-01T13:00:00"), "hh:mm:ss a"), ); assertEquals( "21:00:00 PM", format(new Date("2019-01-01T21:00:00"), "HH:mm:ss a"), ); assertEquals( "09:00:00 PM", format(new Date("2019-01-01T21:00:00"), "hh:mm:ss a"), );
// quoted literal assertEquals( format(new Date(2019, 0, 20), "'today:' yyyy-MM-dd"), "today: 2019-01-20", );
assertEquals( format(new Date("2019-01-09T21:09:09"), "H:m:s yy-M-d"), "21:9:9 19-1-9", );
assertEquals( "13:00:00.00", format(new Date("2019-01-01T13:00:00.000"), "HH:mm:ss.SS"), );
assertEquals( "13:00:00.0", format(new Date("2019-01-01T13:00:00.000"), "HH:mm:ss.S"), );
assertEquals( "1", format(new Date("2019-01-01T13:00:00.000"), "h"), );
assertEquals( "2019-01-01 04:00:00.000", format( new Date("2019-01-01T13:00:00.000+09:00"), "yyyy-MM-dd HH:mm:ss.SSS", { utc: true }, ), );
assertEquals( "2019-01-01 18:00:00.000", format( new Date("2019-01-01T13:00:00.000-05:00"), "yyyy-MM-dd HH:mm:ss.SSS", { utc: true }, ), ); },});
std

Version Info

Tagged at
6 months ago