dt_status_t dt_timezone_lookup()

in src/win32/dt_win32.c [732:777]


dt_status_t dt_timezone_lookup(const char *timezone_name, dt_timezone_t *timezone)
{
    dt_status_t status = DT_UNKNOWN_ERROR;
    tz_aliases_t *aliases = NULL;
    tz_alias_iterator_t *it = TZMAP_BEGIN;
    tz_alias_t *alias = NULL;
    const char *native_tz_name = NULL;

    if (timezone == NULL || timezone_name == NULL) {
        return DT_INVALID_ARGUMENT;
    }

    timezone->reg_tz_data = NULL;
    timezone->reg_tz_data_size = 0;

    if ((status = tzmap_map(timezone_name, &aliases)) != DT_OK) {
        return status;
    }

    while ((status = tzmap_iterate(aliases, &it, &alias)) == DT_OK) {
        if (alias->kind == DT_PREFFERED_TZMAP_TYPE) {
            native_tz_name = alias->name;
            break;
        }
    }

    tzmap_free(aliases);

    if (native_tz_name != NULL) {
        timezone->dtzi = malloc(sizeof(*timezone->dtzi));
        if (GetTimeZoneInformationByName(timezone->dtzi, native_tz_name) == EXIT_SUCCESS) {
            if (dt_timezone_read_registry(timezone)) {
                status = DT_OK;
            } else {
                free(timezone->dtzi);
                status = DT_TIMEZONE_NOT_FOUND;
            }
        } else {
            free(timezone->dtzi);
            status = DT_TIMEZONE_NOT_FOUND;
        }

    }

    return status;
}