-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeStamp.cpp
131 lines (100 loc) · 3.32 KB
/
TimeStamp.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/************************************************************************
MeOS - Orienteering Software
Copyright (C) 2009-2015 Melin Software HB
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Melin Software HB - [email protected] - www.melin.nu
Stigbergsvägen 7, SE-75242 UPPSALA, Sweden
************************************************************************/
// TimeStamp.cpp: implementation of the TimeStamp class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "meos.h"
#include "TimeStamp.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TimeStamp::TimeStamp()
{
Time=0;
//Update();
}
TimeStamp::~TimeStamp()
{
}
void TimeStamp::update(TimeStamp &ts)
{
Time=max(Time, ts.Time);
}
void TimeStamp::update()
{
SYSTEMTIME st;
GetLocalTime(&st);
FILETIME ft;
SystemTimeToFileTime(&st, &ft);
__int64 ¤ttime=*(__int64*)&ft;
Time=int((currenttime/10000000)-__int64(370)*365*24*3600);
}
int TimeStamp::getAge() const
{
SYSTEMTIME st;
GetLocalTime(&st);
FILETIME ft;
SystemTimeToFileTime(&st, &ft);
__int64 ¤ttime=*(__int64*)&ft;
int CTime=int((currenttime/10000000)-__int64(370)*365*24*3600);
return CTime-Time;
}
string TimeStamp::getStamp() const
{
__int64 ft64=(__int64(Time)+__int64(370)*365*24*3600)*10000000;
FILETIME &ft=*(FILETIME*)&ft64;
SYSTEMTIME st;
FileTimeToSystemTime(&ft, &st);
char bf[32];
sprintf_s(bf, "%d%02d%02d%02d%02d%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
return bf;
}
string TimeStamp::getStampString() const
{
__int64 ft64=(__int64(Time)+__int64(370)*365*24*3600)*10000000;
FILETIME &ft=*(FILETIME*)&ft64;
SYSTEMTIME st;
FileTimeToSystemTime(&ft, &st);
char bf[32];
sprintf_s(bf, "%d-%02d-%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
return bf;
}
void TimeStamp::setStamp(string s)
{
if (s.size()<14)
return;
SYSTEMTIME st;
memset(&st, 0, sizeof(st));
//const char *ptr=s.c_str();
//sscanf(s.c_str(), "%4hd%2hd%2hd%2hd%2hd%2hd", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
st.wYear=atoi(s.substr(0, 4).c_str());
st.wMonth=atoi(s.substr(4, 2).c_str());
st.wDay=atoi(s.substr(6, 2).c_str());
st.wHour=atoi(s.substr(8, 2).c_str());
st.wMinute=atoi(s.substr(10, 2).c_str());
st.wSecond=atoi(s.substr(12, 2).c_str());
FILETIME ft;
SystemTimeToFileTime(&st, &ft);
__int64 ¤ttime=*(__int64*)&ft;
Time=int((currenttime/10000000)-__int64(370)*365*24*3600);
}