diff options
| author | Mohammad Akhlaghi <mohammad@akhlaghi.org> | 2020-03-15 19:37:51 +0000 |
|---|---|---|
| committer | Mohammad Akhlaghi <mohammad@akhlaghi.org> | 2020-03-15 19:37:51 +0000 |
| commit | 51ee136ddb3867103d54b15864945a901e79de1d (patch) | |
| tree | 41a660f38416989f471abbc61a86317b8c24ae60 | |
| parent | 0d5776acd448de897ab08aaf1acc5041a9fbaf3f (diff) | |
| download | gnuastro-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-- | NEWS | 1 | ||||
| -rw-r--r-- | lib/fits.c | 10 |
2 files changed, 7 insertions, 4 deletions
@@ -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. @@ -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; |
