Instantly share code, notes, and snippets.

Embed
What would you like to do?
const static timelib_tz_lookup_table* abbr_search(const char *word, timelib_long gmtoffset, int isdst)
{
int abbr_found = 0, offset_found = 0;
const timelib_tz_lookup_table *tp, *abbr_found_elem = NULL, *offset_found_elem = NULL;
if (strcasecmp("utc", word) == 0 || strcasecmp("gmt", word) == 0) {
return timelib_timezone_utc;
}
for (tp = timelib_timezone_lookup; tp->name; tp++) {
if (strcasecmp(word, tp->name) == 0) {
if (!abbr_found) {
abbr_found = 1;
abbr_found_elem = tp;
if (gmtoffset == -1) {
return tp;
}
}
if (tp->gmtoffset == gmtoffset) {
return tp;
}
} else if (!offset_found && tp->gmtoffset == gmtoffset && (isdst == -1 || tp->type == isdst)) {
offset_found = 1;
offset_found_elem = tp;
if (!*word) {
return tp;
}
}
}
if (abbr_found) {
return abbr_found_elem;
} else if (offset_found) {
return offset_found_elem;
}
return NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment