in src/win32/dt_win32.c [232:289]
dt_status_t dt_timestamp_to_representation(const dt_timestamp_t *timestamp, const dt_timezone_t *timezone, dt_representation_t *representation)
{
DWORD dwError = -1;
SYSTEMTIME tLocalTime = {0};
SYSTEMTIME tUniversalTime = {0};
TIME_ZONE_INFORMATION tzi = {0};
time_t time = 0;
unsigned long nano = 0;
struct tm result = {0};
dt_status_t status = DT_UNKNOWN_ERROR;
if (timestamp == NULL || representation == NULL) {
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;
}
status = dt_timestamp_to_posix_time(timestamp, &time, &nano);
if (status != DT_OK) {
return status;
}
if (UnixTimeToSystemTime(&time, &tUniversalTime)) {
//return DT_CONVERT_ERROR;
return DT_INVALID_ARGUMENT; // TODO: Maybe to return a DT_SYSTEM_CALL_ERROR?
}
if (timezone != NULL && (GetTimeZoneInformationForYearLower(tUniversalTime.wYear, timezone, &tzi) == FALSE)) {
//return DT_CONVERT_ERROR;
return DT_INVALID_ARGUMENT; // TODO: Maybe to return a DT_SYSTEM_CALL_ERROR?
}
if (SystemTimeToTzSpecificLocalTime(&tzi, &tUniversalTime, &tLocalTime) == FALSE) {
//return DT_CONVERT_ERROR;
return DT_INVALID_ARGUMENT; // TODO: Maybe to return a DT_SYSTEM_CALL_ERROR?
}
if (TmFromSystemTime(&tLocalTime, &result) != EXIT_SUCCESS) {
//return DT_CONVERT_ERROR;
return DT_INVALID_ARGUMENT; // TODO: Maybe to return a DT_SYSTEM_CALL_ERROR?
}
status = dt_tm_to_representation(&result, nano, representation);
if (status != DT_OK) {
return status;
}
return DT_OK;
}