| ... | ... |
@@ -19,25 +19,33 @@ |
| 19 | 19 |
///\file |
| 20 | 20 |
///\brief Some basic non-inline functions and static global data. |
| 21 | 21 |
|
| 22 | 22 |
#include<lemon/bits/windows.h> |
| 23 | 23 |
|
| 24 | 24 |
#ifdef WIN32 |
| 25 | 25 |
#ifndef WIN32_LEAN_AND_MEAN |
| 26 | 26 |
#define WIN32_LEAN_AND_MEAN |
| 27 | 27 |
#endif |
| 28 | 28 |
#ifndef NOMINMAX |
| 29 | 29 |
#define NOMINMAX |
| 30 | 30 |
#endif |
| 31 |
#ifdef UNICODE |
|
| 32 |
#undef UNICODE |
|
| 33 |
#endif |
|
| 31 | 34 |
#include <windows.h> |
| 35 |
#ifdef LOCALE_INVARIANT |
|
| 36 |
#define MY_LOCALE LOCALE_INVARIANT |
|
| 37 |
#else |
|
| 38 |
#define MY_LOCALE LOCALE_NEUTRAL |
|
| 39 |
#endif |
|
| 32 | 40 |
#else |
| 33 | 41 |
#include <unistd.h> |
| 34 | 42 |
#include <ctime> |
| 35 | 43 |
#include <sys/times.h> |
| 36 | 44 |
#include <sys/time.h> |
| 37 | 45 |
#endif |
| 38 | 46 |
|
| 39 | 47 |
#include <cmath> |
| 40 | 48 |
#include <sstream> |
| 41 | 49 |
|
| 42 | 50 |
namespace lemon {
|
| 43 | 51 |
namespace bits {
|
| ... | ... |
@@ -78,45 +86,33 @@ |
| 78 | 86 |
stime=ts.tms_stime/tck; |
| 79 | 87 |
cutime=ts.tms_cutime/tck; |
| 80 | 88 |
cstime=ts.tms_cstime/tck; |
| 81 | 89 |
#endif |
| 82 | 90 |
} |
| 83 | 91 |
|
| 84 | 92 |
std::string getWinFormattedDate() |
| 85 | 93 |
{
|
| 86 | 94 |
std::ostringstream os; |
| 87 | 95 |
#ifdef WIN32 |
| 88 | 96 |
SYSTEMTIME time; |
| 89 | 97 |
GetSystemTime(&time); |
| 90 |
#if defined(_MSC_VER) && (_MSC_VER < 1500) |
|
| 91 |
LPWSTR buf1, buf2, buf3; |
|
| 92 |
if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
| 93 |
L"ddd MMM dd", buf1, 11) && |
|
| 94 |
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
| 95 |
L"HH':'mm':'ss", buf2, 9) && |
|
| 96 |
GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
| 97 |
L"yyyy", buf3, 5)) {
|
|
| 98 |
char buf1[11], buf2[9], buf3[5]; |
|
| 99 |
if (GetDateFormat(MY_LOCALE, 0, &time, |
|
| 100 |
("ddd MMM dd"), buf1, 11) &&
|
|
| 101 |
GetTimeFormat(MY_LOCALE, 0, &time, |
|
| 102 |
("HH':'mm':'ss"), buf2, 9) &&
|
|
| 103 |
GetDateFormat(MY_LOCALE, 0, &time, |
|
| 104 |
("yyyy"), buf3, 5)) {
|
|
| 98 | 105 |
os << buf1 << ' ' << buf2 << ' ' << buf3; |
| 99 | 106 |
} |
| 100 |
#else |
|
| 101 |
char buf1[11], buf2[9], buf3[5]; |
|
| 102 |
if (GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
| 103 |
"ddd MMM dd", buf1, 11) && |
|
| 104 |
GetTimeFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
| 105 |
"HH':'mm':'ss", buf2, 9) && |
|
| 106 |
GetDateFormat(LOCALE_USER_DEFAULT, 0, &time, |
|
| 107 |
"yyyy", buf3, 5)) {
|
|
| 108 |
os << buf1 << ' ' << buf2 << ' ' << buf3; |
|
| 109 |
} |
|
| 110 |
#endif |
|
| 111 | 107 |
else os << "unknown"; |
| 112 | 108 |
#else |
| 113 | 109 |
timeval tv; |
| 114 | 110 |
gettimeofday(&tv, 0); |
| 115 | 111 |
|
| 116 | 112 |
char cbuf[26]; |
| 117 | 113 |
ctime_r(&tv.tv_sec,cbuf); |
| 118 | 114 |
os << cbuf; |
| 119 | 115 |
#endif |
| 120 | 116 |
return os.str(); |
| 121 | 117 |
} |
| 122 | 118 |
|
0 comments (0 inline)