From 9a65a22c58067885775a87130331b36ba00cdbbb Mon Sep 17 00:00:00 2001 From: Xiaochang Liu <49294745+SInginc@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:35:52 +0800 Subject: [PATCH 1/2] handles timezone differences in sas --- src/sas/readstat_sas.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/sas/readstat_sas.c b/src/sas/readstat_sas.c index 6d93bd0..07dc849 100644 --- a/src/sas/readstat_sas.c +++ b/src/sas/readstat_sas.c @@ -124,7 +124,8 @@ static time_t sas_epoch(void) { return - 3653 * 86400; // seconds between 01-01-1960 and 01-01-1970 } -static time_t sas_convert_time(double time, time_t epoch) { +static time_t sas_convert_time(double time, double time_diff, time_t epoch) { + time -= time_diff; time += epoch; if (isnan(time)) return 0; @@ -212,7 +213,7 @@ readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *hinfo, goto cleanup; } - double creation_time, modification_time; + double creation_time, modification_time, creation_time_diff, modification_time_diff; if (io->read(&creation_time, sizeof(double), io->io_ctx) < sizeof(double)) { retval = READSTAT_ERROR_READ; @@ -228,13 +229,27 @@ readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *hinfo, if (bswap) modification_time = byteswap_double(modification_time); - hinfo->creation_time = sas_convert_time(creation_time, epoch); - hinfo->modification_time = sas_convert_time(modification_time, epoch); - - if (io->seek(16, READSTAT_SEEK_CUR, io->io_ctx) == -1) { - retval = READSTAT_ERROR_SEEK; + if (io->read(&creation_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) { + retval = READSTAT_ERROR_READ; goto cleanup; } + if (bswap) + creation_time_diff = byteswap_double(creation_time_diff); + + if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) { + retval = READSTAT_ERROR_READ; + goto cleanup; + } + if (bswap) + modification_time_diff = byteswap_double(modification_time_diff); + + hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch); + hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch); + + // if (io->seek(16, READSTAT_SEEK_CUR, io->io_ctx) == -1) { + // retval = READSTAT_ERROR_SEEK; + // goto cleanup; + // } uint32_t header_size, page_size; From 325e077c98da859696796c87ee258d56eb6a5e44 Mon Sep 17 00:00:00 2001 From: Xiaochang Liu <49294745+SInginc@users.noreply.github.com> Date: Fri, 12 Jan 2024 22:29:42 +0800 Subject: [PATCH 2/2] removed comment out code in readstat_sas.c --- src/sas/readstat_sas.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/sas/readstat_sas.c b/src/sas/readstat_sas.c index 07dc849..542d466 100644 --- a/src/sas/readstat_sas.c +++ b/src/sas/readstat_sas.c @@ -246,11 +246,6 @@ readstat_error_t sas_read_header(readstat_io_t *io, sas_header_info_t *hinfo, hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch); hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch); - // if (io->seek(16, READSTAT_SEEK_CUR, io->io_ctx) == -1) { - // retval = READSTAT_ERROR_SEEK; - // goto cleanup; - // } - uint32_t header_size, page_size; if (io->read(&header_size, sizeof(uint32_t), io->io_ctx) < sizeof(uint32_t)) {