-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] Add period caster #23668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,40 @@ public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stu | |
return $filter & Caster::EXCLUDE_VERBOSE ? $z : $z + $a; | ||
} | ||
|
||
public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNested, $filter) | ||
{ | ||
if (defined('HHVM_VERSION_ID') || \PHP_VERSION_ID < 50605) { | ||
return $a; | ||
} | ||
|
||
$dates = array(); | ||
if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639 | ||
foreach (clone $p as $i => $d) { | ||
if (3 === $i) { | ||
$now = new \DateTimeImmutable(); | ||
$dates[] = sprintf('%s more', ($end = $p->getEndDate()) | ||
? ceil(($end->format('U.u') - $d->format('U.u')) / ($now->add($p->getDateInterval())->format('U.u') - $now->format('U.u'))) | ||
: $p->recurrences - $i | ||
); | ||
break; | ||
} | ||
$dates[] = sprintf('%s) %s', $i + 1, $d->format('Y-m-d H:i:s')); | ||
} | ||
} | ||
|
||
$period = sprintf( | ||
'every %s, from %s (%s) %s', | ||
self::formatInterval($p->getDateInterval()), | ||
$p->getStartDate()->format('Y-m-d H:i:s'), | ||
$p->include_start_date ? 'included' : 'excluded', | ||
($end = $p->getEndDate()) ? 'to '.$end->format('Y-m-d H:i:s') : 'recurring '.$p->recurrences.' time/s' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the interest of this. Always having a digital format is the simplest, no? |
||
); | ||
|
||
$p = array(Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates))); | ||
|
||
return $filter & Caster::EXCLUDE_VERBOSE ? $p : $p + $a; | ||
} | ||
|
||
private static function formatSeconds($s, $us) | ||
{ | ||
return sprintf('%02d.%s', $s, 0 === ($len = strlen($t = rtrim($us, '0'))) ? '0' : ($len <= 3 ? str_pad($t, 3, '0') : $us)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens before 5.6.5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getStartDate()
,getDateInterval()
andgetEndDate()
methods were added in 5.6.5.