-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimestamp.cpp
More file actions
52 lines (43 loc) · 1.02 KB
/
Timestamp.cpp
File metadata and controls
52 lines (43 loc) · 1.02 KB
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
#include <sstream>
#include <iomanip>
#include "Timestamp.h"
using namespace std;
/**
* Construct a new Timestamp object
* @param timestamp A string representing a timestamp
*/
Timestamp::Timestamp(const string ×tamp)
{
parseTimestamp(timestamp);
}
void Timestamp::parseTimestamp(const string ×tamp)
{
istringstream ss(timestamp);
ss >> get_time(&timeStruct, "%Y/%m/%d %H:%M:%S");
}
string Timestamp::formatTimestamp() const
{
ostringstream ss;
ss << put_time(&timeStruct, "%Y/%m/%d %H:%M:%S");
return ss.str();
}
string Timestamp::getMinTimestamp() const
{
tm minTime = timeStruct;
minTime.tm_hour = 0;
minTime.tm_min = 0;
minTime.tm_sec = 0;
ostringstream ss;
ss << put_time(&minTime, "%Y/%m/%d %H:%M:%S");
return ss.str();
}
string Timestamp::getMaxTimestamp() const
{
tm maxTime = timeStruct;
maxTime.tm_hour = 23;
maxTime.tm_min = 59;
maxTime.tm_sec = 59;
ostringstream ss;
ss << put_time(&maxTime, "%Y/%m/%d %H:%M:%S");
return ss.str();
}