From c335e93deff0f710d1837e2f2ab9a6dfc43b3813 Mon Sep 17 00:00:00 2001 From: Brian Read Date: Fri, 26 Jul 2024 06:24:51 +0100 Subject: [PATCH] Add in php routine to convert Tai64n string to date and time - untested --- root/opt/mailstats/html/ShowDetailedLogs.php | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/root/opt/mailstats/html/ShowDetailedLogs.php b/root/opt/mailstats/html/ShowDetailedLogs.php index 75d6e0a..7db5acb 100644 --- a/root/opt/mailstats/html/ShowDetailedLogs.php +++ b/root/opt/mailstats/html/ShowDetailedLogs.php @@ -22,6 +22,28 @@ function process_file($file_path, $input_param) { } fclose($file); } + +function tai64nToDate($tai64n) { + // Check if the input TAI64N string is valid + if (preg_match('/^@([0-9a-f]{8})([0-9a-f]{8})$/', $tai64n, $matches)) { + // First part: seconds since epoch + $sec_hex = $matches[1]; + // Second part: nanoseconds in hex + $nsec_hex = $matches[2]; + + // Convert hex to decimal + $seconds = hexdec($sec_hex); + $nanoseconds = hexdec($nsec_hex); + + // Calculate the full timestamp in seconds + $timestamp = $seconds + ($nanoseconds / 1e9); // Nanoseconds to seconds + + // Format timestamp to 'Y-m-d H:i:s' + return date('Y-m-d H:i:s', $timestamp); + } else { + throw new InvalidArgumentException("Invalid TAI64N format."); + } +} chdir($directory); foreach ($files as $file) { process_file($file, $input_param);