⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wince_time.cpp

📁 最新版本!fastdb是高效的内存数据库系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#define INSIDE_GIGABASE

#include <winbase.h>
#include "wince_time.h"

/* non-zero if daylight savings time is used */
_CRTIMP int _daylight;

/* offset for Daylight Saving Time */
_CRTIMP long _dstbias;

/* difference in seconds between GMT and local time */
_CRTIMP long _timezone;

/* standard/daylight savings time zone names */
_CRTIMP char * _tzname[2];


struct __lc_time_data {
        char *wday_abbr[7];
        char *wday[7];
        char *month_abbr[12];
        char *month[12];
        char *ampm[2];
        char *ww_sdatefmt;
        char *ww_ldatefmt;
        char *ww_timefmt;
};


static int _lpdays[] = {
        -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
};

static int _days[] = {
        -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364
};

/*
 * Flag indicating that time zone information came from GetTimeZoneInformation
 * API call.
 */
static int tzapiused;

static TIME_ZONE_INFORMATION tzinfo;

/* Prototypes for local routines */
static void __cdecl _expandtime (char specifier, const struct tm *tmptr,
        char **out, size_t *count, struct __lc_time_data *lc_time);
static void __cdecl _store_str (char *in, char **out, size_t *count);
static void __cdecl _store_num (int num, int digits, char **out, size_t *count);
static void __cdecl _store_number (int num, char **out, size_t *count);
static void __cdecl _store_winword (const char *format, const struct tm *tmptr, char **out, size_t *count, struct __lc_time_data *lc_time);

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 __cdecl _isindst(struct tm *);
void __cdecl __tzset(void);

/*
 * DST start and end structs.
 */
static transitiondate dststart = { -1, 0, 0L };
static transitiondate dstend   = { -1, 0, 0L };

/*
 *  Code page.
 */
UINT __lc_codepage = _CLOCALECP;                /* CP_ACP */


/*
time_t __cdecl time(time_t *pTime)
{
        // what a mess for getting a simple time!
        SYSTEMTIME lTime;
        FILETIME lFileTime;

        ::GetLocalTime(&lTime);
        SystemTimeToFileTime(&lTime, &lFileTime);
        ULARGE_INTEGER lNTime = *(ULARGE_INTEGER*)&lFileTime;
        if (0l != pTime)
                *pTime = *(time_t*)&lNTime;
        return *(time_t*)&lNTime;
}
*/

/* LC_TIME data for local "C" */

__declspec(selectany) struct __lc_time_data __lc_time_c = {

        {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"},

        {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
                "Friday", "Saturday", },

        {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
                "Sep", "Oct", "Nov", "Dec"},

        {"January", "February", "March", "April", "May", "June",
                "July", "August", "September", "October",
                "November", "December"},

        {"AM", "PM"}

        , { "M/d/yy" }
        , { "dddd, MMMM dd, yyyy" }
        , { "H:mm:ss" }
        };

/* Pointer to the current LC_TIME data structure. */

struct __lc_time_data *__lc_time_curr = &__lc_time_c;


/* Flags */
static unsigned __alternate_form;
static unsigned __no_lead_zeros;


time_t __cdecl mktime(struct tm * lTms)
{
        SYSTEMTIME lSTime;
        lSTime.wYear = lTms->tm_year + 1900;
        lSTime.wMonth = lTms->tm_mon + 1;
        lSTime.wDay = lTms->tm_mday;
        lSTime.wDayOfWeek = lTms->tm_wday;
        lSTime.wHour = lTms->tm_hour;
        lSTime.wMinute = lTms->tm_min;
        lSTime.wSecond = lTms->tm_sec;
        lSTime.wMilliseconds = 0;

        FILETIME lFileTime;

        SystemTimeToFileTime(&lSTime, &lFileTime);
        ULARGE_INTEGER lNTime = *(ULARGE_INTEGER*)&lFileTime;

        //TODO: update the values of wDay and yDay in the 
        //      original structure.
        return *(time_t*)&lNTime;
}

/*
struct tm * __cdecl localtime(const time_t* pTime)
{
        FILETIME lFileTime = *(FILETIME *)&pTime;
        FILETIME lLocalFileTime;

        ::FileTimeToLocalFileTime(&lFileTime, &lLocalFileTime);

        SYSTEMTIME lSTime;
        if (::FileTimeToSystemTime(&lLocalFimeTime, &lSTime) != 0)
        {
                struct tm* lTms = new struct tm;

                lTms->tm_year   =       lSTime.wYear - 1900;
                lTms->tm_mon    =       lSTime.wMonth - 1;
                lTms->tm_mday   =       lSTime.wDay;
                lTms->tm_wday   =       lSTime.wDayOfWeek;
                lTms->tm_hour   =       lSTime.wHour;
                lTms->tm_min    =       lSTime.wMinute;
                lTms->tm_sec    =       lSTime.wSecond;

                return lTms;
        }
        return 0l;
}

size_t __cdecl wcsftime(wchar_t *pDest, size_t maxsize, const wchar_t *pFormat,
        const struct tm *pTime)
{
        
}
*/

/***
*size_t _Strftime(string, maxsize, format,
*       timeptr, lc_time) - Format a time string for a given locale
*
*Purpose:
*       Place characters into the user's output buffer expanding time
*       format directives as described in the user's control string.
*       Use the supplied 'tm' structure for time data when expanding
*       the format directives. use the locale information at lc_time.
*       [ANSI]
*
*Entry:
*       char *string = pointer to output string
*       size_t maxsize = max length of string
*       const char *format = format control string
*       const struct tm *timeptr = pointer to tb data structure
*               struct __lc_time_data *lc_time = pointer to locale-specific info
*                       (passed as void * to avoid type mismatch with C++)
*
*Exit:
*       !0 = If the total number of resulting characters including the
*       terminating null is not more than 'maxsize', then return the
*       number of chars placed in the 'string' array (not including the
*       null terminator).
*
*       0 = Otherwise, return 0 and the contents of the string are
*       indeterminate.
*
*Exceptions:
*
*******************************************************************************/

size_t __cdecl _Strftime (
        char *string,
        size_t maxsize,
        const char *format,
        const struct tm *timeptr,
                void *lc_time_arg
        )
{
        struct __lc_time_data *lc_time;

        size_t left;                    /* space left in output string */

        /* Copy maxsize into temp. */
        left = maxsize;

        /* Defer initialization until the crtitical section has been entered */
        lc_time = lc_time_arg == 0 ? __lc_time_curr : (struct __lc_time_data *)lc_time_arg;

        /* Copy the input string to the output string expanding the format
        designations appropriately.  Stop copying when one of the following
        is true: (1) we hit a null char in the input stream, or (2) there's
        no room left in the output stream. */

        while (left > 0)
        {
                switch(*format)
                {

                case('\0'):

                        /* end of format input string */
                        goto done;

                case('%'):

                        /* Format directive.  Take appropriate action based
                        on format control character. */

                        format++;                       /* skip over % char */

                        /* process flags */
                        __alternate_form = 0;
                        if (*format == '#')
                        {
                                __alternate_form = 1;
                                format++;
                        }
                        _expandtime(*format, timeptr, &string, &left,
                                                        lc_time);
                        format++;                       /* skip format char */
                        break;


                default:

                        /* store character, bump pointers, dec the char count */
                        if (isleadbyte((int)(*format)) && left > 1)
                        {
                                *string++ = *format++;
                                left--;
                        }
                        *string++ = *format++;
                        left--;
                        break;
                }
        }


        /* All done.  See if we terminated because we hit a null char or because
        we ran out of space */

        done:

        if (left > 0) {

                /* Store a terminating null char and return the number of chars
                we stored in the output string. */

                *string = '\0';
                return(maxsize-left);
        }

        else
                return(0);

}


/***
*_expandtime() - Expand the conversion specifier
*
*Purpose:
*       Expand the given strftime conversion specifier using the time struct
*       and store it in the supplied buffer.
*
*       The expansion is locale-dependent.
*
*       *** For internal use with strftime() only ***
*
*Entry:
*       char specifier = strftime conversion specifier to expand
*       const struct tm *tmptr = pointer to time/date structure
*       char **string = address of pointer to output string
*       size_t *count = address of char count (space in output area)
*       struct __lc_time_data *lc_time = pointer to locale-specific info
*
*Exit:
*       none
*
*Exceptions:
*
*******************************************************************************/

static void __cdecl _expandtime (
        char specifier,
        const struct tm *timeptr,
        char **string,
        size_t *left,
        struct __lc_time_data *lc_time
        )
{
        unsigned temp;                  /* temps */
        int wdaytemp;

        /* Use a copy of the appropriate __lc_time_data pointer.  This
        should prevent the necessity of locking/unlocking in mthread
        code (if we can guarantee that the various __lc_time data
        structures are always in the same segment). contents of time
        strings structure can now change, so thus we do use locking */

        switch(specifier) {             /* switch on specifier */

                case('a'):              /* abbreviated weekday name */
                        _store_str((char *)(lc_time->wday_abbr[timeptr->tm_wday]),
                                 string, left);
                        break;

                case('A'):              /* full weekday name */
                        _store_str((char *)(lc_time->wday[timeptr->tm_wday]),
                                 string, left);
                        break;

⌨️ 快捷键说明

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