diff options
| author | Mattias EngdegÄrd | 2020-10-26 18:44:05 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2020-10-27 12:33:51 +0100 |
| commit | cde72637dfd6989081ed8b2f26e7187c309780b8 (patch) | |
| tree | 1784cc7c3cb1edacd353276fbe1bf422d0b71a2c | |
| parent | f971a612a92eea4c8aab6b002d7998bb0b6f5ca1 (diff) | |
| download | emacs-cde72637dfd6989081ed8b2f26e7187c309780b8.tar.gz emacs-cde72637dfd6989081ed8b2f26e7187c309780b8.zip | |
Fix sunrise and sunset calculation (bug#44237)
* lisp/calendar/solar.el (solar-moment): Use initial values for binary
search that won't end the loop prematurely and yield incorrect
answers.
* test/lisp/calendar/solar-tests.el: New file.
| -rw-r--r-- | lisp/calendar/solar.el | 4 | ||||
| -rw-r--r-- | test/lisp/calendar/solar-tests.el | 42 |
2 files changed, 44 insertions, 2 deletions
diff --git a/lisp/calendar/solar.el b/lisp/calendar/solar.el index 05bb3164e12..07562f62240 100644 --- a/lisp/calendar/solar.el +++ b/lisp/calendar/solar.el | |||
| @@ -490,8 +490,8 @@ Uses binary search." | |||
| 490 | (utmin (+ ut (* direction 12.0))) | 490 | (utmin (+ ut (* direction 12.0))) |
| 491 | (utmax ut) ; the time searched is between utmin and utmax | 491 | (utmax ut) ; the time searched is between utmin and utmax |
| 492 | ;; utmin and utmax are in hours. | 492 | ;; utmin and utmax are in hours. |
| 493 | (utmoment-old 0.0) ; rise or set approximation | 493 | (utmoment-old utmin) ; rise or set approximation |
| 494 | (utmoment 1.0) ; rise or set approximation | 494 | (utmoment utmax) ; rise or set approximation |
| 495 | (hut 0) ; sun height at utmoment | 495 | (hut 0) ; sun height at utmoment |
| 496 | (t0 (car time)) | 496 | (t0 (car time)) |
| 497 | (hmin (cadr (solar-horizontal-coordinates (list t0 utmin) | 497 | (hmin (cadr (solar-horizontal-coordinates (list t0 utmin) |
diff --git a/test/lisp/calendar/solar-tests.el b/test/lisp/calendar/solar-tests.el new file mode 100644 index 00000000000..441beafe71c --- /dev/null +++ b/test/lisp/calendar/solar-tests.el | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | ;;; solar-tests.el --- tests for solar.el -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2020 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | (require 'ert) | ||
| 21 | (require 'solar) | ||
| 22 | |||
| 23 | (ert-deftest solar-sunrise-sunset () | ||
| 24 | ;; Bug#44237: wrong sunrise time on Dec 30 and 31, 2020 for Jaipur. | ||
| 25 | (let ((calendar-latitude 26.9) | ||
| 26 | (calendar-longitude 75.8) | ||
| 27 | (calendar-time-zone +330) | ||
| 28 | (calendar-standard-time-zone-name "IST") | ||
| 29 | (calendar-daylight-time-zone-name "IST") | ||
| 30 | (epsilon (/ 60.0))) ; Minute accuracy is good enough. | ||
| 31 | (let* ((sunrise-sunset (solar-sunrise-sunset '(12 30 2020))) | ||
| 32 | (sunrise (car (nth 0 sunrise-sunset))) | ||
| 33 | (sunset (car (nth 1 sunrise-sunset)))) | ||
| 34 | (should (< (abs (- sunrise 7.27)) epsilon)) | ||
| 35 | (should (< (abs (- sunset 17.72)) epsilon))) | ||
| 36 | (let* ((sunrise-sunset (solar-sunrise-sunset '(12 31 2020))) | ||
| 37 | (sunrise (car (nth 0 sunrise-sunset))) | ||
| 38 | (sunset (car (nth 1 sunrise-sunset)))) | ||
| 39 | (should (< (abs (- sunrise 7.28)) epsilon)) | ||
| 40 | (should (< (abs (- sunset 17.72)) epsilon))))) | ||
| 41 | |||
| 42 | (provide 'solar-tests) | ||