gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master 51ee136 2/2: FITS library: timezone and daylig


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 51ee136 2/2: FITS library: timezone and daylight factored out of date_to_seconds
Date: Sun, 15 Mar 2020 15:44:59 -0400 (EDT)

branch: master
commit 51ee136ddb3867103d54b15864945a901e79de1d
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>

    FITS library: timezone and daylight factored out of date_to_seconds
    
    Until now, in the `gal_fits_key_date_to_seconds' function, we would simply
    return the value of the C library's `mktime'. However, `mktime' also
    accounts for the host's timezone and daylight saving paramters. So in
    effect, the result would be different on different systems (based on their
    timezone).
    
    With this commit, we subtract the standard POSIX C library global variables
    `timezone' and `daylight' from the output of `mktime'. I tested it on my
    system by changing my system's timezone and this fixed the problem.
    
    This bug was found by Zahra Sharbaf.
    
    This fixes bug #57995.
---
 NEWS       |  1 +
 lib/fits.c | 10 ++++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 43c9e97..2c11e68 100644
--- a/NEWS
+++ b/NEWS
@@ -76,6 +76,7 @@ See the end of the file for license conditions.
   bug #57301: MakeCatalog using river sum instead of mean times by clump area.
   bug #57921: Arithmetic's interpolation operator not reading metric.
   bug #57989: Warp not accounting for translation in pixel grid.
+  bug #57995: Fits lib's date to second function affected by host's timezone.
 
 
 
diff --git a/lib/fits.c b/lib/fits.c
index 2e65006..7a76a8c 100644
--- a/lib/fits.c
+++ b/lib/fits.c
@@ -909,8 +909,7 @@ gal_fits_key_clean_str_value(char *string)
 
    The basic FITS string is defined under the `DATE' keyword in the FITS
    standard. For the more complete format which includes timezones, see the
-   W3 standard: https://www.w3.org/TR/NOTE-datetime
-*/
+   W3 standard: https://www.w3.org/TR/NOTE-datetime */
 char *
 gal_fits_key_date_to_struct_tm(char *fitsdate, struct tm *tp)
 {
@@ -1037,8 +1036,11 @@ gal_fits_key_date_to_seconds(char *fitsdate, char 
**subsecstr,
                 tmp);
     }
 
-  /* Convert the `tm' structure to `time_t'. */
-  t=mktime(&tp);
+  /* Convert the `tm' structure to `time_t'. Note that the system's
+     timezone and daylight saving need to be subtracted from the output of
+     `mktime'. Otherwise the result will be different on different
+     host-system timezones (which is not what we want here: bug #57995). */
+  t=mktime(&tp)-timezone-daylight;
 
   /* Return the value and set the output pointer. */
   return (size_t)t;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]