@@ -233,3 +233,53 @@ describe('getSecondsUntilUTCMidnight — sliding window boundary robustness', ()
233233 }
234234 } ) ;
235235} ) ;
236+
237+ describe ( 'getSecondsUntilMidnightInTimezone — extreme timezone offset boundary robustness' , ( ) => {
238+ beforeEach ( ( ) => {
239+ vi . useFakeTimers ( ) ;
240+ } ) ;
241+
242+ afterEach ( ( ) => {
243+ vi . useRealTimers ( ) ;
244+ } ) ;
245+
246+ it ( 'converts timestamp cleanly to target offset without calendar shifting (UTC+5:30)' , ( ) => {
247+ // UTC 2024-06-15T18:30:00Z = 2024-06-16T00:00:00 in Asia/Kolkata (UTC+5:30)
248+ // So exactly at local midnight → 86400 seconds remaining
249+ vi . setSystemTime ( new Date ( '2024-06-15T18:30:00.000Z' ) ) ;
250+
251+ expect ( getSecondsUntilMidnightInTimezone ( 'Asia/Kolkata' ) ) . toBe ( 86400 ) ;
252+ } ) ;
253+
254+ it ( 'converts timestamp cleanly to target offset without calendar shifting (UTC+14)' , ( ) => {
255+ // UTC 2024-06-14T10:00:00Z = 2024-06-15T00:00:00 in Pacific/Kiritimati (UTC+14)
256+ // Exactly local midnight → 86400 seconds remaining, no date shift
257+ vi . setSystemTime ( new Date ( '2024-06-14T10:00:00.000Z' ) ) ;
258+
259+ expect ( getSecondsUntilMidnightInTimezone ( 'Pacific/Kiritimati' ) ) . toBe ( 86400 ) ;
260+ } ) ;
261+
262+ it ( 'converts timestamp cleanly to target offset without calendar shifting (UTC-12)' , ( ) => {
263+ // UTC 2024-06-15T12:00:00Z = 2024-06-15T00:00:00 in Etc/GMT+12 (UTC-12)
264+ // Exactly local midnight → 86400 seconds remaining, no date shift
265+ vi . setSystemTime ( new Date ( '2024-06-15T12:00:00.000Z' ) ) ;
266+
267+ expect ( getSecondsUntilMidnightInTimezone ( 'Etc/GMT+12' ) ) . toBe ( 86400 ) ;
268+ } ) ;
269+
270+ it ( 'handles a timestamp near year-end boundary without calendar shifting (UTC+14)' , ( ) => {
271+ // UTC 2023-12-31T10:00:00Z = 2024-01-01T00:00:00 in Pacific/Kiritimati
272+ // Crosses year boundary cleanly → 86400 seconds remaining
273+ vi . setSystemTime ( new Date ( '2023-12-31T10:00:00.000Z' ) ) ;
274+
275+ expect ( getSecondsUntilMidnightInTimezone ( 'Pacific/Kiritimati' ) ) . toBe ( 86400 ) ;
276+ } ) ;
277+
278+ it ( 'handles a timestamp near year-end boundary without calendar shifting (UTC-11)' , ( ) => {
279+ // UTC 2024-01-01T11:00:00Z = 2024-01-01T00:00:00 in Pacific/Midway (UTC-11)
280+ // Crosses year boundary cleanly → 86400 seconds remaining
281+ vi . setSystemTime ( new Date ( '2024-01-01T11:00:00.000Z' ) ) ;
282+
283+ expect ( getSecondsUntilMidnightInTimezone ( 'Pacific/Midway' ) ) . toBe ( 86400 ) ;
284+ } ) ;
285+ } ) ;
0 commit comments