@@ -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 | { |
@@ -12,13 +12,13 @@ discard block |
||
12 | 12 | const MONTHES_IN_A_YEAR = 12; |
13 | 13 | |
14 | 14 | |
15 | - public static function format($parm=null, $format=null) |
|
15 | + public static function format($parm = null, $format = null) |
|
16 | 16 | { |
17 | 17 | $format = $format ?? self::FORMAT; |
18 | 18 | return parent::format($parm, $format); |
19 | 19 | } |
20 | 20 | |
21 | - public static function today($format=null) |
|
21 | + public static function today($format = null) |
|
22 | 22 | { |
23 | 23 | $format = $format ?? self::FORMAT; |
24 | 24 | return parent::format(null, $format); |
@@ -27,7 +27,7 @@ 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)) |
|
30 | + if (!is_a($a, $c) || !is_a($b, $c)) |
|
31 | 31 | throw new \InvalidArgumentException('ARGUMENT_MUST_HAVE_SAME_TYPE'); |
32 | 32 | return self::days($a) - self::days($b); |
33 | 33 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | { |
37 | 37 | $lfy = $x->format('Y') - 1; // last full year |
38 | 38 | |
39 | - foreach([4, -100, 400] as $f) // leap year factors |
|
39 | + foreach ([4, -100, 400] as $f) // leap year factors |
|
40 | 40 | $d += ($lfy / $f); |
41 | 41 | |
42 | 42 | return (int)(($lfy * 365.25) + $d + $x->format('z')); // days since 1.1.1001 from last year (+|-) leap days + days in current year |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | |
49 | 49 | $previous_part = 'd'; |
50 | 50 | |
51 | - foreach(['w' => self::DAYS_IN_A_WEEK, 'm' => self::WEEKS_IN_A_MONTH, 'y' => self::MONTHES_IN_A_YEAR] as $part => $limit) |
|
51 | + foreach (['w' => self::DAYS_IN_A_WEEK, 'm' => self::WEEKS_IN_A_MONTH, 'y' => self::MONTHES_IN_A_YEAR] as $part => $limit) |
|
52 | 52 | { |
53 | - if($amount_of_days >= $limit) |
|
53 | + if ($amount_of_days >= $limit) |
|
54 | 54 | { |
55 | 55 | $date_diff[$part] = intval($amount_of_days / $limit); |
56 | 56 | $date_diff[$previous_part] = $amount_of_days % $limit; |
@@ -67,21 +67,21 @@ discard block |
||
67 | 67 | return $date_diff; |
68 | 68 | } |
69 | 69 | |
70 | - public static function first_date($year, $month, $format=null) |
|
70 | + public static function first_date($year, $month, $format = null) |
|
71 | 71 | { |
72 | 72 | $format = $format ?? self::FORMAT; |
73 | 73 | return date_format(new \DateTime("$year-$month-1"), $format); |
74 | 74 | } |
75 | 75 | |
76 | - public static function last_date($year,$month, $format=null) |
|
76 | + public static function last_date($year, $month, $format = null) |
|
77 | 77 | { |
78 | 78 | $format = $format ?? self::FORMAT; |
79 | - return date_format(new \DateTime("$year-$month-".self::last_day($year,$month)), $format); |
|
79 | + return date_format(new \DateTime("$year-$month-".self::last_day($year, $month)), $format); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | public static function last_day($year, $month) |
83 | 83 | { |
84 | - return date_format(new \DateTime("$year-$month-1"),'t'); |
|
84 | + return date_format(new \DateTime("$year-$month-1"), 't'); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 |
@@ -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; |