File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 55namespace SwooleBundle \SwooleBundle \Bridge \Log ;
66
77use DateTimeImmutable ;
8+ use DateTimeZone ;
89use IntlDateFormatter ;
910use Symfony \Component \HttpFoundation \Request ;
1011use Symfony \Component \HttpFoundation \Response ;
@@ -301,6 +302,7 @@ public function getRequestTime(string $format): string
301302 default :
302303 // Cast to int first, as it may be a float
303304 $ requestTime = new DateTimeImmutable ('@ ' . (int ) $ time );
305+ $ requestTime = $ requestTime ->setTimezone (new DateTimeZone (date_default_timezone_get ()));
304306
305307 return IntlDateFormatter::formatObject (
306308 $ requestTime ,
Original file line number Diff line number Diff line change @@ -31,9 +31,9 @@ public function testFormatterDelegatesToDataMapToReplacePlaceholdersInFormat():
3131 ->method ('getRequestDuration ' )
3232 ->willReturnCallback (
3333 static fn (string $ format ) => match ([$ format ]) { // @phpstan-ignore-line
34- ['ms ' ] => '4321 ' , // %D
35- ['s ' ] => '22 ' , // %T
36- ['us ' ] => '22 ' , // %{us}T
34+ ['ms ' ] => '4321 ' , // %{ms}T
35+ ['s ' ] => '4 ' , // %T
36+ ['us ' ] => '4321210 ' , // %{us}T, %D
3737 }
3838 );
3939 $ dataMap ->method ('getFilename ' )->willReturn (__FILE__ ); // %f
@@ -84,7 +84,7 @@ public function testFormatterDelegatesToDataMapToReplacePlaceholdersInFormat():
8484 '127.0.0.1 ' ,
8585 '1234 ' ,
8686 '1234 ' ,
87- '4321 ' ,
87+ '4321210 ' ,
8888 __FILE__ ,
8989 $ hostname ,
9090 'HTTP/1.1 ' ,
@@ -94,7 +94,7 @@ public function testFormatterDelegatesToDataMapToReplacePlaceholdersInFormat():
9494 'POST /path?foo=bar HTTP/1.1 ' ,
9595 '202 ' ,
9696 '[1234567890] ' ,
97- '22 ' ,
97+ '4 ' ,
9898 'swoole ' ,
9999 '/path ' ,
100100 'swoole.local ' ,
@@ -108,7 +108,7 @@ public function testFormatterDelegatesToDataMapToReplacePlaceholdersInFormat():
108108 'response ' ,
109109 '9999 ' ,
110110 '[1234567890] ' ,
111- '22 ' ,
111+ '4321210 ' ,
112112 ];
113113 $ expected = implode (' ' , $ expected );
114114
Original file line number Diff line number Diff line change @@ -98,4 +98,18 @@ public function testGetHttpFoundationRequestTimeAsRequestedByFormatterReturnsFor
9898
9999 $ this ->assertSame ('[02/Dec/2021:02:21:12 ' . $ date ->format ('O ' ) . '] ' , $ requestTime );
100100 }
101+
102+ public function testGetHttpFoundationRequestTimeInDifferentTimeZoneAsUTC (): void
103+ {
104+ $ oldTZ = date_default_timezone_get ();
105+ date_default_timezone_set ('Europe/Bratislava ' );
106+ $ tz = new DateTimeZone (date_default_timezone_get ());
107+ $ date = new DateTimeImmutable ('2021-12-02T02:21:12.4242 ' , $ tz );
108+ $ this ->request ->server = new ServerBag (['REQUEST_TIME_FLOAT ' => (float ) $ date ->getTimestamp ()]);
109+ $ map = new SymfonyAccessLogDataMap ($ this ->request , $ this ->response , false );
110+ $ requestTime = $ map ->getRequestTime ('begin:%d/%b/%Y:%H:%M:%S %z ' );
111+
112+ $ this ->assertSame ('[02/Dec/2021:02:21:12 ' . $ date ->format ('O ' ) . '] ' , $ requestTime );
113+ date_default_timezone_set ($ oldTZ );
114+ }
101115}
You can’t perform that action at this time.
0 commit comments