Commit 1dd5504def6e1a9d7bb0fdab01c834181d6f9cb0
1 parent
403dcf46
Exists in
master
and in
109 other branches
obsoler folder
Showing
1 changed file
with
0 additions
and
70 deletions
Show diff stats
php/old_amda/DateClass.php deleted
... | ... | @@ -1,70 +0,0 @@ |
1 | -<?php | |
2 | -/** @class DateClass | |
3 | -* $Id: DateClass.php 1131 2012-12-18 16:49:40Z elena $ | |
4 | -* @brief extends DateTime class with createFromFormat for php 5.2 | |
5 | -*/ | |
6 | - | |
7 | - | |
8 | -class DateClass extends DateTime { | |
9 | - | |
10 | -public function getTimestamp(){ | |
11 | - return $this->format ("U"); | |
12 | -} | |
13 | - | |
14 | -/** | |
15 | -* This function calculates the number of days between the first and the second date. Arguments must be subclasses of DateTime | |
16 | -**/ | |
17 | -static function differenceInDays ($firstDate, $secondDate){ | |
18 | - $firstDateTimeStamp = $firstDate->format("U"); | |
19 | - $secondDateTimeStamp = $secondDate->format("U"); | |
20 | - $rv = round ((($firstDateTimeStamp - $secondDateTimeStamp))/86400); | |
21 | - return $rv; | |
22 | -} | |
23 | - | |
24 | -/** | |
25 | -* This function returns an object of DateClass from $time in format $format. See date() for possible values for $format | |
26 | -**/ | |
27 | -static function createFromFormat ($format, $time){ | |
28 | - assert ($format!=""); | |
29 | - if($time==""){ | |
30 | - return new DateClass(); | |
31 | - } | |
32 | - | |
33 | - $regexpArray['Y'] = "(?P<Y>[12][90]\d\d)"; | |
34 | - $regexpArray['m'] = "(?P<m>0[1-9]|1[012])"; | |
35 | - $regexpArray['d'] = "(?P<d>0[1-9]|[12][0-9]|3[01])"; | |
36 | - $regexpArray['-'] = "[-]"; | |
37 | - $regexpArray['.'] = "[\. /.]"; | |
38 | - $regexpArray[':'] = "[:]"; | |
39 | - $regexpArray['/'] = "[\/]"; | |
40 | - $regexpArray['space'] = "[\s]"; | |
41 | - $regexpArray['H'] = "(?P<H>0[0-9]|1[0-9]|2[0-3])"; | |
42 | - $regexpArray['i'] = "(?P<i>[0-5][0-9])"; | |
43 | - $regexpArray['s'] = "(?P<s>[0-5][0-9])"; | |
44 | - | |
45 | - $formatArray = str_split ($format); | |
46 | - $regex = ""; | |
47 | - | |
48 | - // create the regular expression | |
49 | - foreach($formatArray as $character){ | |
50 | - if ($character==" ") $regex = $regex.$regexpArray['space']; | |
51 | - elseif (array_key_exists($character, $regexpArray)) $regex = $regex.$regexpArray[$character]; | |
52 | - } | |
53 | - $regex = "/".$regex."/"; | |
54 | - | |
55 | - // get results for regualar expression | |
56 | - preg_match ($regex, $time, $result); | |
57 | - | |
58 | - // create the init string for the new DateTime | |
59 | - $initString = $result['Y']."-".$result['m']."-".$result['d']; | |
60 | - | |
61 | -// if no value for hours, minutes and seconds was found add 00:00:00 | |
62 | - if (isset($result['H'])) $initString = $initString." ".$result['H'].":".$result['i'].":".$result['s']; | |
63 | - else {$initString = $initString." 00:00:00";} | |
64 | - | |
65 | - $newDate = new DateClass ($initString); | |
66 | - return $newDate; | |
67 | - } | |
68 | -} | |
69 | - | |
70 | -?> |