Skip to content

Commit 595aff7

Browse files
Optimize 24-hour stats loop in yourls-infos.php
- Reduce date() calls from 24 to 1 - Use sprintf and modular arithmetic for hour formatting - Replace intval(date('U')) with time() - Verified 100% output parity with original logic Co-authored-by: projectedanx <238904666+projectedanx@users.noreply.github.com>
1 parent e689d96 commit 595aff7

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

yourls-infos.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,11 @@
176176

177177
$_last_24h = array_column((array)$rows, 'count', 'time');
178178

179-
$now = intval( date('U') );
179+
$now = time();
180+
$current_hour = (int)date('G', $now + ($offset * 3600));
180181
for ($i = 23; $i >= 0; $i--) {
181-
$h = date('H A', ($now - ($i * 60 * 60) + ($offset * 60 * 60)) );
182+
$hour = ($current_hour - $i + 24) % 24;
183+
$h = sprintf('%02d %s', $hour, $hour < 12 ? 'AM' : 'PM');
182184
// If the $last_24h doesn't have all the hours, insert missing hours with value 0
183185
$last_24h[ $h ] = $_last_24h[ $h ] ?? 0;
184186
}

0 commit comments

Comments
 (0)