@@ -15,11 +15,64 @@ test('toDate()', () => {
15
15
} ) ;
16
16
17
17
test ( 'create record with time field' , ( ) => {
18
- const t = createData ( new Date ( 0 ) ) as Time ;
18
+ const t = createData ( new Date ( 0 ) ) as unknown as Time ;
19
19
expect ( t . toDate ( ) ) . toEqual ( new Date ( 0 ) ) ;
20
20
} ) ;
21
21
22
22
test ( 'keeps the milliseconds' , ( ) => {
23
23
const date = new Time ( '2020-02-25T16:03:17.838527Z' ) . toDate ( ) ;
24
24
expect ( date ?. toISOString ( ) ) . toEqual ( '2020-02-25T16:03:17.838Z' ) ;
25
25
} ) ;
26
+
27
+ test ( 'format with strftime with default' , ( ) => {
28
+ const time = new Time ( '2000-01-01T00:00:00Z' ) ;
29
+ expect ( time . format ( ) ) . toBe ( '2000-01-01T00:00:00.000+00:00' ) ;
30
+ } ) ;
31
+
32
+ test ( 'format in new york' , ( ) => {
33
+ const time = new Time ( '2000-01-01T00:00:00Z' ) ;
34
+ time . zone = 'America/New_York' ;
35
+ expect ( time . format ( ) ) . toBe ( '1999-12-31T19:00:00.000-05:00' ) ;
36
+ } ) ;
37
+
38
+ test ( 'format in los angeles' , ( ) => {
39
+ const time = new Time ( '2000-01-01T00:00:00Z' ) ;
40
+ Time . config . zone = 'America/Los_Angeles' ;
41
+ expect ( time . format ( ) ) . toEqual ( '1999-12-31T16:00:00.000-08:00' ) ;
42
+ } ) ;
43
+
44
+ test ( 'format using local specifier and static ime zone' , ( ) => {
45
+ const time = new Time ( '2000-01-01T00:00:00Z' ) ;
46
+ Time . config . zone = 'Asia/Bangkok' ;
47
+ expect ( time . format ( '%a, %B %d %Y at %H:%M, %z' ) ) . toEqual (
48
+ 'Sat, January 01 2000 at 07:00, +0700'
49
+ ) ;
50
+ } ) ;
51
+
52
+ test ( 'format using static format' , ( ) => {
53
+ const time = new Time ( '2000-01-01T00:00:00Z' ) ;
54
+ Time . config . zone = 'America/New_York' ;
55
+ Time . config . format = '%a, %B %d %Y at %H:%M, %z' ;
56
+ expect ( time . format ( ) ) . toEqual ( 'Fri, December 31 1999 at 19:00, -0500' ) ;
57
+ } ) ;
58
+
59
+ test ( 'toString when nothing is set' , ( ) => {
60
+ Time . config . zone = null ;
61
+ Time . config . format = null ;
62
+ const time = new Time ( '2000-01-01T00:00:00Z' ) ;
63
+ expect ( time . toString ( ) ) . toBe ( time . value ) ;
64
+ } ) ;
65
+
66
+ test ( 'toString when zone is set' , ( ) => {
67
+ Time . config . zone = 'America/New_York' ;
68
+ Time . config . format = null ;
69
+ const time = new Time ( '1999-12-31T19:00:00.000-05:00' ) ;
70
+ expect ( time . toString ( ) ) . toBe ( time . value ) ;
71
+ } ) ;
72
+
73
+ test ( 'toString when format is set' , ( ) => {
74
+ Time . config . zone = null ;
75
+ Time . config . format = '%A' ;
76
+ const time = new Time ( '1999-12-31T19:00:00.000-05:00' ) ;
77
+ expect ( time . toString ( ) ) . toBe ( 'Saturday' ) ;
78
+ } ) ;
0 commit comments