xs/zone.xs

filter: Statementstmt 97.4% 114 / 117 Branchbran 81.1% 73 / 90 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 90.3% 187 / 207 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/tkz/tkz_dump.h ↑ Summary include/tkz/tkz_engine.h »
1 # The public surface: class methods, since a zone is a name and not an
2 # object. Each takes the class as its first argument and ignores it.
3  
4 MODULE = Time::Keeper::Zone PACKAGE = Time::Keeper::Zone
5  
6 SV *
7 tzdata_version(...)
8 CODE:
9 1 RETVAL = newSVpvs(TKZ_TZDATA_VERSION);
10 OUTPUT:
11 RETVAL
12  
13 void
14 names(...)
15 PREINIT:
16 int i;
17 PPCODE:
18 3 ▶ EXTEND(SP, TKZ_ZONE_COUNT);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, TKZ_ZONE_COUNT); 0 3 3
19 1035 ▶ for (i = 0; i < TKZ_ZONE_COUNT; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < TKZ_ZONE_COUNT; i++) 1032 3 1035
20 1032 mPUSHp(tkz_names + tkz_zones[i].name, strlen(tkz_names + tkz_zones[i].name));
21  
22 void
23 links(...)
24 PREINIT:
25 int i;
26 PPCODE:
27 1 ▶ EXTEND(SP, TKZ_LINK_COUNT * 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, TKZ_LINK_COUNT * 2); 0 1 1
28 598 ▶ for (i = 0; i < TKZ_LOOKUP_COUNT; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < TKZ_LOOKUP_COUNT; i++) { 597 1 598
29 const char *n, *c;
30 597 ▶ if (!tkz_lookup[i].is_link)
Branch: 1 branch
BranchTrueFalseTotal
if (!tkz_lookup[i].is_link) 344 253 597
31 344 continue;
32 253 n = tkz_id_name(i);
33 253 c = tkz_id_canonical(i);
34 253 mPUSHp(n, strlen(n));
35 253 mPUSHp(c, strlen(c));
36 }
37  
38 bool
39 is_valid(class, name)
40 SV *class
41 SV *name
42 PREINIT:
43 STRLEN len;
44 const char *p;
45 CODE:
46 PERL_UNUSED_VAR(class);
47 1800 ▶ if (!SvOK(name))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(name)) 1 1799 1800
48 1 XSRETURN_NO;
49 1799 p = SvPV(name, len);
50 1799 ▶ RETVAL = tkz_lookup_name(p, len) >= 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = tkz_lookup_name(p, len) >= 0; 1794 5 1799
51 OUTPUT:
52 RETVAL
53  
54 SV *
55 name(class, name)
56 SV *class
57 SV *name
58 ALIAS:
59 canonical_name = 1
60 PREINIT:
61 STRLEN len;
62 const char *p;
63 int id;
64 CODE:
65 PERL_UNUSED_VAR(class);
66 5 ▶ if (!SvOK(name))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(name)) 0 5 5
67 1 XSRETURN_UNDEF;
68 5 p = SvPV(name, len);
69 5 id = tkz_lookup_name(p, len);
70 5 ▶ if (id < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (id < 0) 1 4 5
71 1 XSRETURN_UNDEF;
72 4 ▶ p = ix ? tkz_id_canonical(id) : tkz_id_name(id);
Branch: 1 branch
BranchTrueFalseTotal
p = ix ? tkz_id_canonical(id) : tkz_id_name(id); 2 2 4
73 4 RETVAL = newSVpv(p, 0);
74 OUTPUT:
75 RETVAL
76  
77 SV *
78 local_name(...)
79 PREINIT:
80 SV **tz;
81 2 STRLEN len = 0;
82 2 const char *p = NULL;
83 CODE:
84 2 ▶ tz = hv_fetchs(GvHVn(PL_envgv), "TZ", 0);
Branch: 1 branch
BranchTrueFalseTotal
tz = hv_fetchs(GvHVn(PL_envgv), "TZ", 0); 2 0 2
85 2 ▶ if (tz && SvOK(*tz))
Branch: 2 branches
BranchTrueFalseTotal
if (tz && SvOK(*tz)) 2 0 2
if (tz && SvOK(*tz)) 2 0 2
86 4 p = SvPV(*tz, len);
87 2 RETVAL = newSVpv(tkz_id_name(tkz_local_zone(p, len)), 0);
88 OUTPUT:
89 RETVAL
90  
91 void
92 countries(...)
93 PREINIT:
94 int i;
95 PPCODE:
96 1 ▶ EXTEND(SP, TKZ_COUNTRY_COUNT * 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, TKZ_COUNTRY_COUNT * 2); 0 1 1
97 248 ▶ for (i = 0; i < TKZ_COUNTRY_COUNT; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < TKZ_COUNTRY_COUNT; i++) { 247 1 248
98 247 mPUSHp(tkz_countries[i].code, 2);
99 247 mPUSHp(tkz_country_names + tkz_countries[i].name,
100 strlen(tkz_country_names + tkz_countries[i].name));
101 }
102  
103 void
104 zones_for_country(class, code)
105 SV *class
106 SV *code
107 PREINIT:
108 STRLEN len;
109 const char *p;
110 char cc[3];
111 5 int lo = 0, hi = TKZ_COUNTRY_COUNT - 1, i;
112 PPCODE:
113 PERL_UNUSED_VAR(class);
114 5 ▶ if (!SvOK(code))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(code)) 0 5 5
115 0 XSRETURN_EMPTY;
116 5 p = SvPV(code, len);
117 5 ▶ if (len != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (len != 2) 1 4 5
118 1 XSRETURN_EMPTY;
119 4 ▶ cc[0] = toUPPER(p[0]);
Branch: 1 branch
BranchTrueFalseTotal
cc[0] = toUPPER(p[0]); 1 3 4
120 4 ▶ cc[1] = toUPPER(p[1]);
Branch: 1 branch
BranchTrueFalseTotal
cc[1] = toUPPER(p[1]); 1 3 4
121 4 cc[2] = '\0';
122 33 ▶ while (lo <= hi) {
Branch: 1 branch
BranchTrueFalseTotal
while (lo <= hi) { 32 1 33
123 32 int mid = lo + (hi - lo) / 2;
124 32 int c = strcmp(tkz_countries[mid].code, cc);
125 32 ▶ if (c == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (c == 0) { 3 29 32
126 3 const tkz_country *k = &tkz_countries[mid];
127 3 ▶ EXTEND(SP, k->n);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, k->n); 0 3 3
128 34 ▶ for (i = 0; i < k->n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < k->n; i++) { 31 3 34
129 31 const char *n = tkz_id_name(tkz_country_zones[k->first + i]);
130 31 mPUSHp(n, strlen(n));
131 }
132 3 break;
133 }
134 29 ▶ if (c < 0) lo = mid + 1; else hi = mid - 1;
Branch: 1 branch
BranchTrueFalseTotal
if (c < 0) lo = mid + 1; else hi = mid - 1; 20 9 29
135 }
136  
137 SV *
138 windows_zone(class, name)
139 SV *class
140 SV *name
141 PREINIT:
142 int id;
143 CODE:
144 PERL_UNUSED_VAR(class);
145 4 ▶ if (!SvOK(name))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(name)) 0 4 4
146 0 XSRETURN_UNDEF;
147 4 id = tkz_windows_lookup(SvPV_nolen(name));
148 4 ▶ if (id < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (id < 0) 1 3 4
149 1 XSRETURN_UNDEF;
150 3 RETVAL = newSVpv(tkz_id_name(id), 0);
151 OUTPUT:
152 RETVAL
153  
154 # Each change from `from` to `to`, both included, as
155 # [epoch, offset before, offset after, abbreviation after, is DST after].
156 void
157 transitions(class, name, from, to)
158 SV *class
159 SV *name
160 SV *from
161 SV *to
162 PREINIT:
163 int id;
164 int64_t t, t0, t1;
165 PPCODE:
166 PERL_UNUSED_VAR(class);
167 10 id = tkz_sv_zone(aTHX_ name);
168 9 t0 = tkz_sv_epoch(aTHX_ from);
169 9 t1 = tkz_sv_epoch(aTHX_ to);
170 9 ▶ if (t1 < t0)
Branch: 1 branch
BranchTrueFalseTotal
if (t1 < t0) 1 8 9
171 1 croak("Time::Keeper::Zone: transitions: the end is before the start");
172 8 ▶ if (t1 - t0 > INT64_C(31557600000))
Branch: 1 branch
BranchTrueFalseTotal
if (t1 - t0 > INT64_C(31557600000)) 1 7 8
173 1 croak("Time::Keeper::Zone: transitions: the span is over 1,000 years");
174 7 t = t0 - 1;
175 246 ▶ while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t <= t1) {
Branch: 2 branches
BranchTrueFalseTotal
while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t <= t1) { 244 2 246
while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t <= t1) { 239 5 244
176 int32_t before, after;
177 int isdst;
178 const char *abbr;
179 239 AV *row = newAV();
180 239 tkz_offset_at(id, t - 1, &before, NULL, NULL);
181 239 tkz_offset_at(id, t, &after, &isdst, &abbr);
182 239 av_extend(row, 4);
183 239 av_push(row, tkz_newSVi64(aTHX_ t));
184 239 av_push(row, newSViv(before));
185 239 av_push(row, newSViv(after));
186 239 av_push(row, newSVpv(abbr, 0));
187 239 av_push(row, newSViv(isdst));
188 239 ▶ XPUSHs(sv_2mortal(newRV_noinc((SV *)row)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newRV_noinc((SV *)row))); 0 239 239
189 }
190  
191 SV *
192 next_transition(class, name, epoch)
193 SV *class
194 SV *name
195 SV *epoch
196 ALIAS:
197 previous_transition = 1
198 PREINIT:
199 int id;
200 int64_t t;
201 CODE:
202 PERL_UNUSED_VAR(class);
203 11 id = tkz_sv_zone(aTHX_ name);
204 9 t = tkz_sv_epoch(aTHX_ epoch);
205 9 ▶ t = ix ? tkz_prev_change(id, t) : tkz_next_change(id, t);
Branch: 1 branch
BranchTrueFalseTotal
t = ix ? tkz_prev_change(id, t) : tkz_next_change(id, t); 5 4 9
206 9 ▶ if (t == TKZ_NO_CHANGE)
Branch: 1 branch
BranchTrueFalseTotal
if (t == TKZ_NO_CHANGE) 3 6 9
207 3 XSRETURN_UNDEF;
208 6 RETVAL = tkz_newSVi64(aTHX_ t);
209 OUTPUT:
210 RETVAL
211  
212 void
213 offset_at(class, name, epoch)
214 SV *class
215 SV *name
216 SV *epoch
217 PREINIT:
218 int id, isdst;
219 int32_t utoff;
220 const char *abbr;
221 PPCODE:
222 PERL_UNUSED_VAR(class);
223 8 id = tkz_sv_zone(aTHX_ name);
224 7 tkz_offset_at(id, tkz_sv_epoch(aTHX_ epoch), &utoff, &isdst, &abbr);
225 6 ▶ if (GIMME_V != G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_LIST) { 3 3 6
226 3 ▶ mXPUSHi(utoff);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHi(utoff); 0 3 3
227 3 XSRETURN(1);
228 }
229 3 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 3 3
230 3 mPUSHi(utoff);
231 3 mPUSHi(isdst);
232 3 mPUSHp(abbr, strlen(abbr));
233  
234 IV
235 standard_offset_at(class, name, epoch)
236 SV *class
237 SV *name
238 SV *epoch
239 PREINIT:
240 int32_t utoff;
241 CODE:
242 PERL_UNUSED_VAR(class);
243 8 tkz_standard_offset_at(tkz_sv_zone(aTHX_ name), tkz_sv_epoch(aTHX_ epoch), &utoff);
244 7 ▶ RETVAL = utoff;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = utoff; 0 7 7
245 OUTPUT:
246 RETVAL
247  
248 # Whether the DST flag changes in the year, the year as the zone's own
249 # wall clock counts it.
250 bool
251 has_dst(class, name, year)
252 SV *class
253 SV *name
254 IV year
255 PREINIT:
256 int id, was;
257 int64_t u[2], t, end;
258 int32_t o[2];
259 CODE:
260 PERL_UNUSED_VAR(class);
261 7 id = tkz_sv_zone(aTHX_ name);
262 6 ▶ if (year < -999999999 || year > 999999999)
Branch: 2 branches
BranchTrueFalseTotal
if (year < -999999999 || year > 999999999) 6 0 6
if (year < -999999999 || year > 999999999) 0 6 6
263 0 croak("Time::Keeper::Zone: has_dst: year %" IVdf " is out of range", year);
264 6 tkz_resolve_local_all(id, tkz_days_from_civil(year, 1, 1) * 86400, u, o);
265 6 t = u[0];
266 6 tkz_resolve_local_all(id, tkz_days_from_civil(year + 1, 1, 1) * 86400, u, o);
267 6 end = u[0];
268 6 tkz_offset_at(id, t, NULL, &was, NULL);
269 6 RETVAL = 0;
270 6 ▶ while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t < end) {
Branch: 2 branches
BranchTrueFalseTotal
while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t < end) { 3 3 6
while ((t = tkz_next_change(id, t)) != TKZ_NO_CHANGE && t < end) { 2 1 3
271 int isdst;
272 2 tkz_offset_at(id, t, NULL, &isdst, NULL);
273 2 ▶ if (isdst != was) {
Branch: 1 branch
BranchTrueFalseTotal
if (isdst != was) { 2 0 2
274 2 RETVAL = 1;
275 2 break;
276 }
277 }
278 OUTPUT:
279 RETVAL
280  
281 SV *
282 country_of(class, name)
283 SV *class
284 SV *name
285 ALIAS:
286 windows_name = 1
287 PREINIT:
288 STRLEN len;
289 const char *p;
290 CODE:
291 PERL_UNUSED_VAR(class);
292 13 ▶ if (!SvOK(name))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(name)) 1 12 13
293 5 XSRETURN_UNDEF;
294 12 p = SvPV(name, len);
295 12 ▶ p = ix ? tkz_windows_name(tkz_lookup_name(p, len)) : tkz_country_of(tkz_lookup_name(p, len));
Branch: 1 branch
BranchTrueFalseTotal
p = ix ? tkz_windows_name(tkz_lookup_name(p, len)) : tkz_country_of(tkz_lookup_name(p, len)); 6 6 12
296 12 ▶ if (!p)
Branch: 1 branch
BranchTrueFalseTotal
if (!p) 4 8 12
297 4 XSRETURN_UNDEF;
298 8 RETVAL = newSVpv(p, 0);
299 OUTPUT:
300 RETVAL
« include/tkz/tkz_dump.h ↑ Summary include/tkz/tkz_engine.h »