Blame view

php/classes/TimeUtils.php 786 Bytes
5446b8f0   Benjamin Renard   Move CacheTools i...
1
2
3
4
5
6
7
8
9
10
11
<?php

class TimeUtils
{
	public static function iso2stamp($iso) {
		try {
			$time = new DateTime($iso);
		}
		catch (Exception $e) {
			$time = new DateTime('1970-01-01T00:00:00Z');
		}
b4c976eb   Hacene SI HADJ MOHAND   pack unpack ne ma...
12
		$stamp = $time->format('U.u');
5446b8f0   Benjamin Renard   Move CacheTools i...
13
14
15
16
17
		unset($time);
		return $stamp;
	}

	public static function stamp2iso($stamp) {
f7fefad1   Hacene SI HADJ MOHAND   progress
18
19
                                        $intStamp = floor($stamp);
                                        $intMilli = round(($stamp-$intStamp)*1000);
70c8089a   Hacene SI HADJ MOHAND   seems ok
20
                                        // c'est moche mais setTime de php ne prends pas en compte les ms 
3a8eaaff   Hacene SI HADJ MOHAND   resolue
21
22
                                        $strMilli = str_pad(strval($intMilli),3, '0', STR_PAD_LEFT);
                                        $dateIso = date("Y-m-d\TH:i:s",$intStamp).'.'.$strMilli;
70c8089a   Hacene SI HADJ MOHAND   seems ok
23
		return $dateIso;
5446b8f0   Benjamin Renard   Move CacheTools i...
24
25
26
27
	}
}

?>