| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#ifndef TSTR_TIME_H |
|
2
|
|
|
|
|
|
|
#define TSTR_TIME_H |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#include |
|
5
|
|
|
|
|
|
|
#include |
|
6
|
|
|
|
|
|
|
#include "tstr_calendar.h" |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#define TSTR_TIME_EPOCH_MIN INT64_C(-62135596800) |
|
9
|
|
|
|
|
|
|
#define TSTR_TIME_EPOCH_MAX INT64_C(253402300799) |
|
10
|
|
|
|
|
|
|
|
|
11
|
11
|
|
|
|
|
|
static inline bool tstr_time_valid_hms(int h, int m, int s) { |
|
12
|
10
|
100
|
|
|
|
|
return (h >= 0 && h <= 23) |
|
13
|
9
|
100
|
|
|
|
|
&& (m >= 0 && m <= 59) |
|
|
|
100
|
|
|
|
|
|
|
14
|
21
|
100
|
|
|
|
|
&& (s >= 0 && s <= 59); |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
} |
|
16
|
|
|
|
|
|
|
|
|
17
|
9
|
|
|
|
|
|
static inline bool tstr_time_valid_hms60(int h, int m, int s) { |
|
18
|
8
|
100
|
|
|
|
|
return (h >= 0 && h <= 23) |
|
19
|
7
|
100
|
|
|
|
|
&& (m >= 0 && m <= 59) |
|
|
|
100
|
|
|
|
|
|
|
20
|
17
|
100
|
|
|
|
|
&& (s >= 0 && s <= 60); |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
388
|
|
|
|
|
|
static inline int64_t tstr_time_timegm(int y, |
|
24
|
|
|
|
|
|
|
int m, |
|
25
|
|
|
|
|
|
|
int d, |
|
26
|
|
|
|
|
|
|
int H, |
|
27
|
|
|
|
|
|
|
int M, |
|
28
|
|
|
|
|
|
|
int S) { |
|
29
|
388
|
|
|
|
|
|
uint32_t rdn = tstr_calendar_ymd_to_rdn(y, m, d); |
|
30
|
388
|
|
|
|
|
|
int64_t sod = (int64_t)H * 3600 + (int64_t)M * 60 + S; |
|
31
|
388
|
|
|
|
|
|
return ((int64_t)rdn - TSTR_CALENDAR_RDN_UNIX_EPOCH) * 86400 + sod; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
103
|
|
|
|
|
|
static inline void tstr_time_gmtime(int64_t epoch, |
|
35
|
|
|
|
|
|
|
int* yp, |
|
36
|
|
|
|
|
|
|
int* mp, |
|
37
|
|
|
|
|
|
|
int* dp, |
|
38
|
|
|
|
|
|
|
int* Hp, |
|
39
|
|
|
|
|
|
|
int* Mp, |
|
40
|
|
|
|
|
|
|
int* Sp, |
|
41
|
|
|
|
|
|
|
int* wdayp, |
|
42
|
|
|
|
|
|
|
int* ydayp) { |
|
43
|
|
|
|
|
|
|
int y, m, d; |
|
44
|
103
|
|
|
|
|
|
int64_t days = epoch / 86400; |
|
45
|
103
|
|
|
|
|
|
int sod = (int)(epoch - days * 86400); |
|
46
|
103
|
100
|
|
|
|
|
if (sod < 0) { |
|
47
|
2
|
|
|
|
|
|
sod += 86400; |
|
48
|
2
|
|
|
|
|
|
days--; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
103
|
|
|
|
|
|
uint32_t rdn = (uint32_t)(days + TSTR_CALENDAR_RDN_UNIX_EPOCH); |
|
51
|
103
|
|
|
|
|
|
tstr_calendar_rdn_to_ymd(rdn, &y, &m, &d); |
|
52
|
103
|
50
|
|
|
|
|
if (yp) |
|
53
|
103
|
|
|
|
|
|
*yp = y; |
|
54
|
103
|
100
|
|
|
|
|
if (mp) |
|
55
|
19
|
|
|
|
|
|
*mp = m; |
|
56
|
103
|
100
|
|
|
|
|
if (dp) |
|
57
|
19
|
|
|
|
|
|
*dp = d; |
|
58
|
103
|
100
|
|
|
|
|
if (Hp) |
|
59
|
19
|
|
|
|
|
|
*Hp = sod / 3600; |
|
60
|
103
|
100
|
|
|
|
|
if (Mp) |
|
61
|
19
|
|
|
|
|
|
*Mp = (sod % 3600) / 60; |
|
62
|
103
|
100
|
|
|
|
|
if (Sp) |
|
63
|
19
|
|
|
|
|
|
*Sp = sod % 60; |
|
64
|
103
|
100
|
|
|
|
|
if (wdayp) |
|
65
|
19
|
|
|
|
|
|
*wdayp = tstr_calendar_rdn_to_dow(rdn) % 7; |
|
66
|
103
|
100
|
|
|
|
|
if (ydayp) |
|
67
|
19
|
|
|
|
|
|
*ydayp = tstr_calendar_ymd_to_doy(y, m, d) - 1; |
|
68
|
103
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#endif /* TSTR_TIME_H */ |