Beispiel #1
0
    std::string dateToCtimeString(Date_t date) {
        time_t t = date.toTimeT();
        char buf[64];
#if defined(_WIN32)
        ctime_s(buf, sizeof(buf), &t);
#else
        ctime_r(&t, buf);
#endif
        char* milliSecStr = buf + 19;
        snprintf(milliSecStr, 5, ".%03d", static_cast<int32_t>(date.asInt64() % 1000));
        return buf;
    }
Beispiel #2
0
    static inline std::string _dateToISOString(Date_t date, bool local) {
        const int bufSize = 32;
        char buf[bufSize];
        struct tm t;
        time_t_to_Struct(date.toTimeT(), &t, local);
        int pos = strftime(buf, bufSize, MONGO_ISO_DATE_FMT_NO_TZ, &t);
        fassert(16981, 0 < pos);
        char* cur = buf + pos;
        int bufRemaining = bufSize - pos;
        pos = snprintf(cur, bufRemaining, ".%03d", static_cast<int32_t>(date.asInt64() % 1000));
        fassert(16982, bufRemaining > pos && pos > 0);
        cur += pos;
        bufRemaining -= pos;
        if (local) {
            fassert(16983, bufRemaining >= 6);
#ifdef _WIN32
            // NOTE(schwerin): The value stored by _get_timezone is the value one adds to local time
            // to get UTC.  This is opposite of the ISO-8601 meaning of the timezone offset.
            // NOTE(schwerin): Microsoft's timezone code always assumes US rules for daylight
            // savings time.  We can do no better without completely reimplementing localtime_s and
            // related time library functions.
            long msTimeZone;
            _get_timezone(&msTimeZone);
            if (t.tm_isdst) msTimeZone -= 3600;
            const bool tzIsWestOfUTC = msTimeZone > 0;
            const long tzOffsetSeconds = msTimeZone* (tzIsWestOfUTC ? 1 : -1);
            const long tzOffsetHoursPart = tzOffsetSeconds / 3600;
            const long tzOffsetMinutesPart = (tzOffsetSeconds / 60) % 60;
            snprintf(cur, 6, "%c%02ld%02ld",
                     tzIsWestOfUTC ? '-' : '+',
                     tzOffsetHoursPart,
                     tzOffsetMinutesPart);
#else
            strftime(cur, bufRemaining, "%z", &t);
#endif
        }
        else {
            fassert(16984, bufRemaining >= 2);
            *cur = 'Z';
            ++cur;
            *cur = '\0';
        }
        return buf;
    }
Beispiel #3
0
 void ReplSetImpl::veto(const string& host, const Date_t until) {
     lock lk(this);
     _veto[host] = until.toTimeT();
 }