version 1.2, 2015/04/20 18:10:13
|
version 1.3, 2015/04/20 18:19:53
|
|
|
*/ | */ |
| |
#include "datetime.h" | #include "datetime.h" |
#include <base/strings.h> |
#include <pal/strings.h> |
#include <base/io.h> |
#include <pal/format.h> |
#include <base/helpers.h> | #include <base/helpers.h> |
| |
#if defined(_MSC_VER) | #if defined(_MSC_VER) |
|
|
memcpy(buf, &s[offset], size * sizeof(MI_Char)); | memcpy(buf, &s[offset], size * sizeof(MI_Char)); |
buf[size] = '\0'; | buf[size] = '\0'; |
| |
*x = (MI_Uint32)Ztoul(buf, &end, 10); |
*x = (MI_Uint32)Tcstoul(buf, &end, 10); |
| |
if (*end != '\0') | if (*end != '\0') |
return -1; | return -1; |
|
|
| |
static bool _StrToDatetime(const MI_Char* s, MI_Datetime* x) | static bool _StrToDatetime(const MI_Char* s, MI_Datetime* x) |
{ | { |
if (Zlen(s) != 25) |
if (Tcslen(s) != 25) |
return false; | return false; |
| |
memset(x, 0, sizeof(MI_Datetime)); | memset(x, 0, sizeof(MI_Datetime)); |
|
|
return true; | return true; |
} | } |
| |
|
_Use_decl_annotations_ |
void Datetime::ToString(MI_Char buffer[26]) const | void Datetime::ToString(MI_Char buffer[26]) const |
{ | { |
const MI_Datetime* p = (const MI_Datetime*)&_rep; | const MI_Datetime* p = (const MI_Datetime*)&_rep; |
|
|
{ | { |
MI_Char buffer[26]; | MI_Char buffer[26]; |
ToString(buffer); | ToString(buffer); |
Fzprintf(os, T("%s"), buffer); |
Ftprintf(os, PAL_T("%T"), tcs(buffer)); |
} | } |
| |
#define TIMESTAMP_SIZE 128 | #define TIMESTAMP_SIZE 128 |
| |
bool Datetime::SetCurrent() | bool Datetime::SetCurrent() |
{ | { |
/* ATTN: get UTC offset */ |
|
MI_Uint64 usec; |
|
|
|
if (_GetCurrentTimeInUsec(usec) != 0) |
|
return false; |
|
|
|
MI_Uint32 year; | MI_Uint32 year; |
MI_Uint32 month; | MI_Uint32 month; |
MI_Uint32 day; | MI_Uint32 day; |
|
|
| |
#if defined(_MSC_VER) | #if defined(_MSC_VER) |
{ | { |
time_t t = usec / 1000000; |
SYSTEMTIME st; |
struct tm tm; |
GetLocalTime(&st); |
localtime_s(&tm, &t); |
|
year = tm.tm_year + 1900; |
year = st.wYear; |
month = tm.tm_mon + 1; |
month = st.wMonth; |
day = tm.tm_mday; |
day = st.wDay; |
hour = tm.tm_hour; |
hour = st.wHour; |
minute = tm.tm_min; |
minute = st.wMinute; |
second = tm.tm_sec; |
second = st.wSecond; |
microseconds = (MI_Uint32)(usec % MI_Uint64(1000000)); |
microseconds = st.wMilliseconds*1000; |
} | } |
#else | #else |
|
/* ATTN: get UTC offset */ |
|
MI_Uint64 usec; |
|
|
|
if (_GetCurrentTimeInUsec(usec) != 0) |
|
return false; |
|
|
|
|
{ | { |
time_t t = usec / 1000000; | time_t t = usec / 1000000; |
struct tm tm; | struct tm tm; |