Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
TimeStamp.hpp
1
#ifndef TIMESTAMP_H
2
#define TIMESTAMP_H
3
#include <NTPClient.h>
4
#include <WiFiUdp.h>
5
#include <string>
6
#include <ctime>
7
8
using namespace
std;
9
14
class
TimeStamp
{
15
16
17
private
:
18
int
day;
19
int
month;
20
int
year;
21
22
int
hour;
23
int
minutes;
24
int
seconds;
25
26
int
offset;
27
28
time_t
epoch_time;
29
struct
tm
ptm;
30
31
32
public
:
33
// epoch time(seconds since 1970) to timestamp
34
TimeStamp
(
time_t
epoch_time);
35
// convert mm/dd/yyThh:mm:ss+offset to timestamp
36
TimeStamp
(
string
ts
);
37
// convert ints to date
38
TimeStamp
(
int
day,
39
int
month,
40
int
year,
41
int
hour,
42
int
minutes,
43
int
seconds,
44
int
offset);
45
46
// get "mm/dd/yyThh:mm:ss+offset"
47
string
to_string();
48
// return "mm-dd-yy"
49
string
get_mdy();
50
long
int
get_epoch(){
return
this->epoch_time;}
51
52
friend
bool
operator< (
const
TimeStamp
&
l
,
const
TimeStamp
&
r
) {
53
if
(
l
.epoch_time <
r
.epoch_time){
54
return
true
;
55
}
else
{
56
return
false
;
57
}
58
}
59
60
friend
bool
operator> (
const
TimeStamp
&
l
,
const
TimeStamp
&
r
){
61
return
r
<
l
;
62
}
63
64
friend
bool
operator<= (
const
TimeStamp
&
l
,
const
TimeStamp
&
r
){
65
return
!(
r
<
l
);
66
}
67
68
friend
bool
operator>= (
const
TimeStamp
&
l
,
const
TimeStamp
&
r
){
69
return
!(
l
<
r
);
70
}
71
72
friend
bool
operator== (
const
TimeStamp
&
l
,
const
TimeStamp
&
r
){
73
return
l
.epoch_time ==
r
.epoch_time;
74
}
75
76
friend
bool
operator!= (
const
TimeStamp
&
l
,
const
TimeStamp
&
r
){
77
return
l
.epoch_time !=
r
.epoch_time;
78
}
79
80
};
81
82
91
class
TimeStampBuilder
{
92
93
private
:
94
95
NTPClient
* ntp_client;
96
97
public
:
98
99
TimeStampBuilder
(
NTPClient
*);
100
101
std::string get_date_time();
// use NTPClient
102
std::string get_date_time(std::string
date
,
103
std::string
time
,
104
std::string offset);
// build from strings
105
106
std::string format_time(
int
hours
,
int
minutes,
int
seconds);
107
std::string format_date(
unsigned
long
epoch_time);
108
};
109
110
117
class
TimeStampParser
{
118
119
private
:
120
121
std::string timestamp;
122
123
public
:
124
125
TimeStampParser
(std::string timestamp);
126
127
std::string get_timestamp(
void
){
return
this->timestamp;}
128
129
int
get_day();
130
int
get_month();
131
int
get_year();
132
133
int
get_hours();
134
int
get_minutes();
135
int
get_seconds();
136
137
int
get_offset();
138
};
139
140
#endif
TimeStampBuilder
Definition
TimeStamp.hpp:91
TimeStampParser
Definition
TimeStamp.hpp:117
TimeStamp
Definition
TimeStamp.hpp:14
reset_count
int reset_count
number of resets retrieved for NVS
Definition
scheduler.hpp:31
lib
TimeStamp
TimeStamp.hpp
Generated by
1.10.0