@@ -4,15 +4,15 @@ |
||
| 4 | 4 | |
| 5 | 5 | abstract class Base |
| 6 | 6 | { |
| 7 | - public static function format($parm='now', $format) |
|
| 8 | - { |
|
| 7 | + public static function format($parm='now', $format) |
|
| 8 | + { |
|
| 9 | 9 | try |
| 10 | - { |
|
| 10 | + { |
|
| 11 | 11 | $date = new \DateTimeImmutable("$parm"); |
| 12 | 12 | return $date->format($format); |
| 13 | 13 | } |
| 14 | 14 | catch(\Exception $e) |
| 15 | - { |
|
| 15 | + { |
|
| 16 | 16 | return null; |
| 17 | 17 | } |
| 18 | 18 | } |
@@ -10,8 +10,7 @@ |
||
| 10 | 10 | { |
| 11 | 11 | $date = new \DateTimeImmutable("$parm"); |
| 12 | 12 | return $date->format($format); |
| 13 | - } |
|
| 14 | - catch(\Exception $e) |
|
| 13 | + } catch(\Exception $e) |
|
| 15 | 14 | { |
| 16 | 15 | return null; |
| 17 | 16 | } |
@@ -24,26 +24,26 @@ discard block |
||
| 24 | 24 | return parent::format(null, $format); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - // find the total numbers of days in full years since the mythical 1/1/0001, then add the number of days before the current one in the year passed. Do this for each date, then return the absolute value of the difference |
|
| 28 | - public static function days_diff($a, $b, $c = 'DateTime') |
|
| 29 | - { |
|
| 27 | + // find the total numbers of days in full years since the mythical 1/1/0001, then add the number of days before the current one in the year passed. Do this for each date, then return the absolute value of the difference |
|
| 28 | + public static function days_diff($a, $b, $c = 'DateTime') |
|
| 29 | + { |
|
| 30 | 30 | if(!is_a($a,$c) || !is_a($b,$c)) |
| 31 | 31 | throw new \InvalidArgumentException('ARGUMENT_MUST_HAVE_SAME_TYPE'); |
| 32 | - return self::days($a) - self::days($b); |
|
| 33 | - } |
|
| 32 | + return self::days($a) - self::days($b); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public static function days($x, $d = 0) |
|
| 36 | - { |
|
| 35 | + public static function days($x, $d = 0) |
|
| 36 | + { |
|
| 37 | 37 | $lfy = $x->format('Y') - 1; // last full year |
| 38 | 38 | |
| 39 | - foreach([4, -100, 400] as $f) // leap year factors |
|
| 40 | - $d += ($lfy / $f); |
|
| 39 | + foreach([4, -100, 400] as $f) // leap year factors |
|
| 40 | + $d += ($lfy / $f); |
|
| 41 | 41 | |
| 42 | - return (int)(($lfy * 365.25) + $d + $x->format('z')); // days since 1.1.1001 from last year (+|-) leap days + days in current year |
|
| 43 | - } |
|
| 42 | + return (int)(($lfy * 365.25) + $d + $x->format('z')); // days since 1.1.1001 from last year (+|-) leap days + days in current year |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | public static function days_diff_in_parts($amount_of_days) |
| 46 | - { |
|
| 46 | + { |
|
| 47 | 47 | $date_diff = []; |
| 48 | 48 | |
| 49 | 49 | $previous_part = 'd'; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | return $date_diff; |
| 68 | - } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | public static function first_date($year, $month, $format=null) |
| 71 | 71 | { |
@@ -27,8 +27,9 @@ discard block |
||
| 27 | 27 | // find the total numbers of days in full years since the mythical 1/1/0001, then add the number of days before the current one in the year passed. Do this for each date, then return the absolute value of the difference |
| 28 | 28 | public static function days_diff($a, $b, $c = 'DateTime') |
| 29 | 29 | { |
| 30 | - if(!is_a($a,$c) || !is_a($b,$c)) |
|
| 31 | - throw new \InvalidArgumentException('ARGUMENT_MUST_HAVE_SAME_TYPE'); |
|
| 30 | + if(!is_a($a,$c) || !is_a($b,$c)) { |
|
| 31 | + throw new \InvalidArgumentException('ARGUMENT_MUST_HAVE_SAME_TYPE'); |
|
| 32 | + } |
|
| 32 | 33 | return self::days($a) - self::days($b); |
| 33 | 34 | } |
| 34 | 35 | |
@@ -36,8 +37,10 @@ discard block |
||
| 36 | 37 | { |
| 37 | 38 | $lfy = $x->format('Y') - 1; // last full year |
| 38 | 39 | |
| 39 | - foreach([4, -100, 400] as $f) // leap year factors |
|
| 40 | + foreach([4, -100, 400] as $f) { |
|
| 41 | + // leap year factors |
|
| 40 | 42 | $d += ($lfy / $f); |
| 43 | + } |
|
| 41 | 44 | |
| 42 | 45 | return (int)(($lfy * 365.25) + $d + $x->format('z')); // days since 1.1.1001 from last year (+|-) leap days + days in current year |
| 43 | 46 | } |
@@ -56,8 +59,7 @@ discard block |
||
| 56 | 59 | $date_diff[$previous_part] = $amount_of_days % $limit; |
| 57 | 60 | $previous_part = $part; |
| 58 | 61 | $amount_of_days = intval($amount_of_days / $limit); |
| 59 | - } |
|
| 60 | - else |
|
| 62 | + } else |
|
| 61 | 63 | { |
| 62 | 64 | $date_diff[$previous_part] = $amount_of_days; |
| 63 | 65 | break; |