Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update internal to avoid precision destruction #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions test/test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ts.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down