File Coverage

src/panda/time/timezone.h
Criterion Covered Total %
statement 0 4 0.0
branch 0 6 0.0
condition n/a
subroutine n/a
pod n/a
total 0 10 0.0


line stmt bran cond sub pod time code
1             #pragma once
2             #include
3             #include
4             #include
5              
6             namespace panda { namespace time {
7              
8             using std::string_view;
9              
10             struct Timezone {
11             private:
12             mutable size_t refcnt;
13              
14             public:
15             struct Transition {
16             ptime_t start; // time of transition
17             ptime_t local_start; // local time of transition (epoch+offset).
18             ptime_t local_end; // local time of transition's end (next transition epoch + MY offset).
19             ptime_t local_lower; // local_start or prev transition's local_end
20             ptime_t local_upper; // local_start or prev transition's local_end
21             int32_t offset; // offset from non-leap GMT
22             int32_t gmt_offset; // offset from leap GMT
23             int32_t delta; // offset minus previous transition's offset
24             int32_t isdst; // is DST in effect after this transition
25             int32_t leap_corr; // summary leap seconds correction at the moment
26             int32_t leap_delta; // delta leap seconds correction (0 if it's just a transition, != 0 if it's a leap correction)
27             ptime_t leap_end; // end of leap period (not including last second) = start + leap_delta
28             ptime_t leap_lend; // local_start + 2*leap_delta
29             union {
30             char abbrev[ZONE_ABBR_MAX+1]; // transition (zone) abbreviation
31             int64_t n_abbrev; // abbrev as int64_t
32             };
33             };
34              
35             struct Rule {
36             // rule for future (beyond transition list) dates and for abstract timezones
37             // http://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
38             // --------------------------------------------------------------------------------------------
39             // 1 Jan OUTER ZONE OUTER END INNER ZONE INNER END OUTER ZONE 31 Dec
40             // --------------------------------------------------------------------------------------------
41             struct Zone {
42             enum class Switch { DATE, JDAY, DAY };
43             union {
44             char abbrev[ZONE_ABBR_MAX+1]; // zone abbreviation
45             int64_t n_abbrev; // abbrev as int64_t
46             };
47             int32_t offset; // offset from non-leap GMT
48             int32_t gmt_offset; // offset from leap GMT
49             int32_t isdst; // true if zone represents DST time
50             Switch type; // type of 'end' field
51             datetime end; // dynamic date when this zone ends (only if hasdst=1)
52             };
53              
54             uint32_t hasdst; // does this rule have DST switching
55             Zone outer; // always present
56             Zone inner; // only present if hasdst=1
57             int32_t max_offset; // max(outer.offset, inner.offset)
58             int32_t delta; // inner.offset - outer.offset
59             };
60              
61             struct Leap {
62             ptime_t time;
63             uint32_t correction;
64             };
65              
66             string name;
67             Transition* trans;
68             uint32_t trans_cnt;
69             Transition ltrans; // trans[trans_cnt-1]
70             Leap* leaps;
71             uint32_t leaps_cnt;
72             Rule future;
73             mutable bool is_local; // if timezone is set as local at the moment
74              
75             Timezone () : refcnt(1) {}
76              
77             void retain () const { refcnt++; }
78             void release () const { if (--refcnt <= 0) delete this; }
79              
80 0           void clear () {
81 0 0         delete[] this->trans;
82 0 0         if (this->leaps_cnt > 0) delete[] this->leaps;
    0          
83 0           }
84              
85             ~Timezone () { clear(); }
86             };
87              
88             void tzset (const string_view& zonename);
89             void tzset (const Timezone* tz = NULL);
90             const Timezone* tzget (const string_view& zonename);
91             const Timezone* tzlocal ();
92              
93             const string& tzdir ();
94             bool tzdir (const string&);
95             const string& tzsysdir ();
96              
97             }}