Skip to content

Commit 96a5b50

Browse files
committed
Nitpick style.
1 parent 0355771 commit 96a5b50

File tree

1 file changed

+34
-56
lines changed

1 file changed

+34
-56
lines changed

datespan.php

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
date_default_timezone_set(timezone_name_from_abbr($timezoneAbbreviation));
1111

12-
$dates = explode(" to ", trim(@$argv[1])); // split arguments by " to "
12+
$dates = explode(" to ", trim(@$argv[1])); // Split arguments by " to "
1313

1414
array_map(static function($dateString) {
1515
return str_replace('-', '/', $dateString);
1616
}, $dates);
1717

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
2020
*/
2121

2222
try {
@@ -33,23 +33,23 @@
3333
$minutes = (int) $diff->format('%i');
3434
$hours = (int) $diff->format('%h');
3535
$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;
3939
$weeks = (int) $diff->format('%a') / 7;
40-
$business_weeks = (int) $diff->format('%a') / 5;
40+
$businessWeeks = (int) $diff->format('%a') / 5;
4141
$months = (int) $diff->format('%m');
4242
$years = (int) $diff->format('%y');
4343
$sign = $diff->format('%R');
4444

45-
if ($total_days > 1) {
45+
if ($totalDays > 1) {
4646
$days++;
4747
}
4848

4949

5050
/*
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 theres only one parameter and its in the past
5353
*/
5454

5555
$complete = [];
@@ -61,38 +61,28 @@
6161
if ($minutes) { $complete[] = pluralize('minute', $minutes); }
6262

6363
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];
6666
} else {
67-
$complete_string = implode(', ', $complete);
67+
$completeString = implode(', ', $complete);
6868
}
6969

7070
if ( ! isset($dates[1]) && $sign === "+") {
71-
$complete_string .= " ago";
71+
$completeString .= " ago";
7272
}
7373

7474
$workflow->item()
75-
->title($complete_string)
76-
->arg($complete_string)
75+
->title($completeString)
76+
->arg($completeString)
7777
->subtitle('Copy to clipboard');
7878

79-
80-
/*
81-
* include business weeks if we have them
82-
*/
83-
84-
if ($business_weeks > 0) {
79+
if ($businessWeeks > 0) {
8580
$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))
8883
->subtitle('Copy to clipboard');
8984
}
9085

91-
92-
/*
93-
* include weeks if we have them
94-
*/
95-
9686
if ($weeks > 0) {
9787
$workflow->item()
9888
->title(pluralize('week', $weeks))
@@ -101,50 +91,38 @@
10191
}
10292

10393

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 its probably interesting.
10797
*/
108-
109-
if ($total_days > $days) {
98+
if ($totalDays > $days) {
11099
$workflow->item()
111-
->title(pluralize('day', $total_days))
112-
->arg(pluralize('day', $total_days))
100+
->title(pluralize('day', $totalDays))
101+
->arg(pluralize('day', $totalDays))
113102
->subtitle('Copy to clipboard');
114103
}
115104

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) {
122106
$workflow->item()
123-
->title(pluralize('hour', $total_hours))
124-
->arg(pluralize('hour', $total_hours))
107+
->title(pluralize('hour', $totalHours))
108+
->arg(pluralize('hour', $totalHours))
125109
->subtitle('Copy to clipboard');
126110
}
127111

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) {
134113
$workflow->item()
135-
->title(pluralize('minute', $total_minutes))
136-
->arg(pluralize('minute', $total_minutes))
114+
->title(pluralize('minute', $totalMinutes))
115+
->arg(pluralize('minute', $totalMinutes))
137116
->subtitle('Copy to clipboard');
138117
}
139118

140119
$workflow->output();
141120

142121

143-
/*
144-
* make pretty numbers, and add "s"'s if needed
122+
/**
123+
* Format numbers and pluralize as needed.
145124
*/
146-
147125
function pluralize($label, $value): string
148126
{
149-
return number_format($value) . " ". $label . ($value !== 1 ? "s" : "");
127+
return number_format($value) . " " . $label . ($value !== 1 ? "s" : "");
150128
}

0 commit comments

Comments
 (0)