all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: Pankaj Jangid <pankaj@codeisgreat.org>
Cc: 44237@debbugs.gnu.org
Subject: bug#44237: 28.0.50; Incorrect sunrise time for two days around 31st December 2020
Date: Mon, 26 Oct 2020 19:26:47 +0100	[thread overview]
Message-ID: <BD32C999-8D5E-406B-BE7C-7C15DD92A1CA@acm.org> (raw)
In-Reply-To: <m2k0vdfc6s.fsf@mb2.local.i-did-not-set--mail-host-address--so-tickle-me>

[-- Attachment #1: Type: text/plain, Size: 46 bytes --]

Thanks for the report! Does this patch help?


[-- Attachment #2: 0001-Fix-sunrise-and-sunset-calculation-bug-44237.patch --]
[-- Type: application/octet-stream, Size: 3569 bytes --]

From 12fad1d89b101662d3c81c92138e8801f6ad7622 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Mon, 26 Oct 2020 18:44:05 +0100
Subject: [PATCH] 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.
---
 lisp/calendar/solar.el            |  4 +--
 test/lisp/calendar/solar-tests.el | 42 +++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)
 create mode 100644 test/lisp/calendar/solar-tests.el

diff --git a/lisp/calendar/solar.el b/lisp/calendar/solar.el
index 05bb3164e1..07562f6224 100644
--- a/lisp/calendar/solar.el
+++ b/lisp/calendar/solar.el
@@ -490,8 +490,8 @@ solar-moment
          (utmin (+ ut (* direction 12.0)))
          (utmax ut)     ; the time searched is between utmin and utmax
          ;; utmin and utmax are in hours.
-         (utmoment-old 0.0)             ; rise or set approximation
-         (utmoment 1.0)                 ; rise or set approximation
+         (utmoment-old utmin)           ; rise or set approximation
+         (utmoment utmax)               ; rise or set approximation
          (hut 0)                        ; sun height at utmoment
          (t0 (car time))
          (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 0000000000..441beafe71
--- /dev/null
+++ b/test/lisp/calendar/solar-tests.el
@@ -0,0 +1,42 @@
+;;; solar-tests.el --- tests for solar.el            -*- lexical-binding: t -*-
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+(require 'ert)
+(require 'solar)
+
+(ert-deftest solar-sunrise-sunset ()
+  ;; Bug#44237: wrong sunrise time on Dec 30 and 31, 2020 for Jaipur.
+  (let ((calendar-latitude 26.9)
+        (calendar-longitude 75.8)
+        (calendar-time-zone +330)
+        (calendar-standard-time-zone-name "IST")
+        (calendar-daylight-time-zone-name "IST")
+        (epsilon (/ 60.0)))             ; Minute accuracy is good enough.
+    (let* ((sunrise-sunset (solar-sunrise-sunset '(12 30 2020)))
+           (sunrise (car (nth 0 sunrise-sunset)))
+           (sunset (car (nth 1 sunrise-sunset))))
+      (should (< (abs (- sunrise 7.27)) epsilon))
+      (should (< (abs (- sunset 17.72)) epsilon)))
+    (let* ((sunrise-sunset (solar-sunrise-sunset '(12 31 2020)))
+           (sunrise (car (nth 0 sunrise-sunset)))
+           (sunset (car (nth 1 sunrise-sunset))))
+      (should (< (abs (- sunrise 7.28)) epsilon))
+      (should (< (abs (- sunset 17.72)) epsilon)))))
+
+(provide 'solar-tests)
-- 
2.21.1 (Apple Git-122.3)


  reply	other threads:[~2020-10-26 18:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 11:39 bug#44237: 28.0.50; Incorrect sunrise time for two days around 31st Decemeber 2020 Pankaj Jangid
2020-10-26 18:26 ` Mattias Engdegård [this message]
2020-10-27  3:52   ` bug#44237: 28.0.50; Incorrect sunrise time for two days around 31st December 2020 Pankaj Jangid
2020-10-27 11:36     ` Mattias Engdegård
2020-10-27 13:04       ` Pankaj Jangid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BD32C999-8D5E-406B-BE7C-7C15DD92A1CA@acm.org \
    --to=mattiase@acm.org \
    --cc=44237@debbugs.gnu.org \
    --cc=pankaj@codeisgreat.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.