From 78aa6f935842d67caaf08ca110b8239a00dece5f Mon Sep 17 00:00:00 2001 From: Psionik K <73710933+psionic-k@users.noreply.github.com> Date: Fri, 24 Nov 2023 20:47:09 +0900 Subject: [PATCH] Update internal to avoid precision destruction --- test/test.el | 15 +++++++++++++++ ts.el | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/test/test.el b/test/test.el index e33347e..2026e4f 100644 --- a/test/test.el +++ b/test/test.el @@ -74,11 +74,26 @@ (ert-deftest ts-tz-abbr () (should (equal (ts-tz-abbr (ts-now)) (format-time-string "%Z")))) + + ;; The next cases are anticipated to require an update if ts switches to + ;; (TICKS . HZ) as its implementation time. + ;; (should (let ((ts (ts-now))) + ;; (equal (ts-internal ts) + ;; (time-convert (ts-unix ts) t)))) + ;; (should (let* ((time (float-time)) + ;; (ts (ts-apply :unix time (ts-now)))) + ;; (equal (ts-internal ts) + ;; (time-convert time t)))) + (ert-deftest ts-unix () ;; Theoretically this test could fail if run extremely close to a second boundary, but it's probably good enough. (should (equal (floor (ts-unix (ts-now))) (string-to-number (format-time-string "%s"))))) +(ert-deftest ts-internal () + (should (pcase (ts-internal (ts-now)) + (`(,(pred integerp) . ,(pred integerp)) t)))) + ;;;;; Adjustors ;;;;;; Non-destructive diff --git a/ts.el b/ts.el index 5b2ac3a..748eb38 100644 --- a/ts.el +++ b/ts.el @@ -222,7 +222,7 @@ slot `year' and alias `y' would create an alias `ts-y')." ;; MAYBE: Add tz-offset-minutes (internal - nil :accessor-init (apply #'encode-time (decode-time (ts-unix struct)))) + nil :accessor-init (time-convert (ts-unix struct) t)) (unix nil :accessor-init (pcase-let* (((cl-struct ts second minute hour day month year) struct)) (if (and second minute hour day month year)