aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMattias Engdegård2020-10-02 18:50:50 +0200
committerMattias Engdegård2020-10-02 22:24:54 +0200
commit0ade20f49f80d2d93f596ba9dfa3f1309ad84126 (patch)
tree5b07796eece45179b7abb21d10de5551ac5c6eea /test
parent6a6466031839d5fb4efadbfe2cdbd5ba469dd9c6 (diff)
downloademacs-0ade20f49f80d2d93f596ba9dfa3f1309ad84126.tar.gz
emacs-0ade20f49f80d2d93f596ba9dfa3f1309ad84126.zip
Calc: fix formatting and parsing Unix time (bug#43759)
The number of days from epoch to Jan 1, 1970 that was used in parsing and formatting Unix time was incorrect. The previous fix (in e368697ce36) was incomplete. Reported by Vincent Belaïche. * lisp/calc/calc-forms.el (math-unix-epoch): New constant. (math-format-date-part, math-parse-standard-date, calcFunc-unixtime): Use math-unix-epoch instead of a constant that is sometimes wrong. * test/lisp/calc/calc-tests.el (calc-unix-date): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/calc/calc-tests.el40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el
index 4dded007f79..0df96a0e2db 100644
--- a/test/lisp/calc/calc-tests.el
+++ b/test/lisp/calc/calc-tests.el
@@ -534,6 +534,46 @@ An existing calc stack is reused, otherwise a new one is created."
534 ) 534 )
535 )) 535 ))
536 536
537(ert-deftest calc-unix-date ()
538 (let* ((d-1970-01-01 (math-parse-date "1970-01-01"))
539 (d-2020-09-07 (math-parse-date "2020-09-07"))
540 (d-1991-01-09-0600 (math-parse-date "1991-01-09 06:00")))
541 ;; calcFunc-unixtime (command "t U") converts a date value to Unix time,
542 ;; and a number to a date.
543 (should (equal d-1970-01-01 '(date 719163)))
544 (should (equal (calcFunc-unixtime d-1970-01-01 0) 0))
545 (should (equal (calc-tests--calc-to-number (cadr (calcFunc-unixtime 0 0)))
546 (cadr d-1970-01-01)))
547 (should (equal (calcFunc-unixtime d-2020-09-07 0)
548 (* (- (cadr d-2020-09-07)
549 (cadr d-1970-01-01))
550 86400)))
551 (should (equal (calcFunc-unixtime d-1991-01-09-0600 0)
552 663400800))
553 (should (equal (calc-tests--calc-to-number
554 (cadr (calcFunc-unixtime 663400800 0)))
555 726841.25))
556
557 (let ((calc-date-format '(U)))
558 ;; Test parsing Unix time.
559 (should (equal (calc-tests--calc-to-number
560 (cadr (math-parse-date "0")))
561 719163))
562 (should (equal (calc-tests--calc-to-number
563 (cadr (math-parse-date "469324800")))
564 (+ 719163 (/ 469324800 86400))))
565 (should (equal (calc-tests--calc-to-number
566 (cadr (math-parse-date "663400800")))
567 726841.25))
568
569 ;; Test formatting Unix time.
570 (should (equal (math-format-date d-1970-01-01) "0"))
571 (should (equal (math-format-date d-2020-09-07)
572 (number-to-string (* (- (cadr d-2020-09-07)
573 (cadr d-1970-01-01))
574 86400))))
575 (should (equal (math-format-date d-1991-01-09-0600) "663400800")))))
576
537(provide 'calc-tests) 577(provide 'calc-tests)
538;;; calc-tests.el ends here 578;;; calc-tests.el ends here
539 579