diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2019-07-30 17:33:19 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2019-08-06 13:59:28 +0200 |
commit | 4ce9c6d0b58bd77bc811d6c1c5caf955a5a0be2f (patch) | |
tree | c232b8d99716d4d2c95363f09f27f5093067c63c /test/lisp/calc/calc-tests.el | |
parent | c676444a43e4634c1f98ec286b5bd9e46b23216b (diff) | |
download | emacs-4ce9c6d0b58bd77bc811d6c1c5caf955a5a0be2f.tar.gz emacs-4ce9c6d0b58bd77bc811d6c1c5caf955a5a0be2f.tar.bz2 emacs-4ce9c6d0b58bd77bc811d6c1c5caf955a5a0be2f.zip |
Fix various Calc date conversions (bug#36822)
* lisp/calc/calc-forms.el (math-absolute-from-gregorian-dt):
Rewrite in a way that I understand, and that actually seems to work.
(math-absolute-from-julian-dt): Use Julian, not Gregorian, leap year
rules for counting days within a year.
(math-julian-date-beginning, math-julian-date-beginning-int):
Change constants to be consistent with their doc strings and the code:
use Rata Die epoch at Dec 31, 1 BC Gregorian proleptic, not Julian.
* doc/misc/calc.texi (Date Forms): Correct difference between Julian
Day and Rata Die.
* test/lisp/calc/calc-tests.el (calc-test-calendar): New test.
Diffstat (limited to 'test/lisp/calc/calc-tests.el')
-rw-r--r-- | test/lisp/calc/calc-tests.el | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el index 77d939eb406..e1ee20b5d2d 100644 --- a/test/lisp/calc/calc-tests.el +++ b/test/lisp/calc/calc-tests.el @@ -193,6 +193,27 @@ An existing calc stack is reused, otherwise a new one is created." (let ((calc-number-radix 36)) (should (equal (math-format-number 12345678901) "36#5,O6A,QT1"))))) +(ert-deftest calc-test-calendar () + "Test calendar conversions (bug#36822)." + (should (equal (calcFunc-julian (math-parse-date "2019-07-27")) 2458692)) + (should (equal (math-parse-date "2019-07-27") '(date 737267))) + (should (equal (calcFunc-julian '(date 0)) 1721425)) + (should (equal (math-date-to-gregorian-dt 1) '(1 1 1))) + (should (equal (math-date-to-gregorian-dt 0) '(-1 12 31))) + (should (equal (math-date-to-gregorian-dt -1721425) '(-4714 11 24))) + (should (equal (math-absolute-from-gregorian-dt 2019 7 27) 737267)) + (should (equal (math-absolute-from-gregorian-dt 1 1 1) 1)) + (should (equal (math-absolute-from-gregorian-dt -1 12 31) 0)) + (should (equal (math-absolute-from-gregorian-dt -99 12 31) -35795)) + (should (equal (math-absolute-from-gregorian-dt -4714 11 24) -1721425)) + (should (equal (calcFunc-julian '(date -1721425)) 0)) + (should (equal (math-date-to-julian-dt 1) '(1 1 3))) + (should (equal (math-date-to-julian-dt -1721425) '(-4713 1 1))) + (should (equal (math-absolute-from-julian-dt 2019 1 1) 737073)) + (should (equal (math-absolute-from-julian-dt 1 1 3) 1)) + (should (equal (math-absolute-from-julian-dt -101 1 1) -36892)) + (should (equal (math-absolute-from-julian-dt -101 3 1) -36832)) + (should (equal (math-absolute-from-julian-dt -4713 1 1) -1721425))) (provide 'calc-tests) ;;; calc-tests.el ends here |