dt_status_t dt_representation_to_timestamp()

in src/win32/dt_win32.c [291:348]


dt_status_t dt_representation_to_timestamp(const dt_representation_t *representation, const dt_timezone_t *timezone,
                                           dt_timestamp_t *first_timestamp, dt_timestamp_t *second_timestamp)
{
    DWORD dwError;
    TIME_ZONE_INFORMATION tzi;
    SYSTEMTIME tUniversalTime = {0};
    SYSTEMTIME tLocalTime = {0};
    time_t time = 0;
    unsigned long nano = 0;
    struct tm tm = {0};
    dt_status_t status = DT_UNKNOWN_ERROR;

    if (!representation || !first_timestamp) {
        return DT_INVALID_ARGUMENT;
    }

    if (timezone == NULL ) {
        dwError = GetTimeZoneInformation(&tzi);
        if (dwError != 0) {
            return DT_TIMEZONE_NOT_FOUND;
        }
    } else if (timezone->dtzi == NULL) {
        return DT_INVALID_ARGUMENT;
    }

    nano = representation->nano_second;
    status = dt_representation_to_tm(representation, &tm);
    if (status != DT_OK) {
        return status;
    }

    if (SystemTimeFromTm(&tLocalTime, &tm) != EXIT_SUCCESS) {
        //return DT_CONVERT_ERROR;
        return DT_INVALID_ARGUMENT; // TODO: Maybe to return a DT_SYSTEM_CALL_ERROR?
    }

    if (timezone != NULL && (GetTimeZoneInformationForYearLower(tLocalTime.wYear, timezone, &tzi) == FALSE)) {
        return DT_TIMEZONE_NOT_FOUND;
    }


    if (TzSpecificLocalTimeToSystemTime((LPTIME_ZONE_INFORMATION)&tzi, (LPSYSTEMTIME)&tLocalTime, (LPSYSTEMTIME)&tUniversalTime) == FALSE) {
        //return DT_CONVERT_ERROR;
        return DT_INVALID_ARGUMENT; // TODO: Maybe to return a DT_SYSTEM_CALL_ERROR?
    }

    if (SystemTimeToUnixTime(&tUniversalTime, &time) != EXIT_SUCCESS) {
        //return DT_CONVERT_ERROR;
        return DT_INVALID_ARGUMENT; // TODO: Maybe to return a DT_SYSTEM_CALL_ERROR?
    }

    status = dt_posix_time_to_timestamp(time, nano, first_timestamp);
    if (status != DT_OK) {
        return status;
    }

    return DT_OK;
}