wi_date_t * wi_date_init_with_string(wi_date_t *date, wi_string_t *string, wi_string_t *format) { wi_regexp_t *regexp; wi_string_t *substring; struct tm tm; time_t clock; wi_uinteger_t count, offset, hours, minutes; memset(&tm, 0, sizeof(tm)); if(!strptime(wi_string_utf8_string(string), wi_string_utf8_string(format), &tm)) { wi_release(date); return NULL; } offset = 0; if(wi_string_contains_string(format, WI_STR("%z"), WI_STRING_CASE_INSENSITIVE)) { regexp = wi_regexp_with_pattern(WI_STR("((\\+|\\-)[0-9]{4})"), 0); substring = wi_regexp_string_of_first_match_in_string(regexp, string); if(substring) { hours = wi_string_uinteger(wi_string_substring_with_range(substring, wi_make_range(1, 2))); minutes = wi_string_uinteger(wi_string_substring_with_range(substring, wi_make_range(3, 2))); offset = (hours * 3600) + (minutes * 60); if(wi_string_has_prefix(substring, WI_STR("-"))) offset = -offset; } } clock = wi_timegm(&tm) - offset; return wi_date_init_with_time(date, clock); }
static wi_boolean_t wd_users_get_human_readable_version(wi_string_t *version, wi_string_t **application_name, wi_string_t **application_version, wi_string_t **os_name, wi_string_t **os_version, wi_string_t **arch) { wi_range_t range; wi_uinteger_t index; range = wi_make_range(0, wi_string_length(version)); index = wi_string_index_of_string_in_range(version, WI_STR("/"), 0, range); if(index == WI_NOT_FOUND || index == range.length - 1) return false; *application_name = wi_string_substring_with_range(version, wi_make_range(range.location, index - range.location)); range.location = index + 1; range.length -= index + 1; index = wi_string_index_of_string_in_range(version, WI_STR(" ("), 0, range); if(index == WI_NOT_FOUND || index == range.length - 2) return false; *application_version = wi_string_substring_with_range(version, wi_make_range(range.location, index - range.location)); range.location = index + 2; range.length -= index + 2; index = wi_string_index_of_string_in_range(version, WI_STR("; "), 0, range); if(index == WI_NOT_FOUND || index == range.length - 2) return false; *os_name = wi_string_substring_with_range(version, wi_make_range(range.location, index - range.location)); range.location = index + 2; range.length -= index + 2; index = wi_string_index_of_string_in_range(version, WI_STR("; "), 0, range); if(index == WI_NOT_FOUND || index == range.length - 2) return false; *os_version = wi_string_substring_with_range(version, wi_make_range(range.location, index - range.location)); range.location = index + 2; range.length -= index + 2; index = wi_string_index_of_string_in_range(version, WI_STR(")"), 0, range); if(index == WI_NOT_FOUND || index == range.length - 1) return false; *arch = wi_string_substring_with_range(version, wi_make_range(range.location, index - range.location)); return true; }