|
9 | 9 |
|
10 | 10 | date_default_timezone_set(timezone_name_from_abbr($timezoneAbbreviation)); |
11 | 11 |
|
12 | | -$dates = explode(" to ", trim(@$argv[1])); // split arguments by " to " |
| 12 | +$dates = explode(" to ", trim(@$argv[1])); // Split arguments by " to " |
13 | 13 |
|
14 | 14 | array_map(static function($dateString) { |
15 | 15 | return str_replace('-', '/', $dateString); |
16 | 16 | }, $dates); |
17 | 17 |
|
18 | | -/* |
19 | | - * use the current date and time in lieu of a second argument |
| 18 | +/** |
| 19 | + * Use the current date and time in lieu of a second argument |
20 | 20 | */ |
21 | 21 |
|
22 | 22 | try { |
|
33 | 33 | $minutes = (int) $diff->format('%i'); |
34 | 34 | $hours = (int) $diff->format('%h'); |
35 | 35 | $days = (int) $diff->format('%d'); |
36 | | -$total_days = (int) $diff->format('%a'); |
37 | | -$total_hours = $total_days * 24; |
38 | | -$total_minutes = $total_hours * 60; |
| 36 | +$totalDays = (int) $diff->format('%a'); |
| 37 | +$totalHours = $totalDays * 24; |
| 38 | +$totalMinutes = $totalHours * 60; |
39 | 39 | $weeks = (int) $diff->format('%a') / 7; |
40 | | -$business_weeks = (int) $diff->format('%a') / 5; |
| 40 | +$businessWeeks = (int) $diff->format('%a') / 5; |
41 | 41 | $months = (int) $diff->format('%m'); |
42 | 42 | $years = (int) $diff->format('%y'); |
43 | 43 | $sign = $diff->format('%R'); |
44 | 44 |
|
45 | | -if ($total_days > 1) { |
| 45 | +if ($totalDays > 1) { |
46 | 46 | $days++; |
47 | 47 | } |
48 | 48 |
|
49 | 49 |
|
50 | 50 | /* |
51 | | - * a single, complete string; may include years, months, days, hours, minutes, |
52 | | - * and "ago" if there's only one parameter and it's in the past |
| 51 | + * A single, complete string; may include years, months, days, hours, minutes, |
| 52 | + * and “ago” if there’s only one parameter and it’s in the past |
53 | 53 | */ |
54 | 54 |
|
55 | 55 | $complete = []; |
|
61 | 61 | if ($minutes) { $complete[] = pluralize('minute', $minutes); } |
62 | 62 |
|
63 | 63 | if (count($complete) > 1) { |
64 | | - $complete_string = implode(', ', array_slice($complete, 0, -1)); |
65 | | - $complete_string .= " and ".$complete[count($complete)-1]; |
| 64 | + $completeString = implode(', ', array_slice($complete, 0, -1)); |
| 65 | + $completeString .= " and ".$complete[count($complete)-1]; |
66 | 66 | } else { |
67 | | - $complete_string = implode(', ', $complete); |
| 67 | + $completeString = implode(', ', $complete); |
68 | 68 | } |
69 | 69 |
|
70 | 70 | if ( ! isset($dates[1]) && $sign === "+") { |
71 | | - $complete_string .= " ago"; |
| 71 | + $completeString .= " ago"; |
72 | 72 | } |
73 | 73 |
|
74 | 74 | $workflow->item() |
75 | | - ->title($complete_string) |
76 | | - ->arg($complete_string) |
| 75 | + ->title($completeString) |
| 76 | + ->arg($completeString) |
77 | 77 | ->subtitle('Copy to clipboard'); |
78 | 78 |
|
79 | | - |
80 | | -/* |
81 | | - * include business weeks if we have them |
82 | | - */ |
83 | | - |
84 | | -if ($business_weeks > 0) { |
| 79 | +if ($businessWeeks > 0) { |
85 | 80 | $workflow->item() |
86 | | - ->title(pluralize('business week', $business_weeks)) |
87 | | - ->arg(pluralize('business week', $business_weeks)) |
| 81 | + ->title(pluralize('business week', $businessWeeks)) |
| 82 | + ->arg(pluralize('business week', $businessWeeks)) |
88 | 83 | ->subtitle('Copy to clipboard'); |
89 | 84 | } |
90 | 85 |
|
91 | | - |
92 | | -/* |
93 | | - * include weeks if we have them |
94 | | - */ |
95 | | - |
96 | 86 | if ($weeks > 0) { |
97 | 87 | $workflow->item() |
98 | 88 | ->title(pluralize('week', $weeks)) |
|
101 | 91 | } |
102 | 92 |
|
103 | 93 |
|
104 | | -/* |
105 | | - * if the *total* number of days is different from days factoring into the interval, |
106 | | - * we should include it because it's probably interesting |
| 94 | +/** |
| 95 | + * If the *total* number of days is different from days factoring into the interval, |
| 96 | + * we should include it because it’s probably interesting. |
107 | 97 | */ |
108 | | - |
109 | | -if ($total_days > $days) { |
| 98 | +if ($totalDays > $days) { |
110 | 99 | $workflow->item() |
111 | | - ->title(pluralize('day', $total_days)) |
112 | | - ->arg(pluralize('day', $total_days)) |
| 100 | + ->title(pluralize('day', $totalDays)) |
| 101 | + ->arg(pluralize('day', $totalDays)) |
113 | 102 | ->subtitle('Copy to clipboard'); |
114 | 103 | } |
115 | 104 |
|
116 | | - |
117 | | -/* |
118 | | - * include a total count of hours if we've got them |
119 | | - */ |
120 | | - |
121 | | -if ($total_hours > 0) { |
| 105 | +if ($totalHours > 0) { |
122 | 106 | $workflow->item() |
123 | | - ->title(pluralize('hour', $total_hours)) |
124 | | - ->arg(pluralize('hour', $total_hours)) |
| 107 | + ->title(pluralize('hour', $totalHours)) |
| 108 | + ->arg(pluralize('hour', $totalHours)) |
125 | 109 | ->subtitle('Copy to clipboard'); |
126 | 110 | } |
127 | 111 |
|
128 | | - |
129 | | -/* |
130 | | - * include a total count of minutes if we've got them |
131 | | - */ |
132 | | - |
133 | | -if ($total_minutes > 0) { |
| 112 | +if ($totalMinutes > 0) { |
134 | 113 | $workflow->item() |
135 | | - ->title(pluralize('minute', $total_minutes)) |
136 | | - ->arg(pluralize('minute', $total_minutes)) |
| 114 | + ->title(pluralize('minute', $totalMinutes)) |
| 115 | + ->arg(pluralize('minute', $totalMinutes)) |
137 | 116 | ->subtitle('Copy to clipboard'); |
138 | 117 | } |
139 | 118 |
|
140 | 119 | $workflow->output(); |
141 | 120 |
|
142 | 121 |
|
143 | | -/* |
144 | | - * make pretty numbers, and add "s"'s if needed |
| 122 | +/** |
| 123 | + * Format numbers and pluralize as needed. |
145 | 124 | */ |
146 | | - |
147 | 125 | function pluralize($label, $value): string |
148 | 126 | { |
149 | | - return number_format($value) . " ". $label . ($value !== 1 ? "s" : ""); |
| 127 | + return number_format($value) . " " . $label . ($value !== 1 ? "s" : ""); |
150 | 128 | } |
0 commit comments