1818use Cake \Chronos \Chronos ;
1919use Cake \Chronos \Test \TestCase \TestCase ;
2020
21- class TimestampAddTest extends TestCase
21+ class ElapsedTimeAddTest extends TestCase
2222{
23- public function testAddSecondsWithTimestamp (): void
23+ public function testAddElapsedSeconds (): void
2424 {
2525 $ time = Chronos::parse ('2024-01-15 12:00:00 ' , 'UTC ' );
26- $ result = $ time ->addSecondsWithTimestamp (30 );
26+ $ result = $ time ->addElapsedSeconds (30 );
2727 $ this ->assertSame ('2024-01-15 12:00:30 ' , $ result ->format ('Y-m-d H:i:s ' ));
2828 }
2929
30- public function testAddSecondsWithTimestampNegative (): void
30+ public function testAddElapsedSecondsNegative (): void
3131 {
3232 $ time = Chronos::parse ('2024-01-15 12:00:30 ' , 'UTC ' );
33- $ result = $ time ->addSecondsWithTimestamp (-30 );
33+ $ result = $ time ->addElapsedSeconds (-30 );
3434 $ this ->assertSame ('2024-01-15 12:00:00 ' , $ result ->format ('Y-m-d H:i:s ' ));
3535 }
3636
37- public function testSubSecondsWithTimestamp (): void
37+ public function testSubElapsedSeconds (): void
3838 {
3939 $ time = Chronos::parse ('2024-01-15 12:00:30 ' , 'UTC ' );
40- $ result = $ time ->subSecondsWithTimestamp (30 );
40+ $ result = $ time ->subElapsedSeconds (30 );
4141 $ this ->assertSame ('2024-01-15 12:00:00 ' , $ result ->format ('Y-m-d H:i:s ' ));
4242 }
4343
44- public function testAddMinutesWithTimestamp (): void
44+ public function testAddElapsedMinutes (): void
4545 {
4646 $ time = Chronos::parse ('2024-01-15 12:00:00 ' , 'UTC ' );
47- $ result = $ time ->addMinutesWithTimestamp (30 );
47+ $ result = $ time ->addElapsedMinutes (30 );
4848 $ this ->assertSame ('2024-01-15 12:30:00 ' , $ result ->format ('Y-m-d H:i:s ' ));
4949 }
5050
51- public function testAddMinutesWithTimestampNegative (): void
51+ public function testAddElapsedMinutesNegative (): void
5252 {
5353 $ time = Chronos::parse ('2024-01-15 12:30:00 ' , 'UTC ' );
54- $ result = $ time ->addMinutesWithTimestamp (-30 );
54+ $ result = $ time ->addElapsedMinutes (-30 );
5555 $ this ->assertSame ('2024-01-15 12:00:00 ' , $ result ->format ('Y-m-d H:i:s ' ));
5656 }
5757
58- public function testSubMinutesWithTimestamp (): void
58+ public function testSubElapsedMinutes (): void
5959 {
6060 $ time = Chronos::parse ('2024-01-15 12:30:00 ' , 'UTC ' );
61- $ result = $ time ->subMinutesWithTimestamp (30 );
61+ $ result = $ time ->subElapsedMinutes (30 );
6262 $ this ->assertSame ('2024-01-15 12:00:00 ' , $ result ->format ('Y-m-d H:i:s ' ));
6363 }
6464
65- public function testAddHoursWithTimestamp (): void
65+ public function testAddElapsedHours (): void
6666 {
6767 $ time = Chronos::parse ('2024-01-15 12:00:00 ' , 'UTC ' );
68- $ result = $ time ->addHoursWithTimestamp (2 );
68+ $ result = $ time ->addElapsedHours (2 );
6969 $ this ->assertSame ('2024-01-15 14:00:00 ' , $ result ->format ('Y-m-d H:i:s ' ));
7070 }
7171
72- public function testAddHoursWithTimestampNegative (): void
72+ public function testAddElapsedHoursNegative (): void
7373 {
7474 $ time = Chronos::parse ('2024-01-15 14:00:00 ' , 'UTC ' );
75- $ result = $ time ->addHoursWithTimestamp (-2 );
75+ $ result = $ time ->addElapsedHours (-2 );
7676 $ this ->assertSame ('2024-01-15 12:00:00 ' , $ result ->format ('Y-m-d H:i:s ' ));
7777 }
7878
79- public function testSubHoursWithTimestamp (): void
79+ public function testSubElapsedHours (): void
8080 {
8181 $ time = Chronos::parse ('2024-01-15 14:00:00 ' , 'UTC ' );
82- $ result = $ time ->subHoursWithTimestamp (2 );
82+ $ result = $ time ->subElapsedHours (2 );
8383 $ this ->assertSame ('2024-01-15 12:00:00 ' , $ result ->format ('Y-m-d H:i:s ' ));
8484 }
8585
8686 /**
8787 * Test DST transition when clocks go BACK (fall back).
88- * Australia/Melbourne changes out of daylight savings on 5th April 2026
88+ * Australia/Melbourne changes out of daylight saving on 5th April 2026
8989 * at 3:00 AM AEDT (+11) -> 2:00 AM AEST (+10)
9090 */
91- public function testAddMinutesWithTimestampAcrossDstFallBack (): void
91+ public function testAddElapsedMinutesAcrossDstFallBack (): void
9292 {
9393 $ time = Chronos::parse ('2026-04-05 09:00:00 ' , 'Australia/Melbourne ' );
9494
@@ -98,8 +98,8 @@ public function testAddMinutesWithTimestampAcrossDstFallBack(): void
9898 $ diff = $ time ->diffInMinutes ($ time ->startOfDay ());
9999 $ this ->assertSame (600 , $ diff );
100100
101- // Using timestamp arithmetic should correctly account for DST
102- $ result = $ time ->startOfDay ()->addMinutesWithTimestamp (600 );
101+ // Using elapsed time should correctly account for DST
102+ $ result = $ time ->startOfDay ()->addElapsedMinutes (600 );
103103 $ this ->assertSame ('2026-04-05T09:00:00+10:00 ' , $ result ->toIso8601String ());
104104 }
105105
@@ -108,76 +108,76 @@ public function testAddMinutesWithTimestampAcrossDstFallBack(): void
108108 * America/New_York springs forward on 2nd Sunday of March 2025
109109 * at 2:00 AM EST (-05) -> 3:00 AM EDT (-04)
110110 */
111- public function testAddMinutesWithTimestampAcrossDstSpringForward (): void
111+ public function testAddElapsedMinutesAcrossDstSpringForward (): void
112112 {
113113 // March 9, 2025 is the 2nd Sunday of March (DST starts)
114114 $ beforeDst = Chronos::parse ('2025-03-09 01:00:00 ' , 'America/New_York ' );
115115 $ this ->assertSame ('-05:00 ' , $ beforeDst ->format ('P ' ));
116116
117- // Add 2 hours (120 minutes) using timestamp arithmetic
117+ // Add 2 hours (120 minutes) using elapsed time
118118 // Wall clock would show 3:00 AM (skipping 2:00-3:00)
119- $ result = $ beforeDst ->addMinutesWithTimestamp (120 );
119+ $ result = $ beforeDst ->addElapsedMinutes (120 );
120120
121121 // Should be 04:00 AM EDT (not 03:00 AM)
122122 $ this ->assertSame ('2025-03-09T04:00:00-04:00 ' , $ result ->toIso8601String ());
123123 }
124124
125125 /**
126- * Test that addMinutes and addMinutesWithTimestamp differ during DST
126+ * Test that addMinutes and addElapsedMinutes differ during DST
127127 */
128- public function testAddMinutesVsAddMinutesWithTimestampDuringDst (): void
128+ public function testAddMinutesVsAddElapsedMinutesDuringDst (): void
129129 {
130130 // Australia/Melbourne DST ends April 5, 2026 at 3am
131131 $ startOfDay = Chronos::parse ('2026-04-05 00:00:00 ' , 'Australia/Melbourne ' );
132132
133133 // Wall clock addition (regular addMinutes)
134134 $ wallClock = $ startOfDay ->addMinutes (600 );
135135
136- // Timestamp addition
137- $ elapsed = $ startOfDay ->addMinutesWithTimestamp (600 );
136+ // Elapsed time addition
137+ $ elapsed = $ startOfDay ->addElapsedMinutes (600 );
138138
139139 // These should differ by 1 hour due to DST transition
140140 $ this ->assertSame ('2026-04-05T10:00:00+10:00 ' , $ wallClock ->toIso8601String ());
141141 $ this ->assertSame ('2026-04-05T09:00:00+10:00 ' , $ elapsed ->toIso8601String ());
142142 }
143143
144144 /**
145- * Test addHoursWithTimestamp across DST
145+ * Test addElapsedHours across DST
146146 */
147- public function testAddHoursWithTimestampAcrossDst (): void
147+ public function testAddElapsedHoursAcrossDst (): void
148148 {
149149 $ startOfDay = Chronos::parse ('2026-04-05 00:00:00 ' , 'Australia/Melbourne ' );
150150
151- $ result = $ startOfDay ->addHoursWithTimestamp (10 );
151+ $ result = $ startOfDay ->addElapsedHours (10 );
152152
153153 // 10 actual hours from midnight should be 09:00 (since we gain an hour at 3am)
154154 $ this ->assertSame ('2026-04-05T09:00:00+10:00 ' , $ result ->toIso8601String ());
155155 }
156156
157157 /**
158- * Test addSecondsWithTimestamp across DST
158+ * Test addElapsedSeconds across DST
159159 */
160- public function testAddSecondsWithTimestampAcrossDst (): void
160+ public function testAddElapsedSecondsAcrossDst (): void
161161 {
162162 $ startOfDay = Chronos::parse ('2026-04-05 00:00:00 ' , 'Australia/Melbourne ' );
163163
164164 // 10 hours in seconds = 36000
165- $ result = $ startOfDay ->addSecondsWithTimestamp (36000 );
165+ $ result = $ startOfDay ->addElapsedSeconds (36000 );
166166
167167 $ this ->assertSame ('2026-04-05T09:00:00+10:00 ' , $ result ->toIso8601String ());
168168 }
169169
170170 /**
171- * Test that diffInMinutes and addMinutesWithTimestamp are inverses
171+ * Test that diffInMinutes and addElapsedMinutes are inverses
172172 */
173- public function testDiffInMinutesIsInverseOfAddMinutesWithTimestamp (): void
173+ public function testDiffInMinutesIsInverseOfAddElapsedMinutes (): void
174174 {
175175 $ time = Chronos::parse ('2026-04-05 09:00:00 ' , 'Australia/Melbourne ' );
176176 $ startOfDay = $ time ->startOfDay ();
177177
178178 $ diff = $ time ->diffInMinutes ($ startOfDay );
179179
180- $ reconstructed = $ startOfDay ->addMinutesWithTimestamp ($ diff );
180+ $ reconstructed = $ startOfDay ->addElapsedMinutes ($ diff );
181181
182182 $ this ->assertSame ($ time ->toIso8601String (), $ reconstructed ->toIso8601String ());
183183 }
0 commit comments