Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@requinix
Created January 24, 2017 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save requinix/dffeb6a11b278182901cd277bc5b6ba8 to your computer and use it in GitHub Desktop.
Save requinix/dffeb6a11b278182901cd277bc5b6ba8 to your computer and use it in GitHub Desktop.
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