Update to version 3.2
This commit is contained in:
@@ -18,9 +18,10 @@
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <time.h>
|
||||
@@ -168,6 +169,26 @@ inline void normalize(T &sec, U &usec) {
|
||||
}
|
||||
}
|
||||
|
||||
const char *timeFormats[] = {
|
||||
"%FT%T.%fZ", // YYYY-MM-DDThh:mm:ss.ssssssZ
|
||||
"%FT%T.%f", // YYYY-MM-DDThh:mm:ss.ssssss
|
||||
"%FT%TZ", // YYYY-MM-DDThh:mm:ssZ
|
||||
"%FT%T", // YYYY-MM-DDThh:mm:ss
|
||||
"%FT%R", // YYYY-MM-DDThh:mm
|
||||
"%FT%H", // YYYY-MM-DDThh
|
||||
"%Y-%jT%T.%f", // YYYY-DDDThh:mm:ss.ssssss
|
||||
"%Y-%jT%T", // YYYY-DDDThh:mm:ss
|
||||
"%Y-%jT%R", // YYYY-DDDThh:mm
|
||||
"%Y-%jT%H", // YYYY-DDDThh
|
||||
"%F %T.%f", // YYYY-MM-DD hh:mm:ss.ssssss
|
||||
"%F %T", // YYYY-MM-DD hh:mm:ss
|
||||
"%F %R", // YYYY-MM-DD hh:mm
|
||||
"%F %H", // YYYY-MM-DD hh
|
||||
"%F", // YYYY-MM-DD
|
||||
"%Y-%j", // YYYY-DDD
|
||||
"%Y", // YYYY
|
||||
};
|
||||
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
@@ -342,6 +363,17 @@ TimeSpan& TimeSpan::operator=(long t) {
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
TimeSpan& TimeSpan::operator=(const TimeSpan& t) {
|
||||
_timeval = t._timeval;
|
||||
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
TimeSpan& TimeSpan::operator=(double t) {
|
||||
if( t > (double)0x7fffffff || t < -(double)0x80000000 )
|
||||
@@ -801,17 +833,10 @@ Time& Time::localtime() {
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
Time& Time::gmt() {
|
||||
gettimeofday(&_timeval, NULL);
|
||||
time_t secs = (time_t)_timeval.tv_sec;
|
||||
struct tm _tm;
|
||||
#ifndef WIN32
|
||||
_timeval.tv_sec = (long)mktime(::localtime_r(&secs, &_tm));
|
||||
#else
|
||||
// We use the native localtime function of windows, which is thread safe. (But it's not reentrant)
|
||||
_timeval.tv_sec = (long)timegm(::localtime(&secs));
|
||||
#endif
|
||||
|
||||
Time &Time::gmt() {
|
||||
auto us = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
_timeval.tv_sec = us / 1000000;
|
||||
_timeval.tv_usec = us % 1000000;
|
||||
return *this;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
@@ -1055,9 +1080,50 @@ bool Time::fromString(const char* str, const char* fmt) {
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
bool Time::fromString(const char* str) {
|
||||
for ( size_t i = 0; i < sizeof(timeFormats) / sizeof(const char*); ++i ) {
|
||||
if ( fromString(str, timeFormats[i]) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
bool Time::fromString(const std::string& str) {
|
||||
return fromString(str.c_str());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
Time Time::FromString(const char* str, const char* fmt) {
|
||||
Time t;
|
||||
t.fromString(str, fmt);
|
||||
return t;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
Time Time::FromString(const char* str) {
|
||||
Time t;
|
||||
t.fromString(str);
|
||||
return t;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
Time Time::FromString(const std::string& str) {
|
||||
return FromString(str.c_str());
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
Reference in New Issue
Block a user