Example #1
0
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);
}
Example #2
0
wi_date_t * wi_date_init_with_string(wi_date_t *date, wi_string_t *string, wi_string_t *format) {
	struct tm		tm;
	time_t			time;

	memset(&tm, 0, sizeof(tm));

	if(!strptime(wi_string_cstring(string), wi_string_cstring(format), &tm)) {
		wi_release(date);
		
		return NULL;
	}

	tm.tm_isdst = -1;

	time = mktime(&tm);
	
	return wi_date_init_with_time(date, time);
}
Example #3
0
wi_date_t * wi_date_with_time(time_t time) {
	return wi_autorelease(wi_date_init_with_time(wi_date_alloc(), time));
}