Fix 0 quantity not displayed
[order_line_extra.git] / hincludes / lib / Date.class.php
1 <?php
2
3 class Date {
4         public function __construct($year, $month, $day, $hour, $min, $sec) {
5                 if(!php_Boot::$skip_constructor) {
6                 $this->__t = mktime($hour, $min, $sec, $month + 1, $day, $year);
7         }}
8         public function toString() {
9                 return date("Y-m-d H:i:s", $this->__t);
10         }
11         public function getDay() {
12                 return intval(date("w", $this->__t));
13         }
14         public function getSeconds() {
15                 return intval(date("s", $this->__t));
16         }
17         public function getMinutes() {
18                 return intval(date("i", $this->__t));
19         }
20         public function getHours() {
21                 return intval(date("G", $this->__t));
22         }
23         public function getDate() {
24                 return intval(date("j", $this->__t));
25         }
26         public function getMonth() {
27                 $m = intval(date("n", $this->__t));
28                 return -1 + $m;
29         }
30         public function getFullYear() {
31                 return intval(date("Y", $this->__t));
32         }
33         public function getPhpTime() {
34                 return $this->__t;
35         }
36         public function getTime() {
37                 return $this->__t * 1000;
38         }
39         public $__t;
40         public function __call($m, $a) {
41                 if(isset($this->$m) && is_callable($this->$m))
42                         return call_user_func_array($this->$m, $a);
43                 else if(isset($this->»dynamics[$m]) && is_callable($this->»dynamics[$m]))
44                         return call_user_func_array($this->»dynamics[$m], $a);
45                 else if('toString' == $m)
46                         return $this->__toString();
47                 else
48                         throw new HException('Unable to call «'.$m.'»');
49         }
50         static function now() {
51                 return Date::fromPhpTime(round(microtime(true), 3));
52         }
53         static function fromPhpTime($t) {
54                 $d = new Date(2000, 1, 1, 0, 0, 0);
55                 $d->__t = $t;
56                 return $d;
57         }
58         static function fromTime($t) {
59                 $d = new Date(2000, 1, 1, 0, 0, 0);
60                 $d->__t = $t / 1000;
61                 return $d;
62         }
63         static function fromString($s) {
64                 return Date::fromPhpTime(strtotime($s));
65         }
66         function __toString() { return $this->toString(); }
67 }