-
Notifications
You must be signed in to change notification settings - Fork 0
/
Time.h
46 lines (39 loc) · 847 Bytes
/
Time.h
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
#ifndef TIME_H
#define TIME_H
#include "Result.h"
class Time {
public:
static Result<Time> parseFromString(std::string const &string);
public:
int const year;
uint8_t const month;
uint8_t const day;
uint8_t const weekday;
uint8_t const hour;
uint8_t const minute;
uint8_t const second;
Time(
int year,
uint8_t month,
uint8_t day,
uint8_t weekday,
uint8_t hour,
uint8_t minute,
uint8_t second) :
year(year),
month(month),
day(day),
weekday(weekday),
hour(hour),
minute(minute),
second(second) {}
int secondsInDay() const {
auto minutesInDay = hour * MINUTES_PER_HOUR + minute;
return minutesInDay * SECONDS_PER_MINUTE + second;
}
std::string toString() const {
return formatString("%04d%02d%02d-%1d-%02d%02d%02d",
year, month, day, weekday, hour, minute, second);
}
};
#endif