wince_time.cpp

来自「FastDb是高效的内存数据库系统」· C++ 代码 · 共 1,766 行 · 第 1/5 页

CPP
1,766
字号
                case('b'):              /* abbreviated month name */                        _store_str((char *)(lc_time->month_abbr[timeptr->tm_mon]),                                 string, left);                        break;                case('B'):              /* full month name */                        _store_str((char *)(lc_time->month[timeptr->tm_mon]),                                 string, left);                        break;                case('c'):              /* date and time display */                        if (__alternate_form)                        {                                __alternate_form = FALSE;                                _store_winword(lc_time->ww_ldatefmt, timeptr, string, left, lc_time);                                if (*left == 0)                                        return;                                *(*string)++=' ';                                (*left)--;                                _store_winword(lc_time->ww_timefmt, timeptr, string, left, lc_time);                        }                        else {                                _store_winword(lc_time->ww_sdatefmt, timeptr, string, left, lc_time);                                if (*left == 0)                                        return;                                *(*string)++=' ';                                (*left)--;                                _store_winword(lc_time->ww_timefmt, timeptr, string, left, lc_time);                        }                        break;                case('d'):              /* mday in decimal (01-31) */                        __no_lead_zeros = __alternate_form;                        _store_num(timeptr->tm_mday, 2, string, left);                        break;                case('H'):              /* 24-hour decimal (00-23) */                        __no_lead_zeros = __alternate_form;                        _store_num(timeptr->tm_hour, 2, string, left);                        break;                case('I'):              /* 12-hour decimal (01-12) */                        __no_lead_zeros = __alternate_form;                        if (!(temp = timeptr->tm_hour%12))                                temp=12;                        _store_num(temp, 2, string, left);                        break;                case('j'):              /* yday in decimal (001-366) */                        __no_lead_zeros = __alternate_form;                        _store_num(timeptr->tm_yday+1, 3, string, left);                        break;                case('m'):              /* month in decimal (01-12) */                        __no_lead_zeros = __alternate_form;                        _store_num(timeptr->tm_mon+1, 2, string, left);                        break;                case('M'):              /* minute in decimal (00-59) */                        __no_lead_zeros = __alternate_form;                        _store_num(timeptr->tm_min, 2, string, left);                        break;                case('p'):              /* AM/PM designation */                        if (timeptr->tm_hour <= 11)                            _store_str((char *)(lc_time->ampm[0]), string, left);                        else                            _store_str((char *)(lc_time->ampm[1]), string, left);                        break;                case('S'):              /* secs in decimal (00-59) */                        __no_lead_zeros = __alternate_form;                        _store_num(timeptr->tm_sec, 2, string, left);                        break;                case('U'):              /* sunday week number (00-53) */                        __no_lead_zeros = __alternate_form;                        wdaytemp = timeptr->tm_wday;                        goto weeknum;   /* join common code */                case('w'):              /* week day in decimal (0-6) */                        __no_lead_zeros = __alternate_form;                        _store_num(timeptr->tm_wday, 1, string, left);                        break;                case('W'):              /* monday week number (00-53) */                        __no_lead_zeros = __alternate_form;                        if (timeptr->tm_wday == 0)  /* monday based */                                wdaytemp = 6;                        else                                wdaytemp = timeptr->tm_wday-1;                weeknum:                        if (timeptr->tm_yday < wdaytemp)                                temp=0;                        else {                                temp = timeptr->tm_yday/7;                                if ((timeptr->tm_yday%7) >= wdaytemp)                                        temp++;                                }                        _store_num(temp, 2, string, left);                        break;                case('x'):              /* date display */                        if (__alternate_form)                        {                                __alternate_form = FALSE;                                _store_winword(lc_time->ww_ldatefmt, timeptr, string, left, lc_time);                        }                        else                        {                                _store_winword(lc_time->ww_sdatefmt, timeptr, string, left, lc_time);                        }                        break;                case('X'):              /* time display */                        __alternate_form = FALSE;                        _store_winword(lc_time->ww_timefmt, timeptr, string, left, lc_time);                        break;                case('y'):              /* year w/o century (00-99) */                        __no_lead_zeros = __alternate_form;                        temp = timeptr->tm_year%100;                        _store_num(temp, 2, string, left);                        break;                case('Y'):              /* year w/ century */                        __no_lead_zeros = __alternate_form;                        temp = (((timeptr->tm_year/100)+19)*100) +                               (timeptr->tm_year%100);                        _store_num(temp, 4, string, left);                        break;                case('Z'):              /* time zone name, if any */                case('z'):              /* time zone name, if any */                        __tzset();      /* Set time zone info */                        _store_str(_tzname[((timeptr->tm_isdst)?1:0)],                                 string, left);                        break;                case('%'):              /* percent sign */                        *(*string)++ = '%';                        (*left)--;                        break;                default:                /* unknown format directive */                        /* ignore the directive and continue */                        /* [ANSI: Behavior is undefined.]    */                        break;        }       /* end % switch */}/* * Cache holding the last time (GMT) for which the Daylight time status was * determined by an API call. */static SYSTEMTIME gmt_cache;/* * Three values of dstflag_cache and dstflag (local variable in code * below) */#define DAYLIGHT_TIME   1#define STANDARD_TIME   0#define UNKNOWN_TIME    -1static int dstflag_cache;/****time_t time(timeptr) - Get current system time and convert to time_t value.**Purpose:*       Gets the current date and time and stores it in internal (time_t)*       format. The time is returned and stored via the pointer passed in*       timeptr. If timeptr == NULL, the time is only returned, not stored in*       *timeptr. The internal (time_t) format is the number of seconds since*       00:00:00, Jan 1 1970 (UTC).**       Note: We cannot use GetSystemTime since its return is ambiguous. In*       Windows NT, in return UTC. In Win32S, probably also Win32C, it*       returns local time.**Entry:*       time_t *timeptr - pointer to long to store time in.**Exit:*       returns the current time.**Exceptions:********************************************************************************/time_t __cdecl time (        time_t *timeptr        ){        time_t tim;        SYSTEMTIME loct, gmt;        TIME_ZONE_INFORMATION tzinfo;        DWORD tzstate;        int dstflag;        /*         * Get local time from Win32         */        GetLocalTime( &loct );        /*         * Determine whether or not the local time is a Daylight Saving         * Time. On Windows NT, the GetTimeZoneInformation API is *VERY*         * expensive. The scheme below is intended to avoid this API call in         * many important case by caching the GMT value and dstflag.In a         * subsequent call to time(), the cached value of dstflag is used         * unless the new GMT differs from the cached value at least in the         * minutes place.         */        GetSystemTime( &gmt );        if ( (gmt.wMinute == gmt_cache.wMinute) &&             (gmt.wHour == gmt_cache.wHour) &&             (gmt.wDay == gmt_cache.wDay) &&             (gmt.wMonth == gmt_cache.wMonth) &&             (gmt.wYear == gmt_cache.wYear) )        {            dstflag = dstflag_cache;        }        else        {            if ( (tzstate = GetTimeZoneInformation( &tzinfo )) != 0xFFFFFFFF )            {                /*                 * Must be very careful in determining whether or not DST is                 * really in effect.                 */                if ( (tzstate == TIME_ZONE_ID_DAYLIGHT) &&                     (tzinfo.DaylightDate.wMonth != 0) &&                     (tzinfo.DaylightBias != 0) )                    dstflag = DAYLIGHT_TIME;                else                    /*                     * When in doubt, assume standard time                     */                    dstflag = STANDARD_TIME;            }            else                dstflag = UNKNOWN_TIME;            dstflag_cache = dstflag;            gmt_cache = gmt;        }        /* convert using our private routine */        tim = __loctotime_t( (int)loct.wYear,                             (int)loct.wMonth,                             (int)loct.wDay,                             (int)loct.wHour,                             (int)loct.wMinute,                             (int)loct.wSecond,                             dstflag );        if (timeptr)                *timeptr = tim;         /* store time if requested */        return tim;}/****time_t __loctotime_t(yr, mo, dy, hr, mn, sc, dstflag) - converts OS local*       time to internal time format (i.e., a time_t value)**Purpose:*       Converts a local time value, obtained in a broken down format from*       the host OS, to time_t format (i.e., the number elapsed seconds since*       01-01-70, 00:00:00, UTC).**Entry:*       int yr, mo, dy -    date*       int hr, mn, sc -    time*       int dstflag    -    1 if Daylight Time, 0 if Standard Time, -1 if*                           not specified.**Exit:*       Returns calendar time value.**Exceptions:********************************************************************************/time_t __cdecl __loctotime_t (        int yr,         /* 0 based */        int mo,         /* 1 based */        int dy,         /* 1 based */        int hr,        int mn,        int sc,        int dstflag ){        int tmpdays;        long tmptim;        struct tm tb;        /*         * Do a quick range check on the year and convert it to a delta         * off of 1900.         */        if ( ((long)(yr -= 1900) < _BASE_YEAR) || ((long)yr > _MAX_YEAR) )                return (time_t)(-1);        /*         * Compute the number of elapsed days in the current year. Note the         * test for a leap year would fail in the year 2100, if this was in         * range (which it isn't).         */        tmpdays = dy + _days[mo - 1];        if ( !(yr & 3) && (mo > 2) )                tmpdays++;        /*         * Compute the number of elapsed seconds since the Epoch. Note the         * computation of elapsed leap years would break down after 2100         * if such values were in range (fortunately, they aren't).         */        tmptim = /* 365 days for each year */                 (((long)yr - _BASE_YEAR) * 365L                 /* one day for each elapsed leap year */                 + (long)((yr - 1) >> 2) - _LEAP_YEAR_ADJUST                 /* number of elapsed days in yr */                 + tmpdays)                 /* convert to hours and add in hr */                 * 24L + hr;        tmptim = /* convert to minutes and add in mn */                 (tmptim * 60L + mn)                 /* convert to seconds and add in sec */                 * 60L + sc;        /*         * Account for time zone.         */        __tzset();        tmptim += _timezone;        /*         * Fill in enough fields of tb for _isindst(), then call it to         * determine DST.         */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?