Skip to content

Commit 0ed5aff

Browse files
committed
fix: handle times like 10:05 better in time_range plugin
1 parent 069ab40 commit 0ed5aff

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

dwoo-plugins/time_range.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
function Dwoo_Plugin_time_range(Dwoo_Core $dwoo, $start, $end, $showDate = false)
4+
{
5+
$string = '';
6+
7+
$startDate = strftime('%b %e', $start);
8+
$startHour = (int)strftime('%l', $start);
9+
$startMinute = strftime('%M', $start);
10+
$startAmPm = strftime('%P', $start);
11+
12+
$endDate = strftime('%b %e', $end);
13+
$endHour = (int)strftime('%l', $end);
14+
$endMinute = strftime('%M', $end);
15+
$endAmPm = strftime('%P', $end);
16+
17+
// start time
18+
if ($showDate) {
19+
$string .= $startDate.' ';
20+
}
21+
22+
$string .= $startHour;
23+
24+
if ($startMinute && $startMinute != '00') {
25+
$string .= ':'.$startMinute;
26+
}
27+
28+
if ($end && $start != $end) { // check that there is actually a range
29+
if ($startAmPm != $endAmPm) {
30+
$string .= $startAmPm;
31+
}
32+
33+
// glue
34+
$string .= '&ndash;';
35+
36+
// end time
37+
if ($showDate && ($endDate != $startDate)) {
38+
$string .= $endDate.' ';
39+
}
40+
41+
$string .= $endHour;
42+
43+
if ($endMinute && $endMinute != '00') {
44+
$string .= ':'.$endMinute;
45+
}
46+
47+
$string .= $endAmPm;
48+
} else { // otherwise append am/pm and be done
49+
$string .= $startAmPm;
50+
}
51+
52+
return $string;
53+
}

0 commit comments

Comments
 (0)