Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handles metadata timezone differences in sas #309

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/sas/readstat_sas.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@
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;
Expand Down Expand Up @@ -212,7 +213,7 @@
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;
Expand All @@ -228,13 +229,22 @@
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;

Check warning on line 234 in src/sas/readstat_sas.c

View check run for this annotation

Codecov / codecov/patch

src/sas/readstat_sas.c#L233-L234

Added lines #L233 - L234 were not covered by tests
}
if (bswap)
creation_time_diff = byteswap_double(creation_time_diff);

Check warning on line 237 in src/sas/readstat_sas.c

View check run for this annotation

Codecov / codecov/patch

src/sas/readstat_sas.c#L237

Added line #L237 was not covered by tests

if (io->read(&modification_time_diff, sizeof(double), io->io_ctx) < sizeof(double)) {
retval = READSTAT_ERROR_READ;

Check warning on line 240 in src/sas/readstat_sas.c

View check run for this annotation

Codecov / codecov/patch

src/sas/readstat_sas.c#L240

Added line #L240 was not covered by tests
goto cleanup;
}
if (bswap)
modification_time_diff = byteswap_double(modification_time_diff);

Check warning on line 244 in src/sas/readstat_sas.c

View check run for this annotation

Codecov / codecov/patch

src/sas/readstat_sas.c#L244

Added line #L244 was not covered by tests

hinfo->creation_time = sas_convert_time(creation_time, creation_time_diff, epoch);
hinfo->modification_time = sas_convert_time(modification_time, modification_time_diff, epoch);

uint32_t header_size, page_size;

Expand Down
Loading