UINT CDealTime::GetSec() { struct tm *tmNow; _time64(&m_time); tmNow = LOCALTIME_R(&m_time); return tmNow->tm_sec; }
UINT CDealTime::GetWDay() { struct tm *tmNow; _time64(&m_time); tmNow = LOCALTIME_R(&m_time); return tmNow->tm_wday; }
UINT CDealTime::GetMin() { struct tm *tmNow; _time64(&m_time); tmNow = LOCALTIME_R(&m_time); return tmNow->tm_min; }
UINT CDealTime::GetHour() { struct tm *tmNow; _time64(&m_time); tmNow = LOCALTIME_R(&m_time); return tmNow->tm_hour; }
UINT CDealTime::GetYear() { struct tm *tmNow; _time64(&m_time); tmNow = LOCALTIME_R(&m_time); return tmNow->tm_year + 1900; }
CDealTime CDealTime::GetCurrentTime() { struct tm *tmNow; __time64_t longTime; _time64(&longTime); tmNow = LOCALTIME_R(&longTime); return CDealTime(longTime); }
const struct tm *time_tm(const a_time *t) { if (!t->tm.tm_year) { #if CHECK if (!t->time) BUG(); #endif LOCALTIME_R(&t->time, (struct tm *)&t->tm); } return &t->tm; }
int test_hrs3_remaining_out(void) { struct tm ymdhms; time_t t = time(0); LOCALTIME_R(&t, &ymdhms); #define X(ret, x, h, m, s) \ do { \ ymdhms.tm_hour = h; \ ymdhms.tm_min = m; \ ymdhms.tm_sec = s; \ t = mktime(&ymdhms); \ if (ret != hrs3_remaining_out(x, t)) TFAIL(); \ } while_0 X( 1, "9-10", 8, 59, 59); X( 0, "9-10", 9, 0, 0); X( 0, "9-10", 9, 59, 59); X(3600 * 23, "9-10", 10, 0, 0); X( -1, "abc", 0, 0, 0); #undef X return OK; }
struct TM *localtime64_r (const Time64_T *time, struct TM *local_tm) { time_t safe_time; struct tm safe_date; struct TM gm_tm; Year orig_year; int month_diff; assert(local_tm != NULL); /* Use the system localtime() if time_t is small enough */ if( SHOULD_USE_SYSTEM_LOCALTIME(*time) ) { safe_time = *time; TRACE1("Using system localtime for %lld\n", *time); LOCALTIME_R(&safe_time, &safe_date); copy_tm_to_TM(&safe_date, local_tm); assert(check_tm(local_tm)); return local_tm; } if( gmtime64_r(time, &gm_tm) == NULL ) { TRACE1("gmtime64_r returned null for %lld\n", *time); return NULL; } orig_year = gm_tm.tm_year; if (gm_tm.tm_year > (2037 - 1900) || gm_tm.tm_year < (1970 - 1900) ) { TRACE1("Mapping tm_year %lld to safe_year\n", (Year)gm_tm.tm_year); gm_tm.tm_year = safe_year((Year)(gm_tm.tm_year + 1900)) - 1900; } safe_time = timegm64(&gm_tm); if( LOCALTIME_R(&safe_time, &safe_date) == NULL ) { TRACE1("localtime_r(%d) returned NULL\n", (int)safe_time); return NULL; } copy_tm_to_TM(&safe_date, local_tm); local_tm->tm_year = orig_year; if( local_tm->tm_year != orig_year ) { TRACE2("tm_year overflow: tm_year %lld, orig_year %lld\n", (Year)local_tm->tm_year, (Year)orig_year); #ifdef EOVERFLOW errno = EOVERFLOW; #endif return NULL; } month_diff = local_tm->tm_mon - gm_tm.tm_mon; /* When localtime is Dec 31st previous year and gmtime is Jan 1st next year. */ if( month_diff == 11 ) { local_tm->tm_year--; } /* When localtime is Jan 1st, next year and gmtime is Dec 31st, previous year. */ if( month_diff == -11 ) { local_tm->tm_year++; } /* GMT is Jan 1st, xx01 year, but localtime is still Dec 31st in a non-leap xx00. There is one point in the cycle we can't account for which the safe xx00 year is a leap year. So we need to correct for Dec 31st comming out as the 366th day of the year. */ if( !IS_LEAP(local_tm->tm_year) && local_tm->tm_yday == 365 ) local_tm->tm_yday--; assert(check_tm(local_tm)); return local_tm; }