Skip to content

Commit c81268d

Browse files
Merge branch '6.2' into 6.3
* 6.2: [Validator] Add missing validator translations in Polish language [HttpClient] Fix encoding some characters in query strings [SecurityBundle] Remove last usages of tag `security.remember_me_aware` [VarDumper] Dumping DateTime throws error if getTimezone is false Only update autoload_runtime.php when it changed [Intl] Update the ICU data to 73.2 [HttpClient] Force int conversion for floated multiplier for GenericRetryStrategy [FrameworkBundle] Ignore missing directories in about command Revert "[Messenger] Respect `isRetryable` decision of the retry strategy when deciding if failed message should be re-delivered" [Validator][Translator] Fix xlf files for en & fr translations. Bug introduced by #50590 Add missing EN and FR translations for newest constraints
2 parents 90caf9f + facbf30 commit c81268d

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

Caster/DateCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DateCaster
3030
public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub, bool $isNested, int $filter)
3131
{
3232
$prefix = Caster::PREFIX_VIRTUAL;
33-
$location = $d->getTimezone()->getLocation();
33+
$location = $d->getTimezone() ? $d->getTimezone()->getLocation() : null;
3434
$fromNow = (new \DateTimeImmutable())->diff($d);
3535

3636
$title = $d->format('l, F j, Y')

Tests/Caster/DateCasterTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,52 @@ public static function provideDateTimes()
106106
];
107107
}
108108

109+
/**
110+
* @dataProvider provideNoTimezoneDateTimes
111+
*/
112+
public function testCastDateTimeNoTimezone($time, $xDate, $xInfos)
113+
{
114+
$stub = new Stub();
115+
$date = new NoTimezoneDate($time);
116+
$cast = DateCaster::castDateTime($date, Caster::castObject($date, \DateTime::class), $stub, false, 0);
117+
118+
$xDump = <<<EODUMP
119+
array:1 [
120+
"\\x00~\\x00date" => $xDate
121+
]
122+
EODUMP;
123+
124+
$this->assertDumpEquals($xDump, $cast);
125+
126+
$xDump = <<<EODUMP
127+
Symfony\Component\VarDumper\Caster\ConstStub {
128+
+type: 1
129+
+class: "$xDate"
130+
+value: "%A$xInfos%A"
131+
+cut: 0
132+
+handle: 0
133+
+refCount: 0
134+
+position: 0
135+
+attr: []
136+
}
137+
EODUMP;
138+
139+
$this->assertDumpMatchesFormat($xDump, $cast["\0~\0date"]);
140+
}
141+
142+
public static function provideNoTimezoneDateTimes()
143+
{
144+
return [
145+
['2017-04-30 00:00:00.000000', '2017-04-30 00:00:00.0 +00:00', 'Sunday, April 30, 2017'],
146+
['2017-04-30 00:00:00.100000', '2017-04-30 00:00:00.100 +00:00', 'Sunday, April 30, 2017'],
147+
['2017-04-30 00:00:00.120000', '2017-04-30 00:00:00.120 +00:00', 'Sunday, April 30, 2017'],
148+
['2017-04-30 00:00:00.123000', '2017-04-30 00:00:00.123 +00:00', 'Sunday, April 30, 2017'],
149+
['2017-04-30 00:00:00.123400', '2017-04-30 00:00:00.123400 +00:00', 'Sunday, April 30, 2017'],
150+
['2017-04-30 00:00:00.123450', '2017-04-30 00:00:00.123450 +00:00', 'Sunday, April 30, 2017'],
151+
['2017-04-30 00:00:00.123456', '2017-04-30 00:00:00.123456 +00:00', 'Sunday, April 30, 2017'],
152+
];
153+
}
154+
109155
public function testCastDateTimeWithAdditionalChildProperty()
110156
{
111157
$stub = new Stub();
@@ -423,3 +469,11 @@ private function createInterval($intervalSpec, $ms, $invert)
423469
return $interval;
424470
}
425471
}
472+
473+
class NoTimezoneDate extends \DateTime
474+
{
475+
public function getTimezone(): \DateTimeZone|false
476+
{
477+
return false;
478+
}
479+
}

0 commit comments

Comments
 (0)