line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#pragma once |
2
|
|
|
|
|
|
|
#include "basic.h" |
3
|
|
|
|
|
|
|
#include |
4
|
|
|
|
|
|
|
#include |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
namespace panda { namespace time { |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
static const char GMT_FALLBACK[] = "GMT0"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
const size_t TZNAME_MAX = 255; // max length of timezone name or POSIX rule (Europe/Moscow, ...) |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
const ptime_t EPOCH_NEGINF = std::numeric_limits::min(); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
const int DAYS_PER_YEAR = 365; // non-leap year only |
15
|
|
|
|
|
|
|
const int DAYS_PER_QYEAR = DAYS_PER_YEAR*4 + 1; |
16
|
|
|
|
|
|
|
const int DAYS_PER_CENT = DAYS_PER_QYEAR*25 - 1; |
17
|
|
|
|
|
|
|
const int DAYS_PER_QCENT = DAYS_PER_CENT*4 + 1; |
18
|
|
|
|
|
|
|
const int EPOCH_CHRIST_DAYS = 719162; // christ_days(1970); |
19
|
|
|
|
|
|
|
const int EPOCH_WDAY = 4; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
const ptime_t MAX_YEARS = (ptime_t) 1 << 32; |
22
|
|
|
|
|
|
|
const ptime_t MAX_MONTHS = MAX_YEARS*12; |
23
|
|
|
|
|
|
|
const ptime_t MAX_DAYS = MAX_MONTHS*31; |
24
|
|
|
|
|
|
|
const ptime_t MAX_HOURS = MAX_DAYS*24; |
25
|
|
|
|
|
|
|
const ptime_t MAX_MINUTES = MAX_HOURS*60; |
26
|
|
|
|
|
|
|
const ptime_t MAX_EPOCH = MAX_MINUTES*60; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
const ptime_t OUTLIM_MONTH_BY_12 = ((MAX_MONTHS / 12) + 1)*12; |
29
|
|
|
|
|
|
|
const ptime_t OUTLIM_EPOCH_BY_86400 = ((MAX_EPOCH / 86400) + 1)*86400; |
30
|
|
|
|
|
|
|
const ptime_t OUTLIM_DAY_BY_7 = ((MAX_DAYS / 7) + 1)*7; |
31
|
|
|
|
|
|
|
const ptime_t OUTLIM_DAY_BY_QCENT = ((MAX_DAYS / DAYS_PER_QCENT) + 1)*DAYS_PER_QCENT; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
const int YDAY2MON[][366] = { |
34
|
|
|
|
|
|
|
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,-1}, |
35
|
|
|
|
|
|
|
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11} |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
const int YDAY2MDAY[][366] = { |
39
|
|
|
|
|
|
|
{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,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,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,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,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,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,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,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,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,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,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,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,-1}, |
40
|
|
|
|
|
|
|
{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,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,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,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,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,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,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,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,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,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,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,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} |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
const int MON2YDAY[][12] = { |
44
|
|
|
|
|
|
|
{0,31,59,90,120,151,181,212,243,273,304,334}, |
45
|
|
|
|
|
|
|
{0,31,60,91,121,152,182,213,244,274,305,335} |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
panda::string readfile (const string_view& path); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
inline int64_t char8_to_int64 (const char* source) { |
51
|
|
|
|
|
|
|
return *((int64_t*) source); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
// GIVEN DAYS PASSED SINCE 1 Jan 0001 00:00:00 CALCULATES REAL YEAR AND DAYS REMAINDER - YDAY [0-365] |
55
|
26899
|
|
|
|
|
|
inline void christ_year (ptime_t days, int32_t &year, int32_t &remainder) { |
56
|
|
|
|
|
|
|
// 1-st step: separate FULL QUAD CENTURIES |
57
|
26899
|
|
|
|
|
|
ptime_t tmp = (days + OUTLIM_DAY_BY_QCENT) % DAYS_PER_QCENT; |
58
|
26899
|
|
|
|
|
|
year = (days - tmp)/DAYS_PER_QCENT * 400; |
59
|
26899
|
|
|
|
|
|
days = tmp; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
// 2-nd step: separate FULL CENTURIES, condition fixes QCENT -> CENT border |
62
|
26899
|
100
|
|
|
|
|
if (days == DAYS_PER_CENT*4) { |
63
|
7
|
|
|
|
|
|
year += 300; |
64
|
7
|
|
|
|
|
|
days = DAYS_PER_CENT; |
65
|
|
|
|
|
|
|
} else { |
66
|
26892
|
|
|
|
|
|
year += days/DAYS_PER_CENT * 100; |
67
|
26892
|
|
|
|
|
|
days %= DAYS_PER_CENT; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
// 3-rd step: separate FULL QUAD YEARS, no border fix needed |
71
|
26899
|
|
|
|
|
|
year += days/DAYS_PER_QYEAR * 4; |
72
|
26899
|
|
|
|
|
|
days %= DAYS_PER_QYEAR; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
// 4-th step: separate FULL YEARS, condition fixes QYEAR -> YEAR border |
75
|
26899
|
100
|
|
|
|
|
if (days == DAYS_PER_YEAR*4) { |
76
|
42
|
|
|
|
|
|
year += 4; // actually 3, but we must add 1 to result year, as the start is 1-st year, not 0-th |
77
|
42
|
|
|
|
|
|
remainder = 365; |
78
|
|
|
|
|
|
|
} else { |
79
|
26857
|
|
|
|
|
|
year += days/DAYS_PER_YEAR + 1; // we must add 1 to result year, as the start is 1-st year, not 0-th |
80
|
26857
|
|
|
|
|
|
remainder = days % DAYS_PER_YEAR; |
81
|
|
|
|
|
|
|
} |
82
|
26899
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
}} |