comparison vendor/symfony/var-dumper/Caster/DateCaster.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
comparison
equal deleted inserted replaced
3:307d7a7fd348 4:a9cd425dd02b
29 $title = $d->format('l, F j, Y') 29 $title = $d->format('l, F j, Y')
30 ."\n".self::formatInterval($fromNow).' from now' 30 ."\n".self::formatInterval($fromNow).' from now'
31 .($location ? ($d->format('I') ? "\nDST On" : "\nDST Off") : '') 31 .($location ? ($d->format('I') ? "\nDST On" : "\nDST Off") : '')
32 ; 32 ;
33 33
34 $a = array(); 34 $a = [];
35 $a[$prefix.'date'] = new ConstStub(self::formatDateTime($d, $location ? ' e (P)' : ' P'), $title); 35 $a[$prefix.'date'] = new ConstStub(self::formatDateTime($d, $location ? ' e (P)' : ' P'), $title);
36 36
37 $stub->class .= $d->format(' @U'); 37 $stub->class .= $d->format(' @U');
38 38
39 return $a; 39 return $a;
43 { 43 {
44 $now = new \DateTimeImmutable(); 44 $now = new \DateTimeImmutable();
45 $numberOfSeconds = $now->add($interval)->getTimestamp() - $now->getTimestamp(); 45 $numberOfSeconds = $now->add($interval)->getTimestamp() - $now->getTimestamp();
46 $title = number_format($numberOfSeconds, 0, '.', ' ').'s'; 46 $title = number_format($numberOfSeconds, 0, '.', ' ').'s';
47 47
48 $i = array(Caster::PREFIX_VIRTUAL.'interval' => new ConstStub(self::formatInterval($interval), $title)); 48 $i = [Caster::PREFIX_VIRTUAL.'interval' => new ConstStub(self::formatInterval($interval), $title)];
49 49
50 return $filter & Caster::EXCLUDE_VERBOSE ? $i : $i + $a; 50 return $filter & Caster::EXCLUDE_VERBOSE ? $i : $i + $a;
51 } 51 }
52 52
53 private static function formatInterval(\DateInterval $i) 53 private static function formatInterval(\DateInterval $i)
74 74
75 public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stub, $isNested, $filter) 75 public static function castTimeZone(\DateTimeZone $timeZone, array $a, Stub $stub, $isNested, $filter)
76 { 76 {
77 $location = $timeZone->getLocation(); 77 $location = $timeZone->getLocation();
78 $formatted = (new \DateTime('now', $timeZone))->format($location ? 'e (P)' : 'P'); 78 $formatted = (new \DateTime('now', $timeZone))->format($location ? 'e (P)' : 'P');
79 $title = $location && extension_loaded('intl') ? \Locale::getDisplayRegion('-'.$location['country_code'], \Locale::getDefault()) : ''; 79 $title = $location && \extension_loaded('intl') ? \Locale::getDisplayRegion('-'.$location['country_code'], \Locale::getDefault()) : '';
80 80
81 $z = array(Caster::PREFIX_VIRTUAL.'timezone' => new ConstStub($formatted, $title)); 81 $z = [Caster::PREFIX_VIRTUAL.'timezone' => new ConstStub($formatted, $title)];
82 82
83 return $filter & Caster::EXCLUDE_VERBOSE ? $z : $z + $a; 83 return $filter & Caster::EXCLUDE_VERBOSE ? $z : $z + $a;
84 } 84 }
85 85
86 public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNested, $filter) 86 public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNested, $filter)
87 { 87 {
88 if (defined('HHVM_VERSION_ID') || \PHP_VERSION_ID < 50620 || (\PHP_VERSION_ID >= 70000 && \PHP_VERSION_ID < 70005)) { // see https://bugs.php.net/bug.php?id=71635 88 if (\defined('HHVM_VERSION_ID') || \PHP_VERSION_ID < 50620 || (\PHP_VERSION_ID >= 70000 && \PHP_VERSION_ID < 70005)) { // see https://bugs.php.net/bug.php?id=71635
89 return $a; 89 return $a;
90 } 90 }
91 91
92 $dates = array(); 92 $dates = [];
93 if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639 93 if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639
94 foreach (clone $p as $i => $d) { 94 foreach (clone $p as $i => $d) {
95 if (3 === $i) { 95 if (3 === $i) {
96 $now = new \DateTimeImmutable(); 96 $now = new \DateTimeImmutable();
97 $dates[] = sprintf('%s more', ($end = $p->getEndDate()) 97 $dates[] = sprintf('%s more', ($end = $p->getEndDate())
110 self::formatDateTime($p->getStartDate()), 110 self::formatDateTime($p->getStartDate()),
111 $p->include_start_date ? 'included' : 'excluded', 111 $p->include_start_date ? 'included' : 'excluded',
112 ($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end) : 'recurring '.$p->recurrences.' time/s' 112 ($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end) : 'recurring '.$p->recurrences.' time/s'
113 ); 113 );
114 114
115 $p = array(Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates))); 115 $p = [Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates))];
116 116
117 return $filter & Caster::EXCLUDE_VERBOSE ? $p : $p + $a; 117 return $filter & Caster::EXCLUDE_VERBOSE ? $p : $p + $a;
118 } 118 }
119 119
120 private static function formatDateTime(\DateTimeInterface $d, $extra = '') 120 private static function formatDateTime(\DateTimeInterface $d, $extra = '')
122 return $d->format('Y-m-d H:i:'.self::formatSeconds($d->format('s'), $d->format('u')).$extra); 122 return $d->format('Y-m-d H:i:'.self::formatSeconds($d->format('s'), $d->format('u')).$extra);
123 } 123 }
124 124
125 private static function formatSeconds($s, $us) 125 private static function formatSeconds($s, $us)
126 { 126 {
127 return sprintf('%02d.%s', $s, 0 === ($len = strlen($t = rtrim($us, '0'))) ? '0' : ($len <= 3 ? str_pad($t, 3, '0') : $us)); 127 return sprintf('%02d.%s', $s, 0 === ($len = \strlen($t = rtrim($us, '0'))) ? '0' : ($len <= 3 ? str_pad($t, 3, '0') : $us));
128 } 128 }
129 } 129 }