equal
deleted
inserted
replaced
3 |
3 |
4 /** |
4 /** |
5 * Utilities functions |
5 * Utilities functions |
6 */ |
6 */ |
7 class Utils { |
7 class Utils { |
|
8 |
|
9 /** |
|
10 * convert DateIntervals to milliseconds |
|
11 * Months and year calculated by approximation based on average number |
|
12 * of days over 4 years (365*4+1) |
|
13 * @param \DateInterval $di the date interval |
|
14 * @return the number of milliseconds or 0 if $di is null |
|
15 */ |
|
16 public static function dateIntervalToMillis(\DateInterval $di) { |
|
17 if(is_null($di)) { |
|
18 return 0; |
|
19 } |
|
20 $seconds = ($di->s) |
|
21 + ($di->i * 60) |
|
22 + ($di->h * 60 * 60) |
|
23 + ($di->d * 60 * 60 * 24) |
|
24 + ($di->m * (365*4+1)/48*60*60*24) |
|
25 + ($di->y * (365*4+1)/4*60*60*24); |
|
26 return $seconds*1000; |
|
27 } |
|
28 |
|
29 /** |
|
30 * convert iso8601 strings to milliseconds |
|
31 * Months and year calculated by approximation based on average number |
|
32 * of days over 4 years (365*4+1) |
|
33 * |
|
34 * @param str iso8601 string |
|
35 * @return the number of milliseconds or 0 if $str is null |
|
36 */ |
|
37 public static function iso8601IntervalToMillis($str) { |
|
38 if(is_null($str) || $str === '') { |
|
39 return 0; |
|
40 } |
|
41 $di = new \DateInterval($str); |
|
42 return self::dateIntervalToMillis($di); |
|
43 } |
8 |
44 |
9 /* |
45 /* |
10 * From http://www.thecave.info/php-get-mime-type-from-file-extension/ |
46 * From http://www.thecave.info/php-get-mime-type-from-file-extension/ |
11 */ |
47 */ |
12 public static function getMimetype($file) { |
48 public static function getMimetype($file) { |