BulkUpdater work.
[order_line_extra.git] / hincludes / lib / DateTools.class.php
1 <?php
2
3 class DateTools {
4         public function __construct(){}
5         static function format($d, $f) {
6                 return strftime($f, $d->__t);
7         }
8         static function delta($d, $t) {
9                 return Date::fromTime($d->getTime() + $t);
10         }
11         static $DAYS_OF_MONTH;
12         static function getMonthDays($d) {
13                 $month = $d->getMonth();
14                 $year = $d->getFullYear();
15                 if($month !== 1) {
16                         return DateTools::$DAYS_OF_MONTH[$month];
17                 }
18                 $isB = _hx_mod($year, 4) === 0 && _hx_mod($year, 100) !== 0 || _hx_mod($year, 400) === 0;
19                 return (($isB) ? 29 : 28);
20         }
21         static function seconds($n) {
22                 return $n * 1000.0;
23         }
24         static function minutes($n) {
25                 return $n * 60.0 * 1000.0;
26         }
27         static function hours($n) {
28                 return $n * 60.0 * 60.0 * 1000.0;
29         }
30         static function days($n) {
31                 return $n * 24.0 * 60.0 * 60.0 * 1000.0;
32         }
33         static function parse($t) {
34                 $s = $t / 1000;
35                 $m = $s / 60;
36                 $h = $m / 60;
37                 return _hx_anonymous(array("ms" => _hx_mod($t, 1000), "seconds" => intval(_hx_mod($s, 60)), "minutes" => intval(_hx_mod($m, 60)), "hours" => intval(_hx_mod($h, 24)), "days" => intval($h / 24)));
38         }
39         static function make($o) {
40                 return $o->ms + 1000.0 * ($o->seconds + 60.0 * ($o->minutes + 60.0 * ($o->hours + 24.0 * $o->days)));
41         }
42         function __toString() { return 'DateTools'; }
43 }
44 DateTools::$DAYS_OF_MONTH = new _hx_array(array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31));