/var/www/hkosl.com/nick/codeigniter/application/vendor/symfony/var-dumper/Caster/DateCaster.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\VarDumper\Caster;

use 
Symfony\Component\VarDumper\Cloner\Stub;

/**
 * Casts DateTimeInterface related classes to array representation.
 *
 * @author Dany Maillard <danymaillard93b@gmail.com>
 */
class DateCaster
{
    public static function 
castDateTime(\DateTimeInterface $d, array $aStub $stub$isNested$filter)
    {
        
$prefix Caster::PREFIX_VIRTUAL;
        
$location $d->getTimezone()->getLocation();
        
$fromNow = (new \DateTime())->diff($d);

        
$title $d->format('l, F j, Y')
            .
"\n".self::formatInterval($fromNow).' from now'
            
.($location ? ($d->format('I') ? "\nDST On" "\nDST Off") : '')
        ;

        
$a = [];
        
$a[$prefix.'date'] = new ConstStub(self::formatDateTime($d$location ' e (P)' ' P'), $title);

        
$stub->class .= $d->format(' @U');

        return 
$a;
    }

    public static function 
castInterval(\DateInterval $interval, array $aStub $stub$isNested$filter)
    {
        
$now = new \DateTimeImmutable();
        
$numberOfSeconds $now->add($interval)->getTimestamp() - $now->getTimestamp();
        
$title number_format($numberOfSeconds0'.'' ').'s';

        
$i = [Caster::PREFIX_VIRTUAL.'interval' => new ConstStub(self::formatInterval($interval), $title)];

        return 
$filter Caster::EXCLUDE_VERBOSE $i $i $a;
    }

    private static function 
formatInterval(\DateInterval $i)
    {
        
$format '%R ';

        if (
=== $i->&& === $i->&& ($i->>= 24 || $i->>= 60 || $i->>= 60)) {
            
$i date_diff($d = new \DateTime(), date_add(clone $d$i)); // recalculate carry over points
            
$format .= $i->days '%ad ' '';
        } else {
            
$format .= ($i->'%yy ' '').($i->'%mm ' '').($i->'%dd ' '');
        }

        if (\
PHP_VERSION_ID >= 70100 && isset($i->f)) {
            
$format .= $i->|| $i->|| $i->|| $i->'%H:%I:'.self::formatSeconds($i->ssubstr($i->f2)) : '';
        } else {
            
$format .= $i->|| $i->|| $i->'%H:%I:%S' '';
        }

        
$format '%R ' === $format '0s' $format;

        return 
$i->format(rtrim($format));
    }

    public static function 
castTimeZone(\DateTimeZone $timeZone, array $aStub $stub$isNested$filter)
    {
        
$location $timeZone->getLocation();
        
$formatted = (new \DateTime('now'$timeZone))->format($location 'e (P)' 'P');
        
$title $location && \extension_loaded('intl') ? \Locale::getDisplayRegion('-'.$location['country_code'], \Locale::getDefault()) : '';

        
$z = [Caster::PREFIX_VIRTUAL.'timezone' => new ConstStub($formatted$title)];

        return 
$filter Caster::EXCLUDE_VERBOSE $z $z $a;
    }

    public static function 
castPeriod(\DatePeriod $p, array $aStub $stub$isNested$filter)
    {
        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
            
return $a;
        }

        
$dates = [];
        if (\
PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639
            
foreach (clone $p as $i => $d) {
                if (
=== $i) {
                    
$now = new \DateTimeImmutable();
                    
$dates[] = sprintf('%s more', ($end $p->getEndDate())
                        ? 
ceil(($end->format('U.u') - $d->format('U.u')) / ((int) $now->add($p->getDateInterval())->format('U.u') - (int) $now->format('U.u')))
                        : 
$p->recurrences $i
                    
);
                    break;
                }
                
$dates[] = sprintf('%s) %s'$i 1self::formatDateTime($d));
            }
        }

        
$period sprintf(
            
'every %s, from %s (%s) %s',
            
self::formatInterval($p->getDateInterval()),
            
self::formatDateTime($p->getStartDate()),
            
$p->include_start_date 'included' 'excluded',
            (
$end $p->getEndDate()) ? 'to '.self::formatDateTime($end) : 'recurring '.$p->recurrences.' time/s'
        
);

        
$p = [Caster::PREFIX_VIRTUAL.'period' => new ConstStub($periodimplode("\n"$dates))];

        return 
$filter Caster::EXCLUDE_VERBOSE $p $p $a;
    }

    private static function 
formatDateTime(\DateTimeInterface $d$extra '')
    {
        return 
$d->format('Y-m-d H:i:'.self::formatSeconds($d->format('s'), $d->format('u')).$extra);
    }

    private static function 
formatSeconds($s$us)
    {
        return 
sprintf('%02d.%s'$s=== ($len = \strlen($t rtrim($us'0'))) ? '0' : ($len <= str_pad($t3'0') : $us));
    }
}