-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimestamps.cpp
40 lines (32 loc) · 921 Bytes
/
timestamps.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
#include <iostream>
#include <time.h>
#include <fstream>
#include <string.h>
using namespace std;
int main(int argc, char *argv[]) {
string s;
ifstream ifs(argv[1], ifstream::in);
bool first = 1;
time_t last_timestamp = 0;
while (ifs >> s) {
struct tm tm1;
struct tm tm2;
memset(&tm1, 0, sizeof(struct tm));
memset(&tm2, 0, sizeof(struct tm));
strptime(s.c_str(), "%Y/%m/%d", &tm1);
ifs >> s;
strptime(s.c_str(), "%H:%M:%S", &tm2);
tm1.tm_hour = tm2.tm_hour;
tm1.tm_min = tm2.tm_min;
tm1.tm_sec = tm2.tm_sec;
tm1.tm_isdst = -1;
time_t timestamp = mktime(&tm1);
if (first) {
last_timestamp = timestamp;
first = 0;
} else {
cout << (int)difftime(timestamp, last_timestamp) << endl;
last_timestamp = timestamp;
}
}
}