@@ -22,6 +22,115 @@ suite(`${pkg.name} unit`, () => {
2222
2323 assert . deepStrictEqual ( next . toString ( ) , Temporal . Instant . from ( '2020-04-16T13:00:00.0Z' ) . toString ( ) )
2424 } )
25+
26+ test ( 'DST - spring forward' , ( ) => {
27+ // 2024-03-10 - spring forward in US
28+ const springForwardDate = Temporal . Instant . from ( '2024-03-10T13:00:00.0Z' )
29+ const chicagoTime = springForwardDate . toZonedDateTimeISO ( 'America/Chicago' )
30+
31+ // s/b 8 AM CDT (UTC-5)
32+ assert . strictEqual ( chicagoTime . hour , 8 )
33+ assert . strictEqual ( chicagoTime . minute , 0 )
34+ assert . strictEqual ( chicagoTime . offset , '-05:00' )
35+ } )
36+
37+ test ( 'DST - fall back' , ( ) => {
38+ // 2024-11-03 - fall back in US
39+ const fallBackDate = Temporal . Instant . from ( '2024-11-03T13:00:00.0Z' )
40+ const chicagoTime = fallBackDate . toZonedDateTimeISO ( 'America/Chicago' )
41+
42+ // s/b 7 AM CST (UTC-6)
43+ assert . strictEqual ( chicagoTime . hour , 7 )
44+ assert . strictEqual ( chicagoTime . minute , 0 )
45+ assert . strictEqual ( chicagoTime . offset , '-06:00' )
46+ } )
47+
48+ test ( 'DST - summer' , ( ) => {
49+ // 2024-07-15 - summer time
50+ const summerDate = Temporal . Instant . from ( '2024-07-15T13:00:00.0Z' )
51+ const londonTime = summerDate . toZonedDateTimeISO ( 'Europe/London' )
52+ const madridTime = summerDate . toZonedDateTimeISO ( 'Europe/Madrid' )
53+
54+ // London s/b 2 PM BST (UTC+1)
55+ assert . strictEqual ( londonTime . hour , 14 )
56+ assert . strictEqual ( londonTime . offset , '+01:00' )
57+
58+ // Madrid s/b 3 PM CEST (UTC+2)
59+ assert . strictEqual ( madridTime . hour , 15 )
60+ assert . strictEqual ( madridTime . offset , '+02:00' )
61+ } )
62+
63+ test ( 'DST - winter' , ( ) => {
64+ // 2024-01-15 - winter time
65+ const winterDate = Temporal . Instant . from ( '2024-01-15T13:00:00.0Z' )
66+ const londonTime = winterDate . toZonedDateTimeISO ( 'Europe/London' )
67+ const madridTime = winterDate . toZonedDateTimeISO ( 'Europe/Madrid' )
68+
69+ // London s/b 1 PM GMT (UTC+0)
70+ assert . strictEqual ( londonTime . hour , 13 )
71+ assert . strictEqual ( londonTime . offset , '+00:00' )
72+
73+ // Madrid s/b 2 PM CET (UTC+1)
74+ assert . strictEqual ( madridTime . hour , 14 )
75+ assert . strictEqual ( madridTime . offset , '+01:00' )
76+ } )
77+
78+ test ( 'Temporal Instant creation and comparison' , ( ) => {
79+ const instant1 = Temporal . Instant . from ( '2024-03-10T13:00:00.0Z' )
80+ const instant2 = Temporal . Instant . from ( '2024-03-10T13:00:00.0Z' )
81+ const instant3 = Temporal . Instant . from ( '2024-03-10T14:00:00.0Z' )
82+
83+ assert . strictEqual ( instant1 . epochMilliseconds , instant2 . epochMilliseconds )
84+ assert ( instant1 . epochMilliseconds < instant3 . epochMilliseconds )
85+ } )
86+
87+ test ( 'Temporal Duration operations' , ( ) => {
88+ const duration = Temporal . Duration . from ( 'P28D' )
89+ const start = Temporal . Instant . from ( '2024-03-10T13:00:00.0Z' )
90+ const zonedStart = start . toZonedDateTimeISO ( 'UTC' )
91+ const end = zonedStart . add ( duration ) . toInstant ( )
92+
93+ // 28 days later s/b 2024-04-07
94+ const expected = Temporal . Instant . from ( '2024-04-07T13:00:00.0Z' )
95+ assert . strictEqual ( end . epochMilliseconds , expected . epochMilliseconds )
96+ } )
97+
98+ test ( 'getNextScheduledMeeting with DST transition' , ( ) => {
99+ const schedules = [
100+ '2024-03-10T13:00:00.0Z/P7D' , // spring forward
101+ '2024-11-03T13:00:00.0Z/P7D' // fall back
102+ ]
103+
104+ const beforeSpring = Temporal . Instant . from ( '2024-03-09T13:00:00.0Z' )
105+ const nextBefore = meetings . getNextScheduledMeeting ( schedules , beforeSpring )
106+ assert . strictEqual ( nextBefore . toString ( ) , '2024-03-10T13:00:00Z' )
107+
108+ const afterSpring = Temporal . Instant . from ( '2024-03-11T13:00:00.0Z' )
109+ const nextAfter = meetings . getNextScheduledMeeting ( schedules , afterSpring )
110+ assert . strictEqual ( nextAfter . toString ( ) , '2024-03-17T13:00:00Z' )
111+ } )
112+
113+ test ( 'Date formatting with Intl.DateTimeFormat' , ( ) => {
114+ const date = Temporal . Instant . from ( '2024-03-10T13:00:00.0Z' )
115+ const zone = 'America/Chicago'
116+ const zonedDate = date . toZonedDateTimeISO ( zone )
117+ const formatter = new Intl . DateTimeFormat ( 'en-US' , {
118+ weekday : 'short' ,
119+ month : 'short' ,
120+ day : '2-digit' ,
121+ year : 'numeric' ,
122+ hour : '2-digit' ,
123+ minute : '2-digit' ,
124+ hour12 : true ,
125+ timeZone : zone
126+ } )
127+
128+ const formattedDate = formatter . format ( new Date ( zonedDate . epochMilliseconds ) )
129+ // spring forward
130+ assert ( formattedDate . includes ( 'Sun' ) )
131+ assert ( formattedDate . includes ( 'Mar' ) )
132+ assert ( formattedDate . includes ( '08:00 AM' ) )
133+ } )
25134} )
26135
27136test ( 'shorthands transform' , async ( ) => {
0 commit comments