From f1932e703217483c2dd806f78411f2895c0bc8c6 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 27 Jun 2020 09:35:31 +0200 Subject: [PATCH] Fix precision error in `db/ntp-to-time' A curcial step in the conversion, namly the computation of the actual time from the seconds since the epoch, had been conducted with too little precision. Now the precision is fixed to a high value throughout the whole computation, and the tests succeed again. --- site-lisp/db-utils-test.el | 6 +++++- site-lisp/db-utils.el | 14 +++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/site-lisp/db-utils-test.el b/site-lisp/db-utils-test.el index e099906..e76b10c 100644 --- a/site-lisp/db-utils-test.el +++ b/site-lisp/db-utils-test.el @@ -15,6 +15,10 @@ (should (equal (db/ntp-to-time #xbd5927ee #xbc616000) "2000-08-31T18:52:30.735860824Z")) (should (equal (db/ntp-to-time #x00000000 #x0000000) - "1900-01-01T00:00:00.000000000Z"))) + "1900-01-01T00:00:00.000000000Z")) + (should (equal (db/ntp-to-time #xd36968b7 #xe74172bf) + "2012-05-25T02:11:03.903342410Z")) + (should (equal (db/ntp-to-time #xe2a16f23 #x80270e76) + "2020-06-27T07:09:23.500595954Z"))) ;;; db-utils-test.el ends here diff --git a/site-lisp/db-utils.el b/site-lisp/db-utils.el index 2353e76..b00d196 100644 --- a/site-lisp/db-utils.el +++ b/site-lisp/db-utils.el @@ -16,16 +16,12 @@ (require 'term) (require 'nsm) (require 'compile) +(require 'calc) +(require 'calc-forms) (autoload 'async-start "async") (autoload 'lispy-mode "lispy") (autoload 'ldap-search "ldap") -(autoload 'calcFunc-unixtime "calc-forms") -(autoload 'calcFunc-year "calc-forms") -(autoload 'calcFunc-month "calc-forms") -(autoload 'calcFunc-day "calc-forms") -(autoload 'calcFunc-hour "calc-forms") -(autoload 'calcFunc-minute "calc-forms") ;;; Application Shortcuts @@ -198,7 +194,8 @@ FORMAT-STRING defaults to some ISO 8601-like format." (string-to-number input-proper 16))))) (list (read-hex "High (hex): ") (read-hex "Low (hex): ")))) - (let* ((unix-time (calcFunc-unixtime (calc-eval (format "%s - 2208988800 + (%s/4294967296)" high low) + (let* ((calc-internal-prec 30) + (unix-time (calcFunc-unixtime (calc-eval (format "%s - 2208988800 + (%s/4294967296)" high low) 'raw) ;; we explicitly call `calcFunc-unixtime' ;; here to set the time zone to UTC @@ -216,8 +213,7 @@ FORMAT-STRING defaults to some ISO 8601-like format." ;; is what has been done in the test example we use in the ;; corresponding regression test … (string-to-number - (calc-eval '("trunc(second($), 9)" calc-internal-prec 30) - 'num unix-time))))) + (calc-eval "trunc(second($), 9)" 'num unix-time))))) (defun conditionally-enable-lispy () "Enable lispy-mode when in `eval-expression’ or in