Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: symfony/var-dumper
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.4.24
Choose a base ref
...
head repository: symfony/var-dumper
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.4.25
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jun 20, 2023

  1. Copy the full SHA
    82269f7 View commit details
Showing with 59 additions and 1 deletion.
  1. +1 −1 Caster/DateCaster.php
  2. +58 −0 Tests/Caster/DateCasterTest.php
2 changes: 1 addition & 1 deletion Caster/DateCaster.php
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ class DateCaster
public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub, bool $isNested, int $filter)
{
$prefix = Caster::PREFIX_VIRTUAL;
$location = $d->getTimezone()->getLocation();
$location = $d->getTimezone() ? $d->getTimezone()->getLocation() : null;
$fromNow = (new \DateTime())->diff($d);

$title = $d->format('l, F j, Y')
58 changes: 58 additions & 0 deletions Tests/Caster/DateCasterTest.php
Original file line number Diff line number Diff line change
@@ -90,6 +90,52 @@ public static function provideDateTimes()
];
}

/**
* @dataProvider provideNoTimezoneDateTimes
*/
public function testCastDateTimeNoTimezone($time, $xDate, $xInfos)
{
$stub = new Stub();
$date = new NoTimezoneDate($time);
$cast = DateCaster::castDateTime($date, Caster::castObject($date, \DateTime::class), $stub, false, 0);

$xDump = <<<EODUMP
array:1 [
"\\x00~\\x00date" => $xDate
]
EODUMP;

$this->assertDumpEquals($xDump, $cast);

$xDump = <<<EODUMP
Symfony\Component\VarDumper\Caster\ConstStub {
+type: 1
+class: "$xDate"
+value: "%A$xInfos%A"
+cut: 0
+handle: 0
+refCount: 0
+position: 0
+attr: []
}
EODUMP;

$this->assertDumpMatchesFormat($xDump, $cast["\0~\0date"]);
}

public static function provideNoTimezoneDateTimes()
{
return [
['2017-04-30 00:00:00.000000', '2017-04-30 00:00:00.0 +00:00', 'Sunday, April 30, 2017'],
['2017-04-30 00:00:00.100000', '2017-04-30 00:00:00.100 +00:00', 'Sunday, April 30, 2017'],
['2017-04-30 00:00:00.120000', '2017-04-30 00:00:00.120 +00:00', 'Sunday, April 30, 2017'],
['2017-04-30 00:00:00.123000', '2017-04-30 00:00:00.123 +00:00', 'Sunday, April 30, 2017'],
['2017-04-30 00:00:00.123400', '2017-04-30 00:00:00.123400 +00:00', 'Sunday, April 30, 2017'],
['2017-04-30 00:00:00.123450', '2017-04-30 00:00:00.123450 +00:00', 'Sunday, April 30, 2017'],
['2017-04-30 00:00:00.123456', '2017-04-30 00:00:00.123456 +00:00', 'Sunday, April 30, 2017'],
];
}

public function testCastDateTimeWithAdditionalChildProperty()
{
$stub = new Stub();
@@ -407,3 +453,15 @@ private function createInterval($intervalSpec, $ms, $invert)
return $interval;
}
}

class NoTimezoneDate extends \DateTime
{
/**
* @return \DateTimeZone|false
*/
#[\ReturnTypeWillChange]
public function getTimezone()
{
return false;
}
}