//-----------------------------------------------------------------// long get_total_day(short year, char mon, char day) { if(year < 1970) return -1L; long d = 0; short i = 1970; while(i < year) { d += (long)get_yday(i); i++; } i = 0; while(i < mon) { d += get_mday(year, i); i++; } d += day - 1; return d; }
//-----------------------------------------------------------------// struct tm *gmtime(const time_t *tp) { time_t t; short i, j, k; t = *tp; time_st_.tm_sec = t % (time_t)60; t /= (time_t)60; time_st_.tm_min = t % (time_t)60; t /= (time_t)60; time_st_.tm_hour = t % (time_t)24; t /= (time_t)24; time_st_.tm_wday = (t + 4) % 7; j = 1970; while(t >= (i = get_yday(j))) { t -= (time_t)i; j++; } time_st_.tm_year = j - 1900; time_st_.tm_yday = t; k = 0; while(t >= (i = get_mday(j, k))) { t -= (time_t)i; k++; } time_st_.tm_mon = k; time_st_.tm_mday = t + 1; return &time_st_; }
static time_t decode_broken_date (struct _date_token *tokens, int *tzone) { gboolean got_wday, got_month, got_tzone; int hour, min, sec, offset, n; struct _date_token *token; struct tm tm; time_t time; memset ((void *) &tm, 0, sizeof (struct tm)); got_wday = got_month = got_tzone = FALSE; offset = 0; token = tokens; while (token) { if (is_weekday (token) && !got_wday) { if ((n = get_wday (token->start, token->len)) != -1) { d(printf ("weekday; ")); got_wday = TRUE; tm.tm_wday = n; goto next_token; } } if (is_month (token) && !got_month) { if ((n = get_month (token->start, token->len)) != -1) { d(printf ("month; ")); got_month = TRUE; tm.tm_mon = n; goto next_token; } } if (is_time (token) && !tm.tm_hour && !tm.tm_min && !tm.tm_sec) { if (get_time (token->start, token->len, &hour, &min, &sec)) { d(printf ("time; ")); tm.tm_hour = hour; tm.tm_min = min; tm.tm_sec = sec; goto next_token; } } if (is_tzone (token) && !got_tzone) { struct _date_token *t = token; if ((n = get_tzone (&t)) != -1) { d(printf ("tzone; ")); got_tzone = TRUE; offset = n; goto next_token; } } if (is_numeric (token)) { if (token->len == 4 && !tm.tm_year) { if ((n = get_year (token->start, token->len)) != -1) { d(printf ("year; ")); tm.tm_year = n - 1900; goto next_token; } } else { if (!got_month && !got_wday && token->next && is_numeric (token->next)) { d(printf ("mon; ")); n = decode_int (token->start, token->len); got_month = TRUE; tm.tm_mon = n - 1; goto next_token; } else if (!tm.tm_mday && (n = get_mday (token->start, token->len)) != -1) { d(printf ("mday; ")); tm.tm_mday = n; goto next_token; } else if (!tm.tm_year) { d(printf ("2-digit year; ")); n = get_year (token->start, token->len); tm.tm_year = n - 1900; goto next_token; } } } d(printf ("???; ")); next_token: token = token->next; } d(printf ("\n")); time = e_mktime_utc (&tm); /* time is now GMT of the time we want, but not offset by the timezone ... */ /* this should convert the time to the GMT equiv time */ time -= ((offset / 100) * 60 * 60) + (offset % 100) * 60; if (tzone) *tzone = offset; return time; }