📄 wince_time.cpp
字号:
/* * Check to see if there is a daylight time bias. Since the * StandardBias has been added into _timezone, it must be * compensated for in the value computed for _dstbias. */ if ( (tzinfo.DaylightDate.wMonth != 0) && (tzinfo.DaylightBias != 0) ) { _daylight = 1; _dstbias = (tzinfo.DaylightBias - tzinfo.StandardBias) * 60L; } else { _daylight = 0; /* * Set daylight bias to 0 because GetTimeZoneInformation * may return TIME_ZONE_ID_DAYLIGHT even though there is * no DST (in NT 3.51, just turn off the automatic DST * adjust in the control panel)! */ _dstbias = 0; } /* * Try to grab the name strings for both the time zone and the * daylight zone. Note the wide character strings in tzinfo * must be converted to multibyte characters strings. The * locale codepage, __lc_codepage, is used for this. Note that * if setlocale() with LC_ALL or LC_CTYPE has not been called, * then __lc_codepage will be 0 (_CLOCALECP), which is CP_ACP * (which means use the host's default ANSI codepage). */ if ( (WideCharToMultiByte( __lc_codepage, WC_COMPOSITECHECK | WC_SEPCHARS, tzinfo.StandardName, -1, _tzname[0], 63, NULL, &defused ) != 0) && (!defused) ) _tzname[0][63] = '\0'; else _tzname[0][0] = '\0'; if ( (WideCharToMultiByte( __lc_codepage, WC_COMPOSITECHECK | WC_SEPCHARS, tzinfo.DaylightName, -1, _tzname[1], 63, NULL, &defused ) != 0) && (!defused) ) _tzname[1][63] = '\0'; else _tzname[1][0] = '\0'; } /* * Time zone information is unavailable, just return. */ return; }}/****struct tm *localtime(ptime) - convert time_t value to tm structure**Purpose:* Convert a value in internal (time_t) format to a tm struct* containing the corresponding local time.** NOTES:* (1) gmtime must be called before _isindst to ensure that the tb time* structure is initialized.* (2) gmtime and localtime use a single statically allocated buffer.* Each call to one of these routines destroys the contents of the* previous call.* (3) It is assumed that time_t is a 32-bit long integer representing* the number of seconds since 00:00:00, 01-01-70 (UTC) (i.e., the* Posix/Unix Epoch. Only non-negative values are supported.* (4) It is assumed that the maximum adjustment for local time is* less than three days (include Daylight Savings Time adjustment).* This only a concern in Posix where the specification of the TZ* environment restricts the combined offset for time zone and* Daylight Savings Time to 2 * (24:59:59), just under 50 hours.**Entry:* time_t *ptime - pointer to a long time value**Exit:* If *ptime is non-negative, returns a pointer to the tm structure.* Otherwise, returns NULL.**Exceptions:* See items (3) and (4) in the NOTES above. If these assumptions are* violated, behavior is undefined.********************************************************************************/struct tm * __cdecl localtime ( const time_t *ptime ){ struct tm *ptm; long ltime; /* * Check for illegal time_t value */ if ( (long)*ptime < 0L ) return( NULL );#ifdef _WIN32 __tzset();#else /* _WIN32 */#if defined (_M_MPPC) || defined (_M_M68K) _tzset();#endif /* defined (_M_MPPC) || defined (_M_M68K) */#endif /* _WIN32 */ if ( (*ptime > 3 * _DAY_SEC) && (*ptime < LONG_MAX - 3 * _DAY_SEC) ) { /* * The date does not fall within the first three, or last * three, representable days of the Epoch. Therefore, there * is no possibility of overflowing or underflowing the * time_t representation as we compensate for timezone and * Daylight Savings Time. */ ltime = (long)*ptime - _timezone; ptm = gmtime( (time_t *)<ime ); /* * Check and adjust for Daylight Saving Time. */ if ( _daylight && _isindst( ptm ) ) { ltime -= _dstbias; ptm = gmtime( (time_t *)<ime ); ptm->tm_isdst = 1; } } else { ptm = gmtime( ptime ); /* * The date falls with the first three, or last three days * of the Epoch. It is possible the time_t representation * would overflow or underflow while compensating for * timezone and Daylight Savings Time. Therefore, make the * timezone and Daylight Savings Time adjustments directly * in the tm structure. The beginning of the Epoch is * 00:00:00, 01-01-70 (UTC) and the last representable second * in the Epoch is 03:14:07, 01-19-2038 (UTC). This will be * used in the calculations below. * * First, adjust for the timezone. */ if ( _isindst(ptm) ) ltime = (long)ptm->tm_sec - (_timezone + _dstbias); else ltime = (long)ptm->tm_sec - _timezone; ptm->tm_sec = (int)(ltime % 60); if ( ptm->tm_sec < 0 ) { ptm->tm_sec += 60; ltime -= 60; } ltime = (long)ptm->tm_min + ltime/60; ptm->tm_min = (int)(ltime % 60); if ( ptm->tm_min < 0 ) { ptm->tm_min += 60; ltime -= 60; } ltime = (long)ptm->tm_hour + ltime/60; ptm->tm_hour = (int)(ltime % 24); if ( ptm->tm_hour < 0 ) { ptm->tm_hour += 24; ltime -=24; } ltime /= 24; if ( ltime > 0L ) { /* * There is no possibility of overflowing the tm_mday * and tm_yday fields since the date can be no later * than January 19. */ ptm->tm_wday = (ptm->tm_wday + ltime) % 7; ptm->tm_mday += ltime; ptm->tm_yday += ltime; } else if ( ltime < 0L ) { /* * It is possible to underflow the tm_mday and tm_yday * fields. If this happens, then adjusted date must * lie in December 1969. */ ptm->tm_wday = (ptm->tm_wday + 7 + ltime) % 7; if ( (ptm->tm_mday += ltime) <= 0 ) { ptm->tm_mday += 31; ptm->tm_yday = 364; ptm->tm_mon = 11; ptm->tm_year--; } else { ptm->tm_yday += ltime; } } } return(ptm);}static struct tm tb = { 0 }; /* time block *//****struct tm *gmtime(timp) - convert *timp to a structure (UTC)**Purpose:* Converts the calendar time value, in internal format (time_t), to* broken-down time (tm structure) with the corresponding UTC time.**Entry:* const time_t *timp - pointer to time_t value to convert**Exit:* returns pointer to filled-in tm structure.* returns NULL if *timp < 0L**Exceptions:********************************************************************************/struct tm * __cdecl gmtime ( const time_t *timp ){ long caltim = *timp; /* calendar time to convert */ int islpyr = 0; /* is-current-year-a-leap-year flag */ int tmptim; int *mdays; /* pointer to days or lpdays */ struct tm *ptb = &tb; if ( caltim < 0L ) return(NULL); /* * Determine years since 1970. First, identify the four-year interval * since this makes handling leap-years easy (note that 2000 IS a * leap year and 2100 is out-of-range). */ tmptim = (int)(caltim / _FOUR_YEAR_SEC); caltim -= ((long)tmptim * _FOUR_YEAR_SEC); /* * Determine which year of the interval */ tmptim = (tmptim * 4) + 70; /* 1970, 1974, 1978,...,etc. */ if ( caltim >= _YEAR_SEC ) { tmptim++; /* 1971, 1975, 1979,...,etc. */ caltim -= _YEAR_SEC; if ( caltim >= _YEAR_SEC ) { tmptim++; /* 1972, 1976, 1980,...,etc. */ caltim -= _YEAR_SEC; /* * Note, it takes 366 days-worth of seconds to get past a leap * year. */ if ( caltim >= (_YEAR_SEC + _DAY_SEC) ) { tmptim++; /* 1973, 1977, 1981,...,etc. */ caltim -= (_YEAR_SEC + _DAY_SEC); } else { /* * In a leap year after all, set the flag. */ islpyr++; } } } /* * tmptim now holds the value for tm_year. caltim now holds the * number of elapsed seconds since the beginning of that year. */ ptb->tm_year = tmptim; /* * Determine days since January 1 (0 - 365). This is the tm_yday value. * Leave caltim with number of elapsed seconds in that day. */ ptb->tm_yday = (int)(caltim / _DAY_SEC); caltim -= (long)(ptb->tm_yday) * _DAY_SEC; /* * Determine months since January (0 - 11) and day of month (1 - 31) */ if ( islpyr ) mdays = _lpdays; else mdays = _days; for ( tmptim = 1 ; mdays[tmptim] < ptb->tm_yday ; tmptim++ ) ; ptb->tm_mon = --tmptim; ptb->tm_mday = ptb->tm_yday - mdays[tmptim]; /* * Determine days since Sunday (0 - 6) */ ptb->tm_wday = ((int)(*timp / _DAY_SEC) + _BASE_DOW) % 7; /* * Determine hours since midnight (0 - 23), minutes after the hour * (0 - 59), and seconds after the minute (0 - 59). */ ptb->tm_hour = (int)(caltim / 3600); caltim -= (long)ptb->tm_hour * 3600L; ptb->tm_min = (int)(caltim / 60); ptb->tm_sec = (int)(caltim - (ptb->tm_min) * 60); ptb->tm_isdst = 0; return( (struct tm *)ptb );}int abort() { return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -