-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdtime.cpp
58 lines (43 loc) · 1.04 KB
/
dtime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// dtime.cpp
#include "stdafx.h"
const char* Cdtime::monthNames[12] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
void Cdtime::SetDateTime(int year, int month, int day, int hour, int min, int sec)
{
Y = year;
M = month;
D = day;
h = hour;
m = min;
s = sec;
}
// logDate "Mon Apr 17 13:53:45 2006"
bool Cdtime::ReadLog(const char *logDateTime)
{
char monstr[4];
// --- read log time string
if (sscanf(logDateTime, "%*s %3s %d %d:%d:%d %d",
monstr, &D, &h, &m, &s, &Y) != 6) return false;
// --- read month name
M = 0;
for (M = 0; M < 12; M++) if (strcmp(monthNames[M], monstr) == 0) break;
M++;
// --- check date/time
if (M > 12) return false;
if (D<1 || 31<D) return false;
if (Y<1900 || 2500<Y) return false;
if (h<0 || 23<h) return false;
if (m<0 || 59<m) return false;
if (s<0 || 59<m) return false;
return true;
}
// xmlDate "2006-04-17 13:53:45"
std::string Cdtime::GetXmlDateTime()
{
char dt[24];
sprintf(dt, "%04i-%02i-%02i %02i:%02i:%02i", Y, M, D, h, m, s);
return dt;
}