@@ -345,4 +345,94 @@ public static function provideEscapeIdentifier(): iterable
345345 'with dots ' => ['com.sitedb.web ' , '"com.sitedb.web" ' ],
346346 ];
347347 }
348+
349+ public function testConvertTimezoneToOffsetWithOffset (): void
350+ {
351+ $ db = new MockConnection ($ this ->options );
352+
353+ // Offset strings should be returned as-is
354+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'convertTimezoneToOffset ' )('+05:30 ' );
355+ $ this ->assertSame ('+05:30 ' , $ result );
356+
357+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'convertTimezoneToOffset ' )('-08:00 ' );
358+ $ this ->assertSame ('-08:00 ' , $ result );
359+
360+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'convertTimezoneToOffset ' )('+00:00 ' );
361+ $ this ->assertSame ('+00:00 ' , $ result );
362+ }
363+
364+ public function testConvertTimezoneToOffsetWithNamedTimezone (): void
365+ {
366+ $ db = new MockConnection ($ this ->options );
367+
368+ // UTC should always be +00:00
369+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'convertTimezoneToOffset ' )('UTC ' );
370+ $ this ->assertSame ('+00:00 ' , $ result );
371+
372+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'convertTimezoneToOffset ' )('America/New_York ' );
373+ $ this ->assertContains ($ result , ['-05:00 ' , '-04:00 ' ]); // EST/EDT
374+
375+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'convertTimezoneToOffset ' )('Europe/Paris ' );
376+ $ this ->assertContains ($ result , ['+01:00 ' , '+02:00 ' ]); // CET/CEST
377+
378+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'convertTimezoneToOffset ' )('Asia/Tokyo ' );
379+ $ this ->assertSame ('+09:00 ' , $ result ); // JST (no DST)
380+ }
381+
382+ public function testConvertTimezoneToOffsetWithInvalidTimezone (): void
383+ {
384+ $ db = new MockConnection ($ this ->options );
385+
386+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'convertTimezoneToOffset ' )('Invalid/Timezone ' );
387+ $ this ->assertSame ('+00:00 ' , $ result );
388+ $ this ->assertLogged ('error ' , "Invalid timezone 'Invalid/Timezone'. Falling back to UTC. DateTimeZone::__construct(): Unknown or bad timezone (Invalid/Timezone). " );
389+ }
390+
391+ public function testGetSessionTimezoneWithFalse (): void
392+ {
393+ $ options = $ this ->options ;
394+ $ options ['timezone ' ] = false ;
395+ $ db = new MockConnection ($ options );
396+
397+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'getSessionTimezone ' )();
398+ $ this ->assertNull ($ result );
399+ }
400+
401+ public function testGetSessionTimezoneWithTrue (): void
402+ {
403+ $ options = $ this ->options ;
404+ $ options ['timezone ' ] = true ;
405+ $ db = new MockConnection ($ options );
406+
407+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'getSessionTimezone ' )();
408+ $ this ->assertSame ('+00:00 ' , $ result ); // UTC = +00:00
409+ }
410+
411+ public function testGetSessionTimezoneWithSpecificOffset (): void
412+ {
413+ $ options = $ this ->options ;
414+ $ options ['timezone ' ] = '+05:30 ' ;
415+ $ db = new MockConnection ($ options );
416+
417+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'getSessionTimezone ' )();
418+ $ this ->assertSame ('+05:30 ' , $ result );
419+ }
420+
421+ public function testGetSessionTimezoneWithSpecificNamedTimezone (): void
422+ {
423+ $ options = $ this ->options ;
424+ $ options ['timezone ' ] = 'America/Chicago ' ;
425+ $ db = new MockConnection ($ options );
426+
427+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'getSessionTimezone ' )();
428+ $ this ->assertContains ($ result , ['-06:00 ' , '-05:00 ' ]);
429+ }
430+
431+ public function testGetSessionTimezoneWithoutTimezoneKey (): void
432+ {
433+ $ db = new MockConnection ($ this ->options );
434+
435+ $ result = $ this ->getPrivateMethodInvoker ($ db , 'getSessionTimezone ' )();
436+ $ this ->assertNull ($ result );
437+ }
348438}
0 commit comments