mirror of
https://github.com/librespeed/speedtest.git
synced 2026-10-21 07:40:50 +00:00
Merge pull request #832 from BKPepe/fix/results-image-timestamp
fix: format the timestamp drawn on the result image
This commit is contained in:
commit
32defb4fb4
1 changed files with 25 additions and 1 deletions
|
|
@ -41,6 +41,30 @@ function format($d)
|
|||
return number_format($d, 0, '.', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops the fractional seconds a database may keep on the timestamp column.
|
||||
*
|
||||
* How much precision that column carries is decided by the backend, and the
|
||||
* three schemas shipped here disagree: MySQL declares `timestamp`, which keeps
|
||||
* none, PostgreSQL uses `timestamp without time zone DEFAULT now()`, which
|
||||
* keeps microseconds, and MSSQL uses `datetime`, which keeps milliseconds. The
|
||||
* value was drawn exactly as the database returned it, so the same result reads
|
||||
* as "2026-08-10 02:04:13" on one deployment and "2026-08-10 02:04:13.957789"
|
||||
* on another.
|
||||
*
|
||||
* The fraction is matched against the seconds field it belongs to rather than
|
||||
* the end of the string, so a value carrying a zone offset after it, such as
|
||||
* "2026-08-10 02:04:13.957789+00", is handled as well.
|
||||
*
|
||||
* @param string $timestamp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function formatTimestamp($timestamp)
|
||||
{
|
||||
return preg_replace('/(:\d{2})\.\d+/', '$1', (string) $timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $speedtest
|
||||
*
|
||||
|
|
@ -53,7 +77,7 @@ function formatSpeedtestDataForImage($speedtest)
|
|||
$speedtest['ul'] = format($speedtest['ul']);
|
||||
$speedtest['ping'] = format($speedtest['ping']);
|
||||
$speedtest['jitter'] = format($speedtest['jitter']);
|
||||
$speedtest['timestamp'] = $speedtest['timestamp'];
|
||||
$speedtest['timestamp'] = formatTimestamp($speedtest['timestamp']);
|
||||
|
||||
$ispinfo = json_decode($speedtest['ispinfo'], true)['processedString'];
|
||||
$dash = strpos($ispinfo, '-');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue