include/tkr/tkr_zone.h

filter: Statementstmt 95.1% 39 / 41 Branchbran 87.5% 14 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 92.9% 53 / 57 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/tkr/tkr_cron.h ↑ Summary xs/rule.xs »
1 #ifndef TKR_ZONE_H
2 #define TKR_ZONE_H
3  
4 /* A wall time of the rule's zone as instants: one, two when the clocks
5 * went back over it, none when they went forward over it and the rule
6 * skips, by the rule's gap and overlap choices. UTC, a fixed offset and
7 * floating time need no zone data; a named zone asks Time::Keeper::Zone's
8 * resolve_local_all, which gives both readings of a doubled wall time and
9 * the offsets either side of a skipped one. Returns the count, or -1 when
10 * the wall time was skipped and the rule says fail. */
11 static int
12 30223802 tkr_resolve(pTHX_ const tkr_rule *r, int64_t wall, int64_t out[2])
13 {
14 int64_t utc[2];
15 int32_t utoff[2];
16 int rc;
17 30223802 switch (r->zone.kind) {
18 20031845 case TIME_KEEPER_ZONE_UTC:
19 case TIME_KEEPER_ZONE_FLOATING:
20 20031845 out[0] = wall;
21 20031845 return 1;
22 637 case TIME_KEEPER_ZONE_FIXED:
23 637 out[0] = wall - r->zone.value;
24 637 return 1;
25 10191320 default:
26 10191320 break;
27 }
28 10191320 rc = (tkr_tkz(aTHX)->resolve_local_all)(r->zone.value, wall, utc, utoff);
29 10191320 ▶ if (rc == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (rc == 1) { 10188722 2598 10191320
30 10188722 out[0] = utc[0];
31 10188722 return 1;
32 }
33 2598 ▶ if (rc == 2) { /* the clocks went back: two readings, earlier first */
Branch: 1 branch
BranchTrueFalseTotal
if (rc == 2) { /* the clocks went back: two readings, earlier first */ 1290 1308 2598
34 1290 switch (r->overlap) {
35 3 case TKR_OVERLAP_LATER: out[0] = utc[1]; return 1;
36 100 case TKR_OVERLAP_BOTH: out[0] = utc[0]; out[1] = utc[1]; return 2;
37 1187 default: out[0] = utc[0]; return 1;
38 }
39 }
40 1308 ▶ if (rc == 0) { /* the clocks went forward over it */
Branch: 1 branch
BranchTrueFalseTotal
if (rc == 0) { /* the clocks went forward over it */ 1308 0 1308
41 1308 switch (r->gap) {
42 1296 case TKR_GAP_FORWARD: out[0] = wall - utoff[0]; return 1; /* read with the offset before: the moment after the gap */
43 1 case TKR_GAP_BACKWARD: out[0] = wall - utoff[1]; return 1; /* read with the offset after: the moment before it */
44 9 case TKR_GAP_SKIP: return 0;
45 2 default: return -1;
46 }
47 }
48 0 return -1;
49 }
50  
51 /* How far back of a moment's wall time a walk must begin, or on past it
52 * walking back: an occurrence's instant is its wall time less the offset
53 * of its own moment, so a wall time up to a clock change away can fall on
54 * the other side. Three hours covers every change tzdata has; with no
55 * change within three hours, and in UTC, a fixed offset or floating time,
56 * nothing. */
57 static int64_t
58 94840 tkr_lookback(pTHX_ const tkr_rule *r, int64_t from)
59 {
60 int64_t c;
61 94840 ▶ if (r->zone.kind != TIME_KEEPER_ZONE_NAMED)
Branch: 1 branch
BranchTrueFalseTotal
if (r->zone.kind != TIME_KEEPER_ZONE_NAMED) 6810 88030 94840
62 6810 return 0;
63 88030 c = (tkr_tkz(aTHX)->next_change)(r->zone.value, from - 3 * 3600);
64 88030 ▶ return (c != TKZ_NO_CHANGE && c <= from + 3 * 3600) ? 3 * 3600 : 0;
Branch: 2 branches
BranchTrueFalseTotal
return (c != TKZ_NO_CHANGE && c <= from + 3 * 3600) ? 3 * 3600 : 0; 87654 376 88030
return (c != TKZ_NO_CHANGE && c <= from + 3 * 3600) ? 3 * 3600 : 0; 185 87469 87654
65 }
66  
67 /* The wall time of an instant in the rule's zone, as seconds counted as
68 * if UTC, and its fields. */
69 static int64_t
70 5212123 tkr_wall_of(pTHX_ const tkr_rule *r, int64_t inst, time_keeper_civil *c)
71 {
72 5212123 const time_keeper_abi *T = tkr_tk(aTHX);
73 time_keeper_instant t;
74 time_keeper_civil tmp;
75 5212123 t.sec = inst;
76 5212123 t.nsec = 0;
77 5212123 ▶ if (!c)
Branch: 1 branch
BranchTrueFalseTotal
if (!c) 5119447 92676 5212123
78 5119447 c = &tmp;
79 5212123 ▶ if ((T->civil)(aTHX_ &t, &r->zone, c) != TIME_KEEPER_OK)
Branch: 1 branch
BranchTrueFalseTotal
if ((T->civil)(aTHX_ &t, &r->zone, c) != TIME_KEEPER_OK) 0 5212123 5212123
80 0 croak("Time::Keeper::Recurrence: an instant outside the years Time::Keeper holds");
81 5212123 return tkr_days_from_civil(c->year, (unsigned)c->month, (unsigned)c->day) * 86400
82 5212123 + c->hour * 3600 + c->minute * 60 + c->second;
83 }
84  
85 #endif
« include/tkr/tkr_cron.h ↑ Summary xs/rule.xs »