summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Akhlaghi <mohammad@akhlaghi.org>2020-03-15 19:37:51 +0000
committerMohammad Akhlaghi <mohammad@akhlaghi.org>2020-03-15 19:37:51 +0000
commit51ee136ddb3867103d54b15864945a901e79de1d (patch)
tree41a660f38416989f471abbc61a86317b8c24ae60
parent0d5776acd448de897ab08aaf1acc5041a9fbaf3f (diff)
downloadgnuastro-51ee136.tar.gz
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.
-rw-r--r--NEWS1
-rw-r--r--lib/fits.c10
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;