include/tkr/tkr_rrule.h

filter: Statementstmt 98.4% 325 / 330 Branchbran 89.2% 357 / 400 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 93.4% 682 / 730 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/rule.xs ↑ Summary blib/lib/Time/Keeper/Recurrence.pm »
1 #ifndef TKR_RRULE_H
2 #define TKR_RRULE_H
3  
4 /* RFC 5545 section 3.3.10: the RECUR value read into a tkr_rule and written
5 * back in one canonical form. Parts may come in any order and each at most
6 * once; FREQ is required; UNTIL and COUNT exclude each other; every value
7 * is range checked; the RFC's rules about which parts may meet are
8 * enforced; and an unknown part is an error here, not ignored as the RFC
9 * allows, since a scheduler must not fire a rule it half understood. The
10 * error text names the part and the value. */
11  
12 #define TKR_ERR 200
13  
14 static void
15 103 tkr_err(char *err, const char *fmt, ...)
16 {
17 va_list ap;
18 103 va_start(ap, fmt);
19 103 vsnprintf(err, TKR_ERR, fmt, ap);
20 103 va_end(ap);
21 103 }
22  
23 /* Equal ignoring case over len bytes: the dist's own, so the parsers need no interpreter. */
24 static int
25 14024 tkr_ieq(const char *a, const char *b, size_t len)
26 {
27 37063 ▶ while (len--) {
Branch: 1 branch
BranchTrueFalseTotal
while (len--) { 33373 3690 37063
28 33373 unsigned char x = (unsigned char)*a++, y = (unsigned char)*b++; /* the macros read their argument twice */
29 33373 ▶ if (toLOWER(x) != toLOWER(y))
Branch: 3 branches
BranchTrueFalseTotal
if (toLOWER(x) != toLOWER(y)) 32771 602 33373
if (toLOWER(x) != toLOWER(y)) 32826 547 33373
if (toLOWER(x) != toLOWER(y)) 10334 23039 33373
30 10334 return 0;
31 }
32 3690 return 1;
33 }
34  
35 /* A whole non-negative number, or -1. */
36 static long
37 7257 tkr_num(const char *s, size_t len, int allow_sign, int *neg)
38 {
39 7257 long v = 0;
40 7257 size_t i = 0;
41 7257 *neg = 0;
42 7257 ▶ if (len && (s[0] == '+' || s[0] == '-')) {
Branch: 3 branches
BranchTrueFalseTotal
if (len && (s[0] == '+' || s[0] == '-')) { 7257 0 7257
if (len && (s[0] == '+' || s[0] == '-')) { 7257 0 7257
if (len && (s[0] == '+' || s[0] == '-')) { 64 7193 7257
43 64 ▶ if (!allow_sign)
Branch: 1 branch
BranchTrueFalseTotal
if (!allow_sign) 1 63 64
44 1 return -1;
45 63 *neg = s[0] == '-';
46 63 i = 1;
47 }
48 7256 ▶ if (i >= len || len - i > 9)
Branch: 2 branches
BranchTrueFalseTotal
if (i >= len || len - i > 9) 7256 0 7256
if (i >= len || len - i > 9) 0 7256 7256
49 0 return -1;
50 22282 ▶ for (; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (; i < len; i++) { 15026 7256 22282
51 15026 ▶ if (!isDIGIT(s[i]))
Branch: 1 branch
BranchTrueFalseTotal
if (!isDIGIT(s[i])) 0 15026 15026
52 0 return -1;
53 15026 v = v * 10 + (s[i] - '0');
54 }
55 7256 return v;
56 }
57  
58 /* MO .. SU, any case; -1 if not one. */
59 static int
60 2119 tkr_weekday_of(const char *s, size_t len)
61 {
62 int i;
63 2119 ▶ if (len != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (len != 2) 0 2119 2119
64 0 return -1;
65 8471 ▶ for (i = 0; i < 7; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < 7; i++) 8469 2 8471
66 8469 ▶ if (toUPPER(s[0]) == tkr_day_names[i][0] && toUPPER(s[1]) == tkr_day_names[i][1])
Branch: 4 branches
BranchTrueFalseTotal
if (toUPPER(s[0]) == tkr_day_names[i][0] && toUPPER(s[1]) == tkr_day_names[i][1]) 7 8462 8469
if (toUPPER(s[0]) == tkr_day_names[i][0] && toUPPER(s[1]) == tkr_day_names[i][1]) 2780 5689 8469
if (toUPPER(s[0]) == tkr_day_names[i][0] && toUPPER(s[1]) == tkr_day_names[i][1]) 3 2777 2780
if (toUPPER(s[0]) == tkr_day_names[i][0] && toUPPER(s[1]) == tkr_day_names[i][1]) 2117 663 2780
67 2117 return i;
68 2 return -1;
69 }
70  
71 /* YYYYMMDD, YYYYMMDDTHHMMSS or YYYYMMDDTHHMMSSZ. */
72 static int
73 87 tkr_parse_until(const char *v, size_t len, tkr_rule *r, char *err)
74 {
75 87 long y, mo, d, h = 0, mi = 0, s = 0;
76 int neg;
77 int kind;
78 87 ▶ if (len == 8) kind = TKR_UNTIL_DATE;
Branch: 1 branch
BranchTrueFalseTotal
if (len == 8) kind = TKR_UNTIL_DATE; 7 80 87
79 80 ▶ else if (len == 15 && v[8] == 'T') kind = TKR_UNTIL_FLOATING;
Branch: 2 branches
BranchTrueFalseTotal
else if (len == 15 && v[8] == 'T') kind = TKR_UNTIL_FLOATING; 5 75 80
else if (len == 15 && v[8] == 'T') kind = TKR_UNTIL_FLOATING; 5 0 5
80 75 ▶ else if (len == 16 && v[8] == 'T' && v[15] == 'Z') kind = TKR_UNTIL_UTC;
Branch: 3 branches
BranchTrueFalseTotal
else if (len == 16 && v[8] == 'T' && v[15] == 'Z') kind = TKR_UNTIL_UTC; 74 1 75
else if (len == 16 && v[8] == 'T' && v[15] == 'Z') kind = TKR_UNTIL_UTC; 74 0 74
else if (len == 16 && v[8] == 'T' && v[15] == 'Z') kind = TKR_UNTIL_UTC; 74 0 74
81 else {
82 1 tkr_err(err, "UNTIL=%.*s is not a date (YYYYMMDD) or a date and time (YYYYMMDDTHHMMSS, with Z for UTC)", (int)len, v);
83 1 return 0;
84 }
85 86 y = tkr_num(v, 4, 0, &neg); mo = tkr_num(v + 4, 2, 0, &neg); d = tkr_num(v + 6, 2, 0, &neg);
86 86 ▶ if (kind != TKR_UNTIL_DATE) {
Branch: 1 branch
BranchTrueFalseTotal
if (kind != TKR_UNTIL_DATE) { 79 7 86
87 79 h = tkr_num(v + 9, 2, 0, &neg); mi = tkr_num(v + 11, 2, 0, &neg); s = tkr_num(v + 13, 2, 0, &neg);
88 }
89 86 ▶ if (y < 0 || mo < 1 || mo > 12 || d < 1 || (unsigned)d > tkr_days_in_month(y, (unsigned)mo)
Branch: 5 branches
BranchTrueFalseTotal
if (y < 0 || mo < 1 || mo > 12 || d < 1 || (unsigned)d > tkr_days_in_month(y, (unsigned)mo) 86 0 86
if (y < 0 || mo < 1 || mo > 12 || d < 1 || (unsigned)d > tkr_days_in_month(y, (unsigned)mo) 86 0 86
if (y < 0 || mo < 1 || mo > 12 || d < 1 || (unsigned)d > tkr_days_in_month(y, (unsigned)mo) 86 0 86
if (y < 0 || mo < 1 || mo > 12 || d < 1 || (unsigned)d > tkr_days_in_month(y, (unsigned)mo) 86 0 86
if (y < 0 || mo < 1 || mo > 12 || d < 1 || (unsigned)d > tkr_days_in_month(y, (unsigned)mo) 85 1 86
90 85 ▶ || h < 0 || h > 23 || mi < 0 || mi > 59 || s < 0 || s > 60) {
Branch: 6 branches
BranchTrueFalseTotal
|| h < 0 || h > 23 || mi < 0 || mi > 59 || s < 0 || s > 60) { 85 0 85
|| h < 0 || h > 23 || mi < 0 || mi > 59 || s < 0 || s > 60) { 85 0 85
|| h < 0 || h > 23 || mi < 0 || mi > 59 || s < 0 || s > 60) { 85 0 85
|| h < 0 || h > 23 || mi < 0 || mi > 59 || s < 0 || s > 60) { 85 0 85
|| h < 0 || h > 23 || mi < 0 || mi > 59 || s < 0 || s > 60) { 85 0 85
|| h < 0 || h > 23 || mi < 0 || mi > 59 || s < 0 || s > 60) { 0 85 85
91 1 tkr_err(err, "UNTIL=%.*s is not a date that exists", (int)len, v);
92 1 return 0;
93 }
94 85 r->until_kind = (uint8_t)kind;
95 85 r->until_sec = tkr_days_from_civil(y, (unsigned)mo, (unsigned)d) * 86400 + h * 3600 + mi * 60 + s;
96 85 return 1;
97 }
98  
99 /* One part. */
100 static int
101 6768 tkr_rrule_part(const char *name, size_t nlen, const char *val, size_t vlen, tkr_rule *r, uint32_t *seen, const int *rscale, char *err)
102 {
103 char key[16];
104 size_t i;
105 6768 const char *p = val, *end = val + vlen;
106 int bit;
107 6768 ▶ if (nlen == 0 || nlen >= sizeof key) {
Branch: 2 branches
BranchTrueFalseTotal
if (nlen == 0 || nlen >= sizeof key) { 6768 0 6768
if (nlen == 0 || nlen >= sizeof key) { 0 6768 6768
108 0 ▶ tkr_err(err, "'%.*s' is not an RRULE part", (int)(nlen < 40 ? nlen : 40), name);
Branch: 1 branch
BranchTrueFalseTotal
tkr_err(err, "'%.*s' is not an RRULE part", (int)(nlen < 40 ? nlen : 40), name); 0 0 0
109 0 return 0;
110 }
111 43863 ▶ for (i = 0; i < nlen; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < nlen; i++) 37095 6768 43863
112 37095 ▶ key[i] = (char)toUPPER(name[i]);
Branch: 1 branch
BranchTrueFalseTotal
key[i] = (char)toUPPER(name[i]); 49 37046 37095
113 6768 key[nlen] = '\0';
114 {
115 static const char *const parts[] = { "FREQ", "UNTIL", "COUNT", "INTERVAL", "BYSECOND", "BYMINUTE", "BYHOUR",
116 "BYDAY", "BYMONTHDAY", "BYYEARDAY", "BYWEEKNO", "BYMONTH", "BYSETPOS", "WKST",
117 "RSCALE", "SKIP" };
118 36297 ▶ for (bit = 0; bit < 16; bit++)
Branch: 1 branch
BranchTrueFalseTotal
for (bit = 0; bit < 16; bit++) 36296 1 36297
119 36296 ▶ if (strEQ(key, parts[bit]))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, parts[bit])) 6767 29529 36296
120 6767 break;
121 6768 ▶ if (bit == 16) {
Branch: 1 branch
BranchTrueFalseTotal
if (bit == 16) { 1 6767 6768
122 1 tkr_err(err, "'%s' is not an RRULE part", key);
123 1 return 0;
124 }
125 6767 ▶ if (*seen & (1u << bit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (*seen & (1u << bit)) { 1 6766 6767
126 1 tkr_err(err, "%s is given twice", key);
127 1 return 0;
128 }
129 6766 *seen |= 1u << bit;
130 }
131 6766 ▶ if (vlen == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (vlen == 0) { 1 6765 6766
132 1 tkr_err(err, "%s has no value", key);
133 1 return 0;
134 }
135 6765 ▶ if (bit == 0) { /* FREQ */
Branch: 1 branch
BranchTrueFalseTotal
if (bit == 0) { /* FREQ */ 2563 4202 6765
136 int f;
137 12800 ▶ for (f = 0; f < 7; f++)
Branch: 1 branch
BranchTrueFalseTotal
for (f = 0; f < 7; f++) 12797 3 12800
138 12797 ▶ if (vlen == strlen(tkr_freq_names[f]) && tkr_ieq(val, tkr_freq_names[f], vlen))
Branch: 2 branches
BranchTrueFalseTotal
if (vlen == strlen(tkr_freq_names[f]) && tkr_ieq(val, tkr_freq_names[f], vlen)) 4109 8688 12797
if (vlen == strlen(tkr_freq_names[f]) && tkr_ieq(val, tkr_freq_names[f], vlen)) 2560 1549 4109
139 2560 break;
140 2563 ▶ if (f == 7) {
Branch: 1 branch
BranchTrueFalseTotal
if (f == 7) { 3 2560 2563
141 3 tkr_err(err, "FREQ=%.*s is not one of SECONDLY, MINUTELY, HOURLY, DAILY, WEEKLY, MONTHLY, YEARLY", (int)vlen, val);
142 3 return 0;
143 }
144 2560 r->freq = (uint8_t)f;
145 2560 return 1;
146 }
147 4202 ▶ if (bit == 1) /* UNTIL */
Branch: 1 branch
BranchTrueFalseTotal
if (bit == 1) /* UNTIL */ 87 4115 4202
148 87 return tkr_parse_until(val, vlen, r, err);
149 4115 ▶ if (bit == 2 || bit == 3) { /* COUNT, INTERVAL */
Branch: 2 branches
BranchTrueFalseTotal
if (bit == 2 || bit == 3) { /* COUNT, INTERVAL */ 3904 211 4115
if (bit == 2 || bit == 3) { /* COUNT, INTERVAL */ 1026 2878 3904
150 int neg;
151 1237 long v = tkr_num(val, vlen, 0, &neg);
152 1237 ▶ if (v < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (v < 1) { 2 1235 1237
153 2 tkr_err(err, "%s=%.*s is not a whole number above zero", key, (int)vlen, val);
154 2 return 0;
155 }
156 1235 ▶ if (bit == 2) r->count = v; else r->interval = (uint32_t)v;
Branch: 1 branch
BranchTrueFalseTotal
if (bit == 2) r->count = v; else r->interval = (uint32_t)v; 210 1025 1235
157 1235 return 1;
158 }
159 2878 ▶ if (bit == 14) { /* RSCALE: a calendar Time::Keeper knows */
Branch: 1 branch
BranchTrueFalseTotal
if (bit == 14) { /* RSCALE: a calendar Time::Keeper knows */ 443 2435 2878
160 443 ▶ int c = tkr_tk_table ? (tkr_tk_table->calendar_find)(val, vlen) : -1;
Branch: 1 branch
BranchTrueFalseTotal
int c = tkr_tk_table ? (tkr_tk_table->calendar_find)(val, vlen) : -1; 443 0 443
161 443 ▶ if (c < 0 || c > 255) {
Branch: 2 branches
BranchTrueFalseTotal
if (c < 0 || c > 255) { 442 1 443
if (c < 0 || c > 255) { 0 442 442
162 1 ▶ tkr_err(err, "RSCALE=%.*s names no calendar Time::Keeper knows", (int)(vlen < 40 ? vlen : 40), val);
Branch: 1 branch
BranchTrueFalseTotal
tkr_err(err, "RSCALE=%.*s names no calendar Time::Keeper knows", (int)(vlen < 40 ? vlen : 40), val); 1 0 1
163 1 return 0;
164 }
165 442 r->calendar = (uint8_t)c;
166 442 r->flags |= TKR_F_RSCALE;
167 442 return 1;
168 }
169 2435 ▶ if (bit == 15) { /* SKIP */
Branch: 1 branch
BranchTrueFalseTotal
if (bit == 15) { /* SKIP */ 194 2241 2435
170 int s;
171 442 ▶ for (s = 0; s < 3; s++)
Branch: 1 branch
BranchTrueFalseTotal
for (s = 0; s < 3; s++) 441 1 442
172 441 ▶ if (vlen == strlen(tkr_skip_upper[s]) && tkr_ieq(val, tkr_skip_upper[s], vlen))
Branch: 2 branches
BranchTrueFalseTotal
if (vlen == strlen(tkr_skip_upper[s]) && tkr_ieq(val, tkr_skip_upper[s], vlen)) 194 247 441
if (vlen == strlen(tkr_skip_upper[s]) && tkr_ieq(val, tkr_skip_upper[s], vlen)) 193 1 194
173 193 break;
174 194 ▶ if (s == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (s == 3) { 1 193 194
175 1 ▶ tkr_err(err, "SKIP=%.*s is not one of OMIT, BACKWARD, FORWARD", (int)(vlen < 40 ? vlen : 40), val);
Branch: 1 branch
BranchTrueFalseTotal
tkr_err(err, "SKIP=%.*s is not one of OMIT, BACKWARD, FORWARD", (int)(vlen < 40 ? vlen : 40), val); 1 0 1
176 1 return 0;
177 }
178 193 r->skip = (uint8_t)s;
179 193 return 1;
180 }
181 2241 ▶ if (bit == 13) { /* WKST */
Branch: 1 branch
BranchTrueFalseTotal
if (bit == 13) { /* WKST */ 52 2189 2241
182 52 int w = tkr_weekday_of(val, vlen);
183 52 ▶ if (w < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (w < 0) { 1 51 52
184 1 tkr_err(err, "WKST=%.*s is not a weekday MO to SU", (int)vlen, val);
185 1 return 0;
186 }
187 51 r->wkst = (uint8_t)w;
188 51 return 1;
189 }
190 /* the lists */
191 5844 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 3675 2169 5844
192 3675 const char *e = p;
193 size_t len;
194 int neg;
195 long v;
196 10495 ▶ while (e < end && *e != ',')
Branch: 2 branches
BranchTrueFalseTotal
while (e < end && *e != ',') 8308 2187 10495
while (e < end && *e != ',') 6820 1488 8308
197 6820 e++;
198 3675 len = (size_t)(e - p);
199 3675 ▶ if (len == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) { 1 3674 3675
200 1 tkr_err(err, "%s has an empty value", key);
201 20 return 0;
202 }
203 3674 ▶ if (bit == 7) { /* BYDAY: an optional [+-]ordinal, then MO .. SU */
Branch: 1 branch
BranchTrueFalseTotal
if (bit == 7) { /* BYDAY: an optional [+-]ordinal, then MO .. SU */ 2067 1607 3674
204 2067 size_t k = 0;
205 2067 int ord = 0, oneg = 0, ndig = 0, w;
206 2067 ▶ if (p[0] == '+' || p[0] == '-') {
Branch: 2 branches
BranchTrueFalseTotal
if (p[0] == '+' || p[0] == '-') { 2067 0 2067
if (p[0] == '+' || p[0] == '-') { 17 2050 2067
207 17 oneg = p[0] == '-';
208 17 k = 1;
209 }
210 2130 ▶ while (k < len && isDIGIT(p[k]) && ndig < 3) {
Branch: 3 branches
BranchTrueFalseTotal
while (k < len && isDIGIT(p[k]) && ndig < 3) { 2130 0 2130
while (k < len && isDIGIT(p[k]) && ndig < 3) { 63 2067 2130
while (k < len && isDIGIT(p[k]) && ndig < 3) { 63 0 63
211 63 ord = ord * 10 + (p[k] - '0');
212 63 k++;
213 63 ndig++;
214 }
215 2067 w = tkr_weekday_of(p + k, len - k);
216 2067 ▶ if (w < 0 || (k > 0 && (ndig == 0 || ord < 1 || ord > 53))) {
Branch: 5 branches
BranchTrueFalseTotal
if (w < 0 || (k > 0 && (ndig == 0 || ord < 1 || ord > 53))) { 2066 1 2067
if (w < 0 || (k > 0 && (ndig == 0 || ord < 1 || ord > 53))) { 55 2011 2066
if (w < 0 || (k > 0 && (ndig == 0 || ord < 1 || ord > 53))) { 54 1 55
if (w < 0 || (k > 0 && (ndig == 0 || ord < 1 || ord > 53))) { 53 1 54
if (w < 0 || (k > 0 && (ndig == 0 || ord < 1 || ord > 53))) { 1 52 53
217 4 tkr_err(err, "BYDAY=%.*s is not a weekday, with an ordinal 1 to 53 or -1 to -53 before it", (int)len, p);
218 4 return 0;
219 }
220 2063 ▶ if (k == 0) r->by_day_any |= (uint8_t)(1u << w);
Branch: 1 branch
BranchTrueFalseTotal
if (k == 0) r->by_day_any |= (uint8_t)(1u << w); 2011 52 2063
221 52 ▶ else if (oneg) r->by_day_neg[w] |= UINT64_C(1) << ord;
Branch: 1 branch
BranchTrueFalseTotal
else if (oneg) r->by_day_neg[w] |= UINT64_C(1) << ord; 16 36 52
222 36 else r->by_day_pos[w] |= UINT64_C(1) << ord;
223 }
224 else {
225 1607 int lo, hi, signed_ok, leap = 0;
226 1607 ▶ if (bit == 11 && len > 1 && (p[len - 1] == 'L' || p[len - 1] == 'l')) {
Branch: 4 branches
BranchTrueFalseTotal
if (bit == 11 && len > 1 && (p[len - 1] == 'L' || p[len - 1] == 'l')) { 275 1332 1607
if (bit == 11 && len > 1 && (p[len - 1] == 'L' || p[len - 1] == 'l')) { 79 196 275
if (bit == 11 && len > 1 && (p[len - 1] == 'L' || p[len - 1] == 'l')) { 53 26 79
if (bit == 11 && len > 1 && (p[len - 1] == 'L' || p[len - 1] == 'l')) { 0 53 53
227 26 ▶ if (!*rscale) {
Branch: 1 branch
BranchTrueFalseTotal
if (!*rscale) { 1 25 26
228 1 tkr_err(err, "BYMONTH=%.*s: a leap month needs RSCALE", (int)len, p);
229 1 return 0;
230 }
231 25 leap = 1;
232 25 len--;
233 }
234 1606 switch (bit) {
235 13 case 4: lo = 0; hi = 60; signed_ok = 0; break; /* BYSECOND */
236 289 case 5: lo = 0; hi = 59; signed_ok = 0; break; /* BYMINUTE */
237 513 case 6: lo = 0; hi = 23; signed_ok = 0; break; /* BYHOUR */
238 390 case 8: lo = 1; hi = 31; signed_ok = 1; break; /* BYMONTHDAY */
239 93 ▶ case 9: lo = 1; hi = *rscale ? 385 : 366; signed_ok = 1; break; /* BYYEARDAY: a Hebrew leap year has up to 385 days */
Branch: 1 branch
BranchTrueFalseTotal
case 9: lo = 1; hi = *rscale ? 385 : 366; signed_ok = 1; break; /* BYYEARDAY: a Hebrew leap year has up to 385 days */ 1 92 93
240 13 case 10: lo = 1; hi = 53; signed_ok = 1; break; /* BYWEEKNO */
241 274 ▶ case 11: lo = 1; hi = *rscale ? 13 : 12; signed_ok = 0; break; /* BYMONTH: thirteen months in some calendars */
Branch: 1 branch
BranchTrueFalseTotal
case 11: lo = 1; hi = *rscale ? 13 : 12; signed_ok = 0; break; /* BYMONTH: thirteen months in some calendars */ 134 140 274
242 21 default: lo = 1; hi = 366; signed_ok = 1; break; /* BYSETPOS */
243 }
244 1606 v = tkr_num(p, len, signed_ok, &neg);
245 1606 ▶ if (v < lo || v > hi) {
Branch: 2 branches
BranchTrueFalseTotal
if (v < lo || v > hi) { 1604 2 1606
if (v < lo || v > hi) { 10 1594 1604
246 12 ▶ if (signed_ok)
Branch: 1 branch
BranchTrueFalseTotal
if (signed_ok) 5 7 12
247 5 tkr_err(err, "%s=%.*s is out of range %d to %d, or -%d to -%d", key, (int)len, p, lo, hi, lo, hi);
248 else
249 7 tkr_err(err, "%s=%.*s is out of range %d to %d", key, (int)(len + leap), p, lo, hi);
250 12 return 0;
251 }
252 1594 switch (bit) {
253 12 case 4: r->by_second |= UINT64_C(1) << v; break;
254 288 case 5: r->by_minute |= UINT64_C(1) << v; break;
255 512 case 6: r->by_hour |= 1u << v; break;
256 388 ▶ case 8: r->by_monthday |= UINT64_C(1) << (neg ? 32 + v : v); break;
Branch: 1 branch
BranchTrueFalseTotal
case 8: r->by_monthday |= UINT64_C(1) << (neg ? 32 + v : v); break; 51 337 388
257 270 case 11:
258 270 ▶ if (leap) r->by_month_leap |= (uint16_t)(1u << v);
Branch: 1 branch
BranchTrueFalseTotal
if (leap) r->by_month_leap |= (uint16_t)(1u << v); 25 245 270
259 245 else r->by_month |= (uint16_t)(1u << v);
260 270 break;
261 91 case 9:
262 91 ▶ if (!tkr_list_add(r->by_yearday, &r->n_yearday, neg ? -(int)v : (int)v)) { tkr_err(err, "BYYEARDAY has more than %d values", TKR_MAX_LIST); return 0; }
Branch: 2 branches
BranchTrueFalseTotal
if (!tkr_list_add(r->by_yearday, &r->n_yearday, neg ? -(int)v : (int)v)) { tkr_err(err, "BYYEARDAY has more than %d values", TKR_MAX_LIST); return 0; } 1 90 91
if (!tkr_list_add(r->by_yearday, &r->n_yearday, neg ? -(int)v : (int)v)) { tkr_err(err, "BYYEARDAY has more than %d values", TKR_MAX_LIST); return 0; } 1 90 91
263 90 break;
264 12 case 10:
265 12 ▶ if (!tkr_list8_add(r->by_weekno, &r->n_weekno, neg ? -(int)v : (int)v)) { tkr_err(err, "BYWEEKNO has more than %d values", TKR_MAX_LIST); return 0; }
Branch: 2 branches
BranchTrueFalseTotal
if (!tkr_list8_add(r->by_weekno, &r->n_weekno, neg ? -(int)v : (int)v)) { tkr_err(err, "BYWEEKNO has more than %d values", TKR_MAX_LIST); return 0; } 1 11 12
if (!tkr_list8_add(r->by_weekno, &r->n_weekno, neg ? -(int)v : (int)v)) { tkr_err(err, "BYWEEKNO has more than %d values", TKR_MAX_LIST); return 0; } 0 12 12
266 12 break;
267 21 default:
268 21 ▶ if (!tkr_list_add(r->by_setpos, &r->n_setpos, neg ? -(int)v : (int)v)) { tkr_err(err, "BYSETPOS has more than %d values", TKR_MAX_LIST); return 0; }
Branch: 2 branches
BranchTrueFalseTotal
if (!tkr_list_add(r->by_setpos, &r->n_setpos, neg ? -(int)v : (int)v)) { tkr_err(err, "BYSETPOS has more than %d values", TKR_MAX_LIST); return 0; } 10 11 21
if (!tkr_list_add(r->by_setpos, &r->n_setpos, neg ? -(int)v : (int)v)) { tkr_err(err, "BYSETPOS has more than %d values", TKR_MAX_LIST); return 0; } 0 21 21
269 21 break;
270 }
271 }
272 3656 ▶ p = e < end ? e + 1 : e;
Branch: 1 branch
BranchTrueFalseTotal
p = e < end ? e + 1 : e; 1487 2169 3656
273 3656 ▶ if (e < end && e + 1 == end) {
Branch: 2 branches
BranchTrueFalseTotal
if (e < end && e + 1 == end) { 1487 2169 3656
if (e < end && e + 1 == end) { 1 1486 1487
274 1 tkr_err(err, "%s ends with a comma", key);
275 1 return 0;
276 }
277 }
278 2169 return 1;
279 }
280  
281 /* The whole value. 1, or 0 with err filled. The start's form (zoned or
282 * floating) is checked against UNTIL's by the caller, which has the start. */
283 static int
284 2568 tkr_rrule_parse(const char *s, size_t len, tkr_rule *r, char *err)
285 {
286 2568 const char *p = s, *end = s + len;
287 2568 uint32_t seen = 0;
288 2568 int rscale = 0;
289 2568 ▶ while (p < end && isSPACE(*p)) p++;
Branch: 2 branches
BranchTrueFalseTotal
while (p < end && isSPACE(*p)) p++; 2567 1 2568
while (p < end && isSPACE(*p)) p++; 0 2567 2567
290 2568 ▶ while (end > p && isSPACE(end[-1])) end--;
Branch: 2 branches
BranchTrueFalseTotal
while (end > p && isSPACE(end[-1])) end--; 2567 1 2568
while (end > p && isSPACE(end[-1])) end--; 0 2567 2567
291 2568 ▶ if (end - p >= 6 && tkr_ieq(p, "RRULE:", 6))
Branch: 2 branches
BranchTrueFalseTotal
if (end - p >= 6 && tkr_ieq(p, "RRULE:", 6)) 2566 2 2568
if (end - p >= 6 && tkr_ieq(p, "RRULE:", 6)) 1 2565 2566
292 1 p += 6;
293 2568 ▶ if (p >= end) {
Branch: 1 branch
BranchTrueFalseTotal
if (p >= end) { 1 2567 2568
294 1 tkr_err(err, "the rule is empty");
295 1 return 0;
296 }
297 {
298 /* RSCALE widens BYMONTH and BYYEARDAY wherever it stands */
299 2567 const char *q = p;
300 9337 ▶ while (q < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (q < end) { 6770 2567 9337
301 6770 const char *e = q;
302 82256 ▶ while (e < end && *e != ';') e++;
Branch: 2 branches
BranchTrueFalseTotal
while (e < end && *e != ';') e++; 79689 2567 82256
while (e < end && *e != ';') e++; 75486 4203 79689
303 6770 ▶ if (e - q > 7 && tkr_ieq(q, "RSCALE=", 7))
Branch: 2 branches
BranchTrueFalseTotal
if (e - q > 7 && tkr_ieq(q, "RSCALE=", 7)) 6590 180 6770
if (e - q > 7 && tkr_ieq(q, "RSCALE=", 7)) 443 6147 6590
304 443 rscale = 1;
305 6770 ▶ q = e < end ? e + 1 : e;
Branch: 1 branch
BranchTrueFalseTotal
q = e < end ? e + 1 : e; 4203 2567 6770
306 }
307 }
308 9302 ▶ while (p < end) {
Branch: 1 branch
BranchTrueFalseTotal
while (p < end) { 6769 2533 9302
309 6769 const char *e = p, *eq;
310 82244 ▶ while (e < end && *e != ';')
Branch: 2 branches
BranchTrueFalseTotal
while (e < end && *e != ';') 79678 2566 82244
while (e < end && *e != ';') 75475 4203 79678
311 75475 e++;
312 43868 ▶ for (eq = p; eq < e && *eq != '='; eq++) ;
Branch: 2 branches
BranchTrueFalseTotal
for (eq = p; eq < e && *eq != '='; eq++) ; 43867 1 43868
for (eq = p; eq < e && *eq != '='; eq++) ; 37099 6768 43867
313 6769 ▶ if (eq == e) {
Branch: 1 branch
BranchTrueFalseTotal
if (eq == e) { 1 6768 6769
314 1 tkr_err(err, "'%.*s' is not NAME=VALUE", (int)(e - p), p);
315 1 return 0;
316 }
317 6768 ▶ if (!tkr_rrule_part(p, (size_t)(eq - p), eq + 1, (size_t)(e - eq - 1), r, &seen, &rscale, err))
Branch: 1 branch
BranchTrueFalseTotal
if (!tkr_rrule_part(p, (size_t)(eq - p), eq + 1, (size_t)(e - eq - 1), r, &seen, &rscale, err)) 33 6735 6768
318 33 return 0;
319 6735 ▶ p = e < end ? e + 1 : e;
Branch: 1 branch
BranchTrueFalseTotal
p = e < end ? e + 1 : e; 4202 2533 6735
320 }
321 2533 ▶ if (!(seen & 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(seen & 1)) { 2 2531 2533
322 2 tkr_err(err, "FREQ is wanted");
323 2 return 0;
324 }
325 2531 ▶ if (r->count && r->until_kind != TKR_UNTIL_NONE) {
Branch: 2 branches
BranchTrueFalseTotal
if (r->count && r->until_kind != TKR_UNTIL_NONE) { 208 2323 2531
if (r->count && r->until_kind != TKR_UNTIL_NONE) { 1 207 208
326 1 tkr_err(err, "UNTIL and COUNT cannot both be given");
327 1 return 0;
328 }
329 2530 ▶ if (tkr_has_by_day_ordinal(r) && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY) {
Branch: 3 branches
BranchTrueFalseTotal
if (tkr_has_by_day_ordinal(r) && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY) { 43 2487 2530
if (tkr_has_by_day_ordinal(r) && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY) { 12 31 43
if (tkr_has_by_day_ordinal(r) && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY) { 1 11 12
330 1 tkr_err(err, "an ordinal in BYDAY needs FREQ=MONTHLY or FREQ=YEARLY");
331 1 return 0;
332 }
333 2529 ▶ if (tkr_has_by_day_ordinal(r) && r->freq == TKR_YEARLY && r->n_weekno) {
Branch: 3 branches
BranchTrueFalseTotal
if (tkr_has_by_day_ordinal(r) && r->freq == TKR_YEARLY && r->n_weekno) { 42 2487 2529
if (tkr_has_by_day_ordinal(r) && r->freq == TKR_YEARLY && r->n_weekno) { 11 31 42
if (tkr_has_by_day_ordinal(r) && r->freq == TKR_YEARLY && r->n_weekno) { 1 10 11
334 1 tkr_err(err, "an ordinal in BYDAY cannot be given with BYWEEKNO");
335 1 return 0;
336 }
337 2528 ▶ if (r->n_weekno && r->freq != TKR_YEARLY) {
Branch: 2 branches
BranchTrueFalseTotal
if (r->n_weekno && r->freq != TKR_YEARLY) { 11 2517 2528
if (r->n_weekno && r->freq != TKR_YEARLY) { 1 10 11
338 1 tkr_err(err, "BYWEEKNO needs FREQ=YEARLY");
339 1 return 0;
340 }
341 2527 ▶ if (r->n_yearday && (r->freq == TKR_DAILY || r->freq == TKR_WEEKLY || r->freq == TKR_MONTHLY)) {
Branch: 4 branches
BranchTrueFalseTotal
if (r->n_yearday && (r->freq == TKR_DAILY || r->freq == TKR_WEEKLY || r->freq == TKR_MONTHLY)) { 10 2517 2527
if (r->n_yearday && (r->freq == TKR_DAILY || r->freq == TKR_WEEKLY || r->freq == TKR_MONTHLY)) { 10 0 10
if (r->n_yearday && (r->freq == TKR_DAILY || r->freq == TKR_WEEKLY || r->freq == TKR_MONTHLY)) { 10 0 10
if (r->n_yearday && (r->freq == TKR_DAILY || r->freq == TKR_WEEKLY || r->freq == TKR_MONTHLY)) { 1 9 10
342 1 tkr_err(err, "BYYEARDAY cannot be given with FREQ=DAILY, WEEKLY or MONTHLY");
343 1 return 0;
344 }
345 2526 ▶ if (r->by_monthday && r->freq == TKR_WEEKLY) {
Branch: 2 branches
BranchTrueFalseTotal
if (r->by_monthday && r->freq == TKR_WEEKLY) { 238 2288 2526
if (r->by_monthday && r->freq == TKR_WEEKLY) { 1 237 238
346 1 tkr_err(err, "BYMONTHDAY cannot be given with FREQ=WEEKLY");
347 1 return 0;
348 }
349 2525 ▶ if ((seen & (1u << 15)) && !(r->flags & TKR_F_RSCALE)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((seen & (1u << 15)) && !(r->flags & TKR_F_RSCALE)) { 193 2332 2525
if ((seen & (1u << 15)) && !(r->flags & TKR_F_RSCALE)) { 1 192 193
350 1 tkr_err(err, "SKIP needs RSCALE");
351 1 return 0;
352 }
353 2524 ▶ if (r->n_weekno && (r->flags & TKR_F_RSCALE)) {
Branch: 2 branches
BranchTrueFalseTotal
if (r->n_weekno && (r->flags & TKR_F_RSCALE)) { 10 2514 2524
if (r->n_weekno && (r->flags & TKR_F_RSCALE)) { 1 9 10
354 1 tkr_err(err, "BYWEEKNO cannot be given with RSCALE: no calendar here numbers weeks but the Gregorian");
355 1 return 0;
356 }
357 2523 ▶ if (r->n_setpos && !tkr_has_any_by(r)) {
Branch: 2 branches
BranchTrueFalseTotal
if (r->n_setpos && !tkr_has_any_by(r)) { 20 2503 2523
if (r->n_setpos && !tkr_has_any_by(r)) { 1 19 20
358 1 tkr_err(err, "BYSETPOS needs another BY part to choose from");
359 1 return 0;
360 }
361 2522 return 1;
362 }
363  
364 /* ---- writing ------------------------------------------------------------- */
365  
366 static void
367 2184 tkr_cat(pTHX_ SV *out, const char *s)
368 {
369 2184 sv_catpv(out, s);
370 2184 }
371  
372 static void
373 3567 tkr_cat_list_mask64(pTHX_ SV *out, const char *name, uint64_t mask, int lo, int hi)
374 {
375 3567 int v, first = 1;
376 3567 ▶ if (!mask)
Branch: 1 branch
BranchTrueFalseTotal
if (!mask) 3384 183 3567
377 3384 return;
378 183 sv_catpvf(out, ";%s=", name);
379 7927 ▶ for (v = lo; v <= hi; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = lo; v <= hi; v++) 7744 183 7927
380 7744 ▶ if (mask & (UINT64_C(1) << v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (mask & (UINT64_C(1) << v)) { 372 7372 7744
381 372 ▶ sv_catpvf(out, first ? "%d" : ",%d", v);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, first ? "%d" : ",%d", v); 183 189 372
382 372 first = 0;
383 }
384 }
385  
386 static void
387 2378 tkr_cat_list16(pTHX_ SV *out, const char *name, const int16_t *list, unsigned n)
388 {
389 unsigned i;
390 2378 ▶ if (!n)
Branch: 1 branch
BranchTrueFalseTotal
if (!n) 2348 30 2378
391 2348 return;
392 30 sv_catpvf(out, ";%s=", name);
393 80 ▶ for (i = 0; i < n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) 50 30 80
394 50 ▶ sv_catpvf(out, i ? ",%d" : "%d", (int)list[i]);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, i ? ",%d" : "%d", (int)list[i]); 20 30 50
395 }
396  
397 /* The canonical text: the RFC's order of parts, values ascending, no
398 * INTERVAL=1, no WKST=MO. */
399 static void
400 1189 tkr_rrule_write(pTHX_ const tkr_rule *r, SV *out)
401 {
402 int w, i;
403 1189 sv_setpvs(out, "");
404 1189 ▶ if (r->flags & TKR_F_RSCALE) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->flags & TKR_F_RSCALE) { 593 596 1189
405 593 const char *id = NULL;
406 593 ▶ if (r->calendar == 0 || (tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id)
Branch: 3 branches
BranchTrueFalseTotal
if (r->calendar == 0 || (tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id) 517 76 593
if (r->calendar == 0 || (tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id) 517 0 517
if (r->calendar == 0 || (tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id) 0 517 517
407 76 id = "gregorian";
408 593 tkr_cat(aTHX_ out, "RSCALE=");
409 5501 ▶ for (; *id; id++)
Branch: 1 branch
BranchTrueFalseTotal
for (; *id; id++) 4908 593 5501
410 4908 ▶ sv_catpvf(out, "%c", toUPPER(*id));
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, "%c", toUPPER(*id)); 4806 102 4908
411 593 tkr_cat(aTHX_ out, ";");
412 }
413 1189 sv_catpvf(out, "FREQ=%s", tkr_freq_names[r->freq]);
414 1189 ▶ if (r->until_kind != TKR_UNTIL_NONE) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->until_kind != TKR_UNTIL_NONE) { 105 1084 1189
415 105 ▶ int64_t days = r->until_sec >= 0 ? r->until_sec / 86400 : -((-r->until_sec + 86399) / 86400);
Branch: 1 branch
BranchTrueFalseTotal
int64_t days = r->until_sec >= 0 ? r->until_sec / 86400 : -((-r->until_sec + 86399) / 86400); 105 0 105
416 105 int64_t rem = r->until_sec - days * 86400, y;
417 unsigned m, d;
418 105 tkr_civil_from_days(days, &y, &m, &d);
419 105 sv_catpvf(out, ";UNTIL=%04" IVdf "%02u%02u", (IV)y, m, d);
420 105 ▶ if (r->until_kind != TKR_UNTIL_DATE)
Branch: 1 branch
BranchTrueFalseTotal
if (r->until_kind != TKR_UNTIL_DATE) 104 1 105
421 104 ▶ sv_catpvf(out, "T%02d%02d%02d%s", (int)(rem / 3600), (int)(rem % 3600 / 60), (int)(rem % 60),
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, "T%02d%02d%02d%s", (int)(rem / 3600), (int)(rem % 3600 / 60), (int)(rem % 60), 103 1 104
422 r->until_kind == TKR_UNTIL_UTC ? "Z" : "");
423 }
424 1189 ▶ if (r->count)
Branch: 1 branch
BranchTrueFalseTotal
if (r->count) 228 961 1189
425 228 sv_catpvf(out, ";COUNT=%" IVdf, (IV)r->count);
426 1189 ▶ if (r->interval != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (r->interval != 1) 539 650 1189
427 539 sv_catpvf(out, ";INTERVAL=%u", (unsigned)r->interval);
428 1189 tkr_cat_list_mask64(aTHX_ out, "BYSECOND", r->by_second, 0, 60);
429 1189 tkr_cat_list_mask64(aTHX_ out, "BYMINUTE", r->by_minute, 0, 59);
430 1189 tkr_cat_list_mask64(aTHX_ out, "BYHOUR", r->by_hour, 0, 23);
431 1189 ▶ if (tkr_has_by_day(r)) {
Branch: 1 branch
BranchTrueFalseTotal
if (tkr_has_by_day(r)) { 473 716 1189
432 473 int first = 1;
433 473 tkr_cat(aTHX_ out, ";BYDAY=");
434 3784 ▶ for (w = 0; w < 7; w++) {
Branch: 1 branch
BranchTrueFalseTotal
for (w = 0; w < 7; w++) { 3311 473 3784
435 3311 ▶ if (r->by_day_any & (1u << w)) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_day_any & (1u << w)) { 756 2555 3311
436 756 ▶ sv_catpvf(out, first ? "%s" : ",%s", tkr_day_names[w]);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, first ? "%s" : ",%s", tkr_day_names[w]); 418 338 756
437 756 first = 0;
438 }
439 178794 ▶ for (i = 1; i <= 53; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= 53; i++) 175483 3311 178794
440 175483 ▶ if (r->by_day_pos[w] & (UINT64_C(1) << i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_day_pos[w] & (UINT64_C(1) << i)) { 43 175440 175483
441 43 ▶ sv_catpvf(out, first ? "%d%s" : ",%d%s", i, tkr_day_names[w]);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, first ? "%d%s" : ",%d%s", i, tkr_day_names[w]); 43 0 43
442 43 first = 0;
443 }
444 178794 ▶ for (i = 1; i <= 53; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= 53; i++) 175483 3311 178794
445 175483 ▶ if (r->by_day_neg[w] & (UINT64_C(1) << i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_day_neg[w] & (UINT64_C(1) << i)) { 24 175459 175483
446 24 ▶ sv_catpvf(out, first ? "-%d%s" : ",-%d%s", i, tkr_day_names[w]);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, first ? "-%d%s" : ",-%d%s", i, tkr_day_names[w]); 12 12 24
447 24 first = 0;
448 }
449 }
450 }
451 1189 ▶ if (r->by_monthday) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_monthday) { 267 922 1189
452 267 int first = 1;
453 267 tkr_cat(aTHX_ out, ";BYMONTHDAY=");
454 8544 ▶ for (i = 1; i <= 31; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= 31; i++) 8277 267 8544
455 8277 ▶ if (r->by_monthday & (UINT64_C(1) << i)) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_monthday & (UINT64_C(1) << i)) { 404 7873 8277
456 404 ▶ sv_catpvf(out, first ? "%d" : ",%d", i);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, first ? "%d" : ",%d", i); 212 192 404
457 404 first = 0;
458 }
459 8544 ▶ for (i = 1; i <= 31; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= 31; i++) 8277 267 8544
460 8277 ▶ if (r->by_monthday & (UINT64_C(1) << (32 + i))) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_monthday & (UINT64_C(1) << (32 + i))) { 68 8209 8277
461 68 ▶ sv_catpvf(out, first ? "-%d" : ",-%d", i);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, first ? "-%d" : ",-%d", i); 55 13 68
462 68 first = 0;
463 }
464 }
465 1189 tkr_cat_list16(aTHX_ out, "BYYEARDAY", r->by_yearday, r->n_yearday);
466 1189 ▶ if (r->n_weekno) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->n_weekno) { 10 1179 1189
467 10 tkr_cat(aTHX_ out, ";BYWEEKNO=");
468 20 ▶ for (i = 0; i < r->n_weekno; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < r->n_weekno; i++) 10 10 20
469 10 ▶ sv_catpvf(out, i ? ",%d" : "%d", (int)r->by_weekno[i]);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, i ? ",%d" : "%d", (int)r->by_weekno[i]); 0 10 10
470 }
471 1189 ▶ if (r->by_month || r->by_month_leap) {
Branch: 2 branches
BranchTrueFalseTotal
if (r->by_month || r->by_month_leap) { 951 238 1189
if (r->by_month || r->by_month_leap) { 10 941 951
472 248 int first = 1;
473 248 tkr_cat(aTHX_ out, ";BYMONTH=");
474 3472 ▶ for (i = 1; i <= 13; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= 13; i++) { 3224 248 3472
475 3224 ▶ if (r->by_month & (1u << i)) { sv_catpvf(out, first ? "%d" : ",%d", i); first = 0; }
Branch: 2 branches
BranchTrueFalseTotal
if (r->by_month & (1u << i)) { sv_catpvf(out, first ? "%d" : ",%d", i); first = 0; } 291 2933 3224
if (r->by_month & (1u << i)) { sv_catpvf(out, first ? "%d" : ",%d", i); first = 0; } 238 53 291
476 3224 ▶ if (r->by_month_leap & (1u << i)) { sv_catpvf(out, first ? "%dL" : ",%dL", i); first = 0; }
Branch: 2 branches
BranchTrueFalseTotal
if (r->by_month_leap & (1u << i)) { sv_catpvf(out, first ? "%dL" : ",%dL", i); first = 0; } 10 3214 3224
if (r->by_month_leap & (1u << i)) { sv_catpvf(out, first ? "%dL" : ",%dL", i); first = 0; } 10 0 10
477 }
478 }
479 1189 tkr_cat_list16(aTHX_ out, "BYSETPOS", r->by_setpos, r->n_setpos);
480 1189 ▶ if (r->wkst != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (r->wkst != 0) 60 1129 1189
481 60 sv_catpvf(out, ";WKST=%s", tkr_day_names[r->wkst]);
482 1189 ▶ if ((r->flags & TKR_F_RSCALE) && r->skip != TKR_SKIP_OMIT)
Branch: 2 branches
BranchTrueFalseTotal
if ((r->flags & TKR_F_RSCALE) && r->skip != TKR_SKIP_OMIT) 593 596 1189
if ((r->flags & TKR_F_RSCALE) && r->skip != TKR_SKIP_OMIT) 208 385 593
483 208 sv_catpvf(out, ";SKIP=%s", tkr_skip_upper[r->skip]);
484 1189 }
485  
486 #endif
« xs/rule.xs ↑ Summary blib/lib/Time/Keeper/Recurrence.pm »