Version 1
[yaffs-website] / web / modules / contrib / devel / kint / kint / parsers / custom / timestamp.php
1 <?php
2
3 class Kint_Parsers_Timestamp extends kintParser
4 {
5         private static function _fits( $variable )
6         {
7                 if ( !is_string( $variable ) && !is_int( $variable ) ) return false;
8
9                 $len = strlen( (int) $variable );
10                 return
11                         (
12                                 $len === 9 || $len === 10 # a little naive
13                                 || ( $len === 13 && substr( $variable, -3 ) === '000' ) # also handles javascript micro timestamps
14                         )
15                         && ( (string) (int) $variable == $variable );
16         }
17
18
19         protected function _parse( & $variable )
20         {
21                 if ( !self::_fits( $variable ) ) return false;
22
23                 $var = strlen( $variable ) === 13 ? substr( $variable, 0, -3 ) : $variable;
24
25                 $this->type = 'timestamp';
26                 # avoid dreaded "Timezone must be set" error
27                 $this->value = @date( 'Y-m-d H:i:s', $var );
28         }
29 }