Skip to content

Different results of readstat_get_modified_time on Windows and Mac #278

Open

Description

@vonknio

The result of calling readstat_get_modified_time on the same file is different for Windows and Mac. The code for both platforms is as follows:

#include "readstat.h"

struct Context {
    time_t mdate = 0;
};

int handle_metadata(readstat_metadata_t *metadata, void *ctx) {
    Context* context = (Context*)ctx;

    context->mdate = readstat_get_modified_time(metadata);

    return READSTAT_HANDLER_OK;
}

int main(int argc, char *argv[]) {
    if (argc != 2) {
        printf("Usage: %s <filename>\n", argv[0]);
        return 1;
    }

    Context context{};
    readstat_error_t error = READSTAT_OK;
    readstat_parser_t *parser = readstat_parser_init();
    readstat_set_metadata_handler(parser, handle_metadata);

    error = readstat_parse_dta(parser, argv[1], &context);

    readstat_parser_free(parser);

    if (error != READSTAT_OK) {
        printf("Error processing %s: %d\n", argv[1], error);
        return 1;
    }
    printf("Modified date: %ld\n", context.mdate);
    return 0;
}

The output on Windows is:

Modified date: 1031073900

...while the output on Mac is:

Modified date: 1031048700

I'm attaching the sample file. Tested with Readstat 1.1.8.
citytemp.dta.zip

Activity

  1. evanmiller commented on Dec 17, 2022

    @evanmiller
    Contributor

    Hi, these two values appear differ by exactly 7 hours. I am guessing it is a time zone issue. Is this difference important?

  2. evanmiller commented on Oct 12, 2026

    @evanmiller
    Contributor

    The two values are 7 hours apart because Stata (and SPSS, POR and XPORT) store the timestamp with no time zone, and ReadStat reads it in the machine's local zone with mktime. Your two machines are set to different zones. Until this changes, setting TZ the same on both (e.g. TZ=UTC) gives consistent results. This is now documented in readstat.h (9881386); we're considering always reading these timestamps as UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions