From fe0996db090e5809fbeb32a699b57c24d911513e Mon Sep 17 00:00:00 2001 From: Evan Miller Date: Tue, 13 Apr 2021 12:28:37 -0400 Subject: [PATCH] Fix Windows handling of SAS creation/modification times --- src/sas/readstat_sas.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sas/readstat_sas.c b/src/sas/readstat_sas.c index 505e878c..9c2b78a9 100644 --- a/src/sas/readstat_sas.c +++ b/src/sas/readstat_sas.c @@ -120,6 +120,10 @@ static readstat_charset_entry_t _charset_table[] = { { .code = 248, .name = "SHIFT_JISX0213" }, }; +static time_t sas_epoch() { + return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970 +} + static time_t sas_convert_time(double time, time_t epoch) { time += epoch; if (isnan(time)) @@ -159,8 +163,7 @@ readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *hinfo, sas_header_end_t header_end; int retval = READSTAT_OK; char error_buf[1024]; - struct tm epoch_tm = { .tm_year = 60, .tm_mday = 1 }; - time_t epoch = mktime(&epoch_tm); + time_t epoch = sas_epoch(); if (io->read(&header_start, sizeof(sas_header_start_t), io->io_ctx) < sizeof(sas_header_start_t)) { retval = READSTAT_ERROR_READ; @@ -338,8 +341,7 @@ readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *hinfo, readstat_error_t sas_write_header(readstat_writer_t *writer, sas_header_info_t *hinfo, sas_header_start_t header_start) { readstat_error_t retval = READSTAT_OK; - struct tm epoch_tm = { .tm_year = 60, .tm_mday = 1 }; - time_t epoch = mktime(&epoch_tm); + time_t epoch = sas_epoch(); memset(header_start.table_name, ' ', sizeof(header_start.table_name));