From 888c505f88f1f3ca7939e03c802ea1ed11b7acbe Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 18 Nov 2017 11:11:48 +0100 Subject: [PATCH] [Utils] Add function to convert NTP packets to human-readable time --- site-lisp/db-utils.el | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index d67d8a5..cda07d5 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -177,6 +177,17 @@ major mode MODE." (--map (string-to-number (concat it) 16)) concat)) +(defun db/ntp-to-time (high low &optional format-string) + "Format NTP time given by HIGH and LOW (both integer) to time as given by FORMAT-STRING. +If not given, FORMAT-STRING defaults to some ISO 8601-like format." + (let* ((high-seconds (- high 2208992400)) ; subtract seconds between 1900-01-01 and the epoch + (l (% high-seconds 65536)) + (h (lsh high-seconds -16)) + (u (floor (* (/ low 4294967296.0) 1e6))) + (p (- low (floor (/ (* u 4294967296) 1e6))))) + (format-time-string (or format-string "%Y-%m-%dT%H:%M:%S.%9NZ") + (list h l u p)))) + ;;; dired