Skip to content

Commit 229f6a8

Browse files
committed
Use past time since the day start to display clock
Use the current timestamp rounded to the nearest thirty minutes to take a diff to the day's start at 12 am. Use the past hours * 2 plus 1 if the half hour is past to align the clock correctly. If the rounded current time is 12 am at the next day the diff will return **0 past hours**, but **1 past day**. For this case we will multiply by **24**.
1 parent ef55c7c commit 229f6a8

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

library/Notifications/Widget/Timeline.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,17 +370,13 @@ protected function assemble()
370370
)
371371
);
372372

373-
$beforeHour = $now->format('H');
374373
$now = Util::roundToNearestThirtyMinute($now);
375-
376-
if ($beforeHour === '23' && $now->format('H') === '00') {
377-
$now->sub(new DateInterval('PT30M'));
378-
}
374+
$diff = (new DateTime('today'))->diff($now);
379375

380376
$this->getStyle()->addFor($currentTime, [
381377
'--timeStartColumn' =>
382-
$now->format('G') * 2 // 2 columns per hour
383-
+ ($now->format('i') >= 30 ? 1 : 0) // 1 column for the half hour
378+
($diff->d * 24 + $diff->h) * 2 // 2 columns per hour
379+
+ ($diff->i >= 30 ? 1 : 0) // 1 column for the half hour
384380
+ 1 // CSS starts counting columns from 1, not zero
385381
]);
386382

0 commit comments

Comments
 (0)