include/tkr/tkr_describe.h

filter: Statementstmt 91.4% 362 / 396 Branchbran 73.8% 341 / 462 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 81.9% 703 / 858 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/tkr/tkr_abi_impl.h ↑ Summary xs/set.xs »
1 #ifndef TKR_DESCRIBE_H
2 #define TKR_DESCRIBE_H
3  
4 /* A rule in English words, from the compiled rule, so a cron, an RRULE and
5 * the named arguments read the same: "At 09:00, Monday to Friday", "Every
6 * 15 minutes from 09:00 to 17:45", "On the first Monday of every month",
7 * "On the last day of every month, 12 times". The rule's own spelling is
8 * not consulted. A part the words do not cover reads as its numbers, never
9 * as nothing. */
10  
11 static const char *const tkr_d_day[7] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
12 static const char *const tkr_d_month[13] = { "", "January", "February", "March", "April", "May", "June", "July",
13 "August", "September", "October", "November", "December" };
14 static const char *const tkr_d_nth[6] = { "", "first", "second", "third", "fourth", "fifth" };
15  
16 #define TKR_D_ITEMS 64
17 #define TKR_D_ITEM 48
18  
19 typedef struct tkr_d_list {
20 char item[TKR_D_ITEMS][TKR_D_ITEM];
21 int n;
22 } tkr_d_list;
23  
24 static void
25 134 tkr_d_add(tkr_d_list *l, const char *fmt, ...)
26 {
27 va_list ap;
28 134 ▶ if (l->n >= TKR_D_ITEMS)
Branch: 1 branch
BranchTrueFalseTotal
if (l->n >= TKR_D_ITEMS) 0 134 134
29 0 return;
30 134 va_start(ap, fmt);
31 134 vsnprintf(l->item[l->n], TKR_D_ITEM, fmt, ap);
32 134 va_end(ap);
33 134 l->n++;
34 }
35  
36 /* "a", "a and b", "a, b and c" */
37 static void
38 96 tkr_d_join(pTHX_ SV *out, const tkr_d_list *l, const char *last)
39 {
40 int i;
41 230 ▶ for (i = 0; i < l->n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < l->n; i++) { 134 96 230
42 134 ▶ if (i)
Branch: 1 branch
BranchTrueFalseTotal
if (i) 38 96 134
43 38 ▶ sv_catpv(out, i == l->n - 1 ? last : ", ");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpv(out, i == l->n - 1 ? last : ", "); 28 10 38
44 134 sv_catpv(out, l->item[i]);
45 }
46 96 }
47  
48 static int
49 244 tkr_d_bits(uint64_t m)
50 {
51 244 int n = 0;
52 588 ▶ for (; m; m &= m - 1)
Branch: 1 branch
BranchTrueFalseTotal
for (; m; m &= m - 1) 344 244 588
53 344 n++;
54 244 return n;
55 }
56  
57 static int
58 97 tkr_d_lowest(uint64_t m, int lo, int hi)
59 {
60 int v;
61 405 ▶ for (v = lo; v <= hi; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = lo; v <= hi; v++) 405 0 405
62 405 ▶ if (m & (UINT64_C(1) << v))
Branch: 1 branch
BranchTrueFalseTotal
if (m & (UINT64_C(1) << v)) 97 308 405
63 97 return v;
64 0 return -1;
65 }
66  
67 static int
68 73 tkr_d_highest(uint64_t m, int lo, int hi)
69 {
70 int v;
71 470 ▶ for (v = hi; v >= lo; v--)
Branch: 1 branch
BranchTrueFalseTotal
for (v = hi; v >= lo; v--) 470 0 470
72 470 ▶ if (m & (UINT64_C(1) << v))
Branch: 1 branch
BranchTrueFalseTotal
if (m & (UINT64_C(1) << v)) 73 397 470
73 73 return v;
74 0 return -1;
75 }
76  
77 /* The mask is every value from lo to hi. */
78 static int
79 15 tkr_d_full(uint64_t m, int lo, int hi)
80 {
81 int v;
82 20 ▶ for (v = lo; v <= hi; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = lo; v <= hi; v++) 20 0 20
83 20 ▶ if (!(m & (UINT64_C(1) << v)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(m & (UINT64_C(1) << v))) 15 5 20
84 15 return 0;
85 0 return 1;
86 }
87  
88 /* One run a..b with nothing else: 1 with *a and *b. */
89 static int
90 70 tkr_d_run(uint64_t m, int lo, int hi, int *a, int *b)
91 {
92 70 int f = tkr_d_lowest(m, lo, hi), l = tkr_d_highest(m, lo, hi), v;
93 70 ▶ if (f < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (f < 0) 0 70 70
94 0 return 0;
95 227 ▶ for (v = f; v <= l; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = f; v <= l; v++) 176 51 227
96 176 ▶ if (!(m & (UINT64_C(1) << v)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(m & (UINT64_C(1) << v))) 19 157 176
97 19 return 0;
98 51 *a = f;
99 51 *b = l;
100 51 return 1;
101 }
102  
103 /* Every step-th value from the first to the end of lo..hi: 1 with the step
104 * and the first. A single value is no step. The minutes' caller asks for a
105 * first of 0 ("every 15 minutes" is :00, :15, :30, :45). */
106 static int
107 15 tkr_d_step(uint64_t m, int lo, int hi, int *step, int *first)
108 {
109 15 int f = tkr_d_lowest(m, lo, hi), s = -1, v, n = tkr_d_bits(m);
110 15 ▶ if (n < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (n < 2) 2 13 15
111 2 return 0;
112 106 ▶ for (v = f + 1; v <= hi; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = f + 1; v <= hi; v++) 106 0 106
113 106 ▶ if (m & (UINT64_C(1) << v)) { s = v - f; break; }
Branch: 1 branch
BranchTrueFalseTotal
if (m & (UINT64_C(1) << v)) { s = v - f; break; } 13 93 106
114 13 ▶ if (s < 2)
Branch: 1 branch
BranchTrueFalseTotal
if (s < 2) 5 8 13
115 5 return 0;
116 380 ▶ for (v = lo; v <= hi; v++) {
Branch: 1 branch
BranchTrueFalseTotal
for (v = lo; v <= hi; v++) { 372 8 380
117 372 ▶ int want = v >= f && (v - f) % s == 0;
Branch: 2 branches
BranchTrueFalseTotal
int want = v >= f && (v - f) % s == 0; 325 47 372
int want = v >= f && (v - f) % s == 0; 47 278 325
118 372 ▶ if (want != !!(m & (UINT64_C(1) << v)))
Branch: 1 branch
BranchTrueFalseTotal
if (want != !!(m & (UINT64_C(1) << v))) 0 372 372
119 0 return 0;
120 }
121 8 *step = s;
122 8 *first = f;
123 8 return 1;
124 }
125  
126 static void
127 24 tkr_d_ordinal(char *buf, size_t n, int v)
128 {
129 24 const char *suf = "th";
130 24 int t = v % 100;
131 24 ▶ if (t < 11 || t > 13) {
Branch: 2 branches
BranchTrueFalseTotal
if (t < 11 || t > 13) { 12 12 24
if (t < 11 || t > 13) { 8 4 12
132 20 ▶ if (v % 10 == 1) suf = "st";
Branch: 1 branch
BranchTrueFalseTotal
if (v % 10 == 1) suf = "st"; 6 14 20
133 14 ▶ else if (v % 10 == 2) suf = "nd";
Branch: 1 branch
BranchTrueFalseTotal
else if (v % 10 == 2) suf = "nd"; 2 12 14
134 12 ▶ else if (v % 10 == 3) suf = "rd";
Branch: 1 branch
BranchTrueFalseTotal
else if (v % 10 == 3) suf = "rd"; 0 12 12
135 }
136 24 snprintf(buf, n, "%d%s", v, suf);
137 24 }
138  
139 /* "first" .. "fifth", "53rd"; from the end "last", "second to last". */
140 static void
141 19 tkr_d_nth_word(char *buf, size_t n, int v)
142 {
143 char o[16];
144 28 ▶ if (v > 0 && v <= 5) { snprintf(buf, n, "%s", tkr_d_nth[v]); return; }
Branch: 2 branches
BranchTrueFalseTotal
if (v > 0 && v <= 5) { snprintf(buf, n, "%s", tkr_d_nth[v]); return; } 10 9 19
if (v > 0 && v <= 5) { snprintf(buf, n, "%s", tkr_d_nth[v]); return; } 8 2 10
145 11 ▶ if (v == -1) { snprintf(buf, n, "last"); return; }
Branch: 1 branch
BranchTrueFalseTotal
if (v == -1) { snprintf(buf, n, "last"); return; } 5 6 11
146 6 ▶ if (v < 0 && v >= -5) { snprintf(buf, n, "%s to last", tkr_d_nth[-v]); return; }
Branch: 2 branches
BranchTrueFalseTotal
if (v < 0 && v >= -5) { snprintf(buf, n, "%s to last", tkr_d_nth[-v]); return; } 4 2 6
if (v < 0 && v >= -5) { snprintf(buf, n, "%s to last", tkr_d_nth[-v]); return; } 4 0 4
147 2 tkr_d_ordinal(o, sizeof o, v < 0 ? -v : v);
148 2 ▶ snprintf(buf, n, v < 0 ? "%s to last" : "%s", o);
Branch: 1 branch
BranchTrueFalseTotal
snprintf(buf, n, v < 0 ? "%s to last" : "%s", o); 0 2 2
149 }
150  
151 /* ---- the time of day ------------------------------------------------------ */
152  
153 static void
154 67 tkr_d_every(pTHX_ SV *out, unsigned n, const char *one, const char *many)
155 {
156 67 ▶ if (n == 1) sv_catpvf(out, "every %s", one);
Branch: 1 branch
BranchTrueFalseTotal
if (n == 1) sv_catpvf(out, "every %s", one); 41 26 67
157 26 else sv_catpvf(out, "every %u %s", n, many);
158 67 }
159  
160 /* The minutes within an hour: "every minute", "every 15 minutes", "on the
161 * hour", "at 15 minutes past the hour", "at 0, 15 and 45 minutes past". */
162 static void
163 12 tkr_d_minutes(pTHX_ SV *out, const tkr_rule *r)
164 {
165 12 uint64_t m = r->by_minute;
166 int step, first, v;
167 12 ▶ if (!m || tkr_d_full(m, 0, 59)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!m || tkr_d_full(m, 0, 59)) { 7 5 12
if (!m || tkr_d_full(m, 0, 59)) { 0 7 7
168 5 ▶ if (r->freq == TKR_MINUTELY && !m) tkr_d_every(aTHX_ out, r->interval, "minute", "minutes");
Branch: 2 branches
BranchTrueFalseTotal
if (r->freq == TKR_MINUTELY && !m) tkr_d_every(aTHX_ out, r->interval, "minute", "minutes"); 5 0 5
if (r->freq == TKR_MINUTELY && !m) tkr_d_every(aTHX_ out, r->interval, "minute", "minutes"); 5 0 5
169 0 else sv_catpvs(out, "every minute");
170 10 return;
171 }
172 7 ▶ if (tkr_d_step(m, 0, 59, &step, &first) && first == 0 && 60 % step == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (tkr_d_step(m, 0, 59, &step, &first) && first == 0 && 60 % step == 0) { 5 2 7
if (tkr_d_step(m, 0, 59, &step, &first) && first == 0 && 60 % step == 0) { 3 2 5
if (tkr_d_step(m, 0, 59, &step, &first) && first == 0 && 60 % step == 0) { 3 0 3
173 3 sv_catpvf(out, "every %d minutes", step);
174 3 return;
175 }
176 4 ▶ if (tkr_d_bits(m) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (tkr_d_bits(m) == 1) { 2 2 4
177 2 v = tkr_d_lowest(m, 0, 59);
178 2 ▶ if (v == 0) sv_catpvs(out, "on the hour");
Branch: 1 branch
BranchTrueFalseTotal
if (v == 0) sv_catpvs(out, "on the hour"); 1 1 2
179 1 ▶ else sv_catpvf(out, "at %d minute%s past the hour", v, v == 1 ? "" : "s");
Branch: 1 branch
BranchTrueFalseTotal
else sv_catpvf(out, "at %d minute%s past the hour", v, v == 1 ? "" : "s"); 0 1 1
180 2 return;
181 }
182 {
183 tkr_d_list l;
184 2 l.n = 0;
185 122 ▶ for (v = 0; v <= 59; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = 0; v <= 59; v++) 120 2 122
186 120 ▶ if (m & (UINT64_C(1) << v))
Branch: 1 branch
BranchTrueFalseTotal
if (m & (UINT64_C(1) << v)) 5 115 120
187 5 tkr_d_add(&l, "%d", v);
188 2 sv_catpvs(out, "at ");
189 2 tkr_d_join(aTHX_ out, &l, " and ");
190 2 sv_catpvs(out, " minutes past the hour");
191 }
192 }
193  
194 static void
195 36 tkr_d_seconds(pTHX_ SV *out, const tkr_rule *r)
196 {
197 36 uint64_t s = r->by_second;
198 int v;
199 tkr_d_list l;
200 36 ▶ if (!s || (tkr_d_bits(s) == 1 && (s & 1)))
Branch: 3 branches
BranchTrueFalseTotal
if (!s || (tkr_d_bits(s) == 1 && (s & 1))) 0 36 36
if (!s || (tkr_d_bits(s) == 1 && (s & 1))) 0 0 0
if (!s || (tkr_d_bits(s) == 1 && (s & 1))) 0 0 0
201 36 return;
202 0 l.n = 0;
203 0 ▶ for (v = 0; v <= 60; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = 0; v <= 60; v++) 0 0 0
204 0 ▶ if (s & (UINT64_C(1) << v))
Branch: 1 branch
BranchTrueFalseTotal
if (s & (UINT64_C(1) << v)) 0 0 0
205 0 tkr_d_add(&l, "%d", v);
206 0 ▶ sv_catpvf(out, ", at second%s ", l.n == 1 ? "" : "s");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, ", at second%s ", l.n == 1 ? "" : "s"); 0 0 0
207 0 tkr_d_join(aTHX_ out, &l, " and ");
208 }
209  
210 /* The time of day, or nothing when the rule takes it from its start. 1 when
211 * something was written. */
212 static int
213 96 tkr_d_time(pTHX_ SV *out, const tkr_rule *r)
214 {
215 96 uint64_t h = r->by_hour, m = r->by_minute;
216 96 int nh = tkr_d_bits(h), nm = tkr_d_bits(m), a, b, step, first;
217 96 STRLEN at = SvCUR(out);
218  
219 96 ▶ if (r->freq == TKR_SECONDLY && !r->by_second && !m && !h) {
Branch: 4 branches
BranchTrueFalseTotal
if (r->freq == TKR_SECONDLY && !r->by_second && !m && !h) { 1 95 96
if (r->freq == TKR_SECONDLY && !r->by_second && !m && !h) { 1 0 1
if (r->freq == TKR_SECONDLY && !r->by_second && !m && !h) { 1 0 1
if (r->freq == TKR_SECONDLY && !r->by_second && !m && !h) { 1 0 1
220 1 tkr_d_every(aTHX_ out, r->interval, "second", "seconds");
221 1 return 1;
222 }
223 95 ▶ if (r->freq == TKR_HOURLY && !h) {
Branch: 2 branches
BranchTrueFalseTotal
if (r->freq == TKR_HOURLY && !h) { 2 93 95
if (r->freq == TKR_HOURLY && !h) { 2 0 2
224 2 tkr_d_every(aTHX_ out, r->interval, "hour", "hours");
225 2 ▶ if (m) { sv_catpvs(out, ", "); tkr_d_minutes(aTHX_ out, r); }
Branch: 1 branch
BranchTrueFalseTotal
if (m) { sv_catpvs(out, ", "); tkr_d_minutes(aTHX_ out, r); } 0 2 2
226 2 tkr_d_seconds(aTHX_ out, r);
227 2 return 1;
228 }
229 93 ▶ if (!h && !m && r->freq >= TKR_DAILY)
Branch: 3 branches
BranchTrueFalseTotal
if (!h && !m && r->freq >= TKR_DAILY) 67 26 93
if (!h && !m && r->freq >= TKR_DAILY) 62 5 67
if (!h && !m && r->freq >= TKR_DAILY) 59 3 62
230 59 return 0; /* the start's time */
231  
232 /* a few times of day: "at 09:00 and 17:30" */
233 34 ▶ if (nh && nm && nh * nm <= 6) {
Branch: 3 branches
BranchTrueFalseTotal
if (nh && nm && nh * nm <= 6) { 26 8 34
if (nh && nm && nh * nm <= 6) { 24 2 26
if (nh && nm && nh * nm <= 6) { 18 6 24
234 tkr_d_list l;
235 int hh, mm;
236 18 l.n = 0;
237 450 ▶ for (hh = 0; hh <= 23; hh++)
Branch: 1 branch
BranchTrueFalseTotal
for (hh = 0; hh <= 23; hh++) 432 18 450
238 432 ▶ if (h & (1u << hh))
Branch: 1 branch
BranchTrueFalseTotal
if (h & (1u << hh)) 27 405 432
239 1647 ▶ for (mm = 0; mm <= 59; mm++)
Branch: 1 branch
BranchTrueFalseTotal
for (mm = 0; mm <= 59; mm++) 1620 27 1647
240 1620 ▶ if (m & (UINT64_C(1) << mm))
Branch: 1 branch
BranchTrueFalseTotal
if (m & (UINT64_C(1) << mm)) 27 1593 1620
241 27 tkr_d_add(&l, "%02d:%02d", hh, mm);
242 18 sv_catpvs(out, "at ");
243 18 tkr_d_join(aTHX_ out, &l, " and ");
244 18 tkr_d_seconds(aTHX_ out, r);
245 18 return 1;
246 }
247 16 ▶ if (!h || tkr_d_full(h, 0, 23)) { /* every hour of the day */
Branch: 2 branches
BranchTrueFalseTotal
if (!h || tkr_d_full(h, 0, 23)) { /* every hour of the day */ 8 8 16
if (!h || tkr_d_full(h, 0, 23)) { /* every hour of the day */ 0 8 8
248 8 ▶ if (nm == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (nm == 1) 2 6 8
249 2 sv_catpvs(out, "every hour, ");
250 8 tkr_d_minutes(aTHX_ out, r);
251 8 tkr_d_seconds(aTHX_ out, r);
252 8 return 1;
253 }
254 8 ▶ if (tkr_d_step(h, 0, 23, &step, &first)) { /* every 2 hours */
Branch: 1 branch
BranchTrueFalseTotal
if (tkr_d_step(h, 0, 23, &step, &first)) { /* every 2 hours */ 3 5 8
255 3 sv_catpvf(out, "every %d hours", step);
256 3 ▶ if (first) sv_catpvf(out, " from %02d:00", first);
Branch: 1 branch
BranchTrueFalseTotal
if (first) sv_catpvf(out, " from %02d:00", first); 2 1 3
257 3 ▶ if (nm == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (nm == 1) { 3 0 3
258 3 int v = tkr_d_lowest(m, 0, 59);
259 3 ▶ if (v == 0) sv_catpvs(out, ", on the hour");
Branch: 1 branch
BranchTrueFalseTotal
if (v == 0) sv_catpvs(out, ", on the hour"); 3 0 3
260 0 ▶ else sv_catpvf(out, ", at %d minute%s past", v, v == 1 ? "" : "s");
Branch: 1 branch
BranchTrueFalseTotal
else sv_catpvf(out, ", at %d minute%s past", v, v == 1 ? "" : "s"); 0 0 0
261 }
262 0 else { sv_catpvs(out, ", "); tkr_d_minutes(aTHX_ out, r); }
263 3 tkr_d_seconds(aTHX_ out, r);
264 3 return 1;
265 }
266 5 ▶ if (tkr_d_run(h, 0, 23, &a, &b)) { /* from 09:00 to 17:45 */
Branch: 1 branch
BranchTrueFalseTotal
if (tkr_d_run(h, 0, 23, &a, &b)) { /* from 09:00 to 17:45 */ 5 0 5
267 5 ▶ int mlo = m ? tkr_d_lowest(m, 0, 59) : 0, mhi = m ? tkr_d_highest(m, 0, 59) : 59;
Branch: 2 branches
BranchTrueFalseTotal
int mlo = m ? tkr_d_lowest(m, 0, 59) : 0, mhi = m ? tkr_d_highest(m, 0, 59) : 59; 3 2 5
int mlo = m ? tkr_d_lowest(m, 0, 59) : 0, mhi = m ? tkr_d_highest(m, 0, 59) : 59; 3 2 5
268 5 ▶ if (!m && r->freq == TKR_MINUTELY && r->interval > 1 && 60 % r->interval == 0)
Branch: 4 branches
BranchTrueFalseTotal
if (!m && r->freq == TKR_MINUTELY && r->interval > 1 && 60 % r->interval == 0) 2 3 5
if (!m && r->freq == TKR_MINUTELY && r->interval > 1 && 60 % r->interval == 0) 2 0 2
if (!m && r->freq == TKR_MINUTELY && r->interval > 1 && 60 % r->interval == 0) 2 0 2
if (!m && r->freq == TKR_MINUTELY && r->interval > 1 && 60 % r->interval == 0) 2 0 2
269 2 mhi = 60 - (int)r->interval; /* every 20 minutes: the last at :40 */
270 5 ▶ if (nm == 1) sv_catpvs(out, "every hour");
Branch: 1 branch
BranchTrueFalseTotal
if (nm == 1) sv_catpvs(out, "every hour"); 1 4 5
271 4 else tkr_d_minutes(aTHX_ out, r);
272 5 sv_catpvf(out, " from %02d:%02d to %02d:%02d", a, mlo, b, mhi);
273 5 tkr_d_seconds(aTHX_ out, r);
274 5 return 1;
275 }
276 { /* in the hours 9, 12 and 18 */
277 tkr_d_list l;
278 int v;
279 0 l.n = 0;
280 0 ▶ for (v = 0; v <= 23; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = 0; v <= 23; v++) 0 0 0
281 0 ▶ if (h & (1u << v))
Branch: 1 branch
BranchTrueFalseTotal
if (h & (1u << v)) 0 0 0
282 0 tkr_d_add(&l, "%02d", v);
283 0 tkr_d_minutes(aTHX_ out, r);
284 0 sv_catpvs(out, " in the hours ");
285 0 tkr_d_join(aTHX_ out, &l, " and ");
286 0 tkr_d_seconds(aTHX_ out, r);
287 }
288 0 return SvCUR(out) > at;
289 }
290  
291 /* ---- the days --------------------------------------------------------------- */
292  
293 /* The weekdays with no ordinal: "Monday to Friday", "Saturday and Sunday",
294 * "Monday, Wednesday and Friday". */
295 static void
296 29 tkr_d_weekdays(pTHX_ SV *out, unsigned w)
297 {
298 int a, b, v;
299 tkr_d_list l;
300 29 ▶ if (tkr_d_run(w, 0, 6, &a, &b) && b - a >= 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (tkr_d_run(w, 0, 6, &a, &b) && b - a >= 2) { 18 11 29
if (tkr_d_run(w, 0, 6, &a, &b) && b - a >= 2) { 5 13 18
301 5 sv_catpvf(out, "%s to %s", tkr_d_day[a], tkr_d_day[b]);
302 5 return;
303 }
304 24 l.n = 0;
305 192 ▶ for (v = 0; v < 7; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = 0; v < 7; v++) 168 24 192
306 168 ▶ if (w & (1u << v))
Branch: 1 branch
BranchTrueFalseTotal
if (w & (1u << v)) 38 130 168
307 38 tkr_d_add(&l, "%s", tkr_d_day[v]);
308 24 tkr_d_join(aTHX_ out, &l, " and ");
309 }
310  
311 /* The ordinal weekdays: "the first Monday", "the second and fourth Tuesday",
312 * "the last Friday". 1 when there were any. */
313 static int
314 10 tkr_d_ordinals(pTHX_ SV *out, const tkr_rule *r)
315 {
316 tkr_d_list l;
317 int w, i;
318 10 l.n = 0;
319 80 ▶ for (w = 0; w < 7; w++) {
Branch: 1 branch
BranchTrueFalseTotal
for (w = 0; w < 7; w++) { 70 10 80
320 tkr_d_list nths;
321 char buf[TKR_D_ITEM];
322 SV *tmp;
323 70 nths.n = 0;
324 3780 ▶ for (i = 1; i <= 53; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= 53; i++) 3710 70 3780
325 3710 ▶ if (r->by_day_pos[w] & (UINT64_C(1) << i)) { tkr_d_nth_word(buf, sizeof buf, i); tkr_d_add(&nths, "%s", buf); }
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_day_pos[w] & (UINT64_C(1) << i)) { tkr_d_nth_word(buf, sizeof buf, i); tkr_d_add(&nths, "%s", buf); } 9 3701 3710
326 3780 ▶ for (i = 53; i >= 1; i--)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 53; i >= 1; i--) 3710 70 3780
327 3710 ▶ if (r->by_day_neg[w] & (UINT64_C(1) << i)) { tkr_d_nth_word(buf, sizeof buf, -i); tkr_d_add(&nths, "%s", buf); }
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_day_neg[w] & (UINT64_C(1) << i)) { tkr_d_nth_word(buf, sizeof buf, -i); tkr_d_add(&nths, "%s", buf); } 3 3707 3710
328 70 ▶ if (!nths.n)
Branch: 1 branch
BranchTrueFalseTotal
if (!nths.n) 60 10 70
329 60 continue;
330 10 tmp = sv_2mortal(newSVpvs(""));
331 10 tkr_d_join(aTHX_ tmp, &nths, " and ");
332 20 tkr_d_add(&l, "%s %s", SvPV_nolen(tmp), tkr_d_day[w]);
333 }
334 10 ▶ if (!l.n)
Branch: 1 branch
BranchTrueFalseTotal
if (!l.n) 0 10 10
335 0 return 0;
336 10 sv_catpvs(out, "the ");
337 10 tkr_d_join(aTHX_ out, &l, " and the ");
338 10 return 1;
339 }
340  
341 /* The days of the month: "the 1st and 15th", "the last day". */
342 static void
343 15 tkr_d_monthdays(pTHX_ SV *out, uint64_t md)
344 {
345 tkr_d_list l;
346 char buf[TKR_D_ITEM];
347 int i;
348 15 l.n = 0;
349 458 ▶ for (i = 1; i <= 31; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i <= 31; i++) { 443 15 458
350 443 int e = i;
351 443 ▶ if (!(md & (UINT64_C(1) << i)))
Branch: 1 branch
BranchTrueFalseTotal
if (!(md & (UINT64_C(1) << i))) 427 16 443
352 427 continue;
353 38 ▶ while (e < 31 && (md & (UINT64_C(1) << (e + 1))))
Branch: 2 branches
BranchTrueFalseTotal
while (e < 31 && (md & (UINT64_C(1) << (e + 1)))) 38 0 38
while (e < 31 && (md & (UINT64_C(1) << (e + 1)))) 22 16 38
354 22 e++;
355 16 tkr_d_ordinal(buf, sizeof buf, i);
356 16 ▶ if (e - i >= 2) { /* a run: "the 10th to the 15th" */
Branch: 1 branch
BranchTrueFalseTotal
if (e - i >= 2) { /* a run: "the 10th to the 15th" */ 4 12 16
357 char end[TKR_D_ITEM];
358 4 tkr_d_ordinal(end, sizeof end, e);
359 4 tkr_d_add(&l, "%s to the %s", buf, end);
360 4 i = e;
361 }
362 12 else tkr_d_add(&l, "%s", buf);
363 }
364 480 ▶ for (i = 31; i >= 1; i--)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 31; i >= 1; i--) 465 15 480
365 465 ▶ if (md & (UINT64_C(1) << (32 + i))) { tkr_d_nth_word(buf, sizeof buf, -i); tkr_d_add(&l, "%s day", buf); }
Branch: 1 branch
BranchTrueFalseTotal
if (md & (UINT64_C(1) << (32 + i))) { tkr_d_nth_word(buf, sizeof buf, -i); tkr_d_add(&l, "%s day", buf); } 4 461 465
366 15 sv_catpvs(out, "the ");
367 15 tkr_d_join(aTHX_ out, &l, " and the ");
368 15 }
369  
370 /* The months; with prep, "in June and July" or "from March to October". */
371 static void
372 14 tkr_d_months(pTHX_ SV *out, const tkr_rule *r, int prep)
373 {
374 int a, b, v;
375 tkr_d_list l;
376 14 ▶ if (prep)
Branch: 1 branch
BranchTrueFalseTotal
if (prep) 11 3 14
377 11 ▶ sv_catpv(out, !(r->flags & TKR_F_RSCALE) && tkr_d_run(r->by_month, 1, 12, &a, &b) && b - a >= 2 ? "from " : "in ");
Branch: 3 branches
BranchTrueFalseTotal
sv_catpv(out, !(r->flags & TKR_F_RSCALE) && tkr_d_run(r->by_month, 1, 12, &a, &b) && b - a >= 2 ? "from " : "in "); 11 0 11
sv_catpv(out, !(r->flags & TKR_F_RSCALE) && tkr_d_run(r->by_month, 1, 12, &a, &b) && b - a >= 2 ? "from " : "in "); 11 0 11
sv_catpv(out, !(r->flags & TKR_F_RSCALE) && tkr_d_run(r->by_month, 1, 12, &a, &b) && b - a >= 2 ? "from " : "in "); 4 7 11
378 14 ▶ if (r->flags & TKR_F_RSCALE) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->flags & TKR_F_RSCALE) { 1 13 14
379 1 l.n = 0;
380 14 ▶ for (v = 1; v <= 13; v++) {
Branch: 1 branch
BranchTrueFalseTotal
for (v = 1; v <= 13; v++) { 13 1 14
381 13 ▶ if (r->by_month & (1u << v)) tkr_d_add(&l, "%d", v);
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_month & (1u << v)) tkr_d_add(&l, "%d", v); 1 12 13
382 13 ▶ if (r->by_month_leap & (1u << v)) tkr_d_add(&l, "%dL", v);
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_month_leap & (1u << v)) tkr_d_add(&l, "%dL", v); 0 13 13
383 }
384 1 ▶ sv_catpvf(out, "month%s ", l.n == 1 ? "" : "s");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, "month%s ", l.n == 1 ? "" : "s"); 1 0 1
385 1 tkr_d_join(aTHX_ out, &l, " and ");
386 5 return;
387 }
388 13 ▶ if (tkr_d_run(r->by_month, 1, 12, &a, &b) && b - a >= 2) {
Branch: 2 branches
BranchTrueFalseTotal
if (tkr_d_run(r->by_month, 1, 12, &a, &b) && b - a >= 2) { 13 0 13
if (tkr_d_run(r->by_month, 1, 12, &a, &b) && b - a >= 2) { 4 9 13
389 4 sv_catpvf(out, "%s to %s", tkr_d_month[a], tkr_d_month[b]);
390 4 return;
391 }
392 9 l.n = 0;
393 117 ▶ for (v = 1; v <= 12; v++)
Branch: 1 branch
BranchTrueFalseTotal
for (v = 1; v <= 12; v++) 108 9 117
394 108 ▶ if (r->by_month & (1u << v))
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_month & (1u << v)) 10 98 108
395 10 tkr_d_add(&l, "%s", tkr_d_month[v]);
396 9 tkr_d_join(aTHX_ out, &l, " and ");
397 }
398  
399 /* The days a rule keeps, without its cycle: "on Monday to Friday", "on the
400 * first Monday", "on the 1st and 15th", "on the 1st or on Monday" (cron's
401 * either), "on Friday the 13th". 1 when there was a restriction. */
402 static int
403 96 tkr_d_days(pTHX_ SV *out, const tkr_rule *r, int *monthly)
404 {
405 96 unsigned w = r->by_day_any;
406 96 int ord = tkr_has_by_day_ordinal(r), i;
407 96 STRLEN at = SvCUR(out);
408 96 *monthly = 0;
409 96 ▶ if (w == 0x7f && !ord && !r->by_monthday && !r->n_setpos) {
Branch: 4 branches
BranchTrueFalseTotal
if (w == 0x7f && !ord && !r->by_monthday && !r->n_setpos) { 1 95 96
if (w == 0x7f && !ord && !r->by_monthday && !r->n_setpos) { 1 0 1
if (w == 0x7f && !ord && !r->by_monthday && !r->n_setpos) { 1 0 1
if (w == 0x7f && !ord && !r->by_monthday && !r->n_setpos) { 1 0 1
410 1 ▶ if (r->freq > TKR_WEEKLY) { sv_catpvs(out, "every day"); return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (r->freq > TKR_WEEKLY) { sv_catpvs(out, "every day"); return 1; } 1 0 1
411 0 w = 0; /* every day of the week is no restriction */
412 }
413 95 ▶ if (r->n_setpos && (w || ord) && !r->by_monthday) {
Branch: 4 branches
BranchTrueFalseTotal
if (r->n_setpos && (w || ord) && !r->by_monthday) { 3 92 95
if (r->n_setpos && (w || ord) && !r->by_monthday) { 0 3 3
if (r->n_setpos && (w || ord) && !r->by_monthday) { 0 0 0
if (r->n_setpos && (w || ord) && !r->by_monthday) { 3 0 3
414 tkr_d_list l;
415 char buf[TKR_D_ITEM];
416 3 l.n = 0;
417 6 ▶ for (i = 0; i < r->n_setpos; i++) { tkr_d_nth_word(buf, sizeof buf, r->by_setpos[i]); tkr_d_add(&l, "%s", buf); }
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < r->n_setpos; i++) { tkr_d_nth_word(buf, sizeof buf, r->by_setpos[i]); tkr_d_add(&l, "%s", buf); } 3 3 6
418 3 sv_catpvs(out, "on the ");
419 3 tkr_d_join(aTHX_ out, &l, " and ");
420 3 ▶ if (w == 0x1f && !ord) sv_catpvf(out, " weekday%s", l.n == 1 ? "" : "s");
Branch: 3 branches
BranchTrueFalseTotal
if (w == 0x1f && !ord) sv_catpvf(out, " weekday%s", l.n == 1 ? "" : "s"); 2 1 3
if (w == 0x1f && !ord) sv_catpvf(out, " weekday%s", l.n == 1 ? "" : "s"); 2 0 2
if (w == 0x1f && !ord) sv_catpvf(out, " weekday%s", l.n == 1 ? "" : "s"); 2 0 2
421 1 ▶ else if (w == 0x60 && !ord) sv_catpvf(out, " weekend day%s", l.n == 1 ? "" : "s");
Branch: 3 branches
BranchTrueFalseTotal
else if (w == 0x60 && !ord) sv_catpvf(out, " weekend day%s", l.n == 1 ? "" : "s"); 0 1 1
else if (w == 0x60 && !ord) sv_catpvf(out, " weekend day%s", l.n == 1 ? "" : "s"); 0 0 0
else if (w == 0x60 && !ord) sv_catpvf(out, " weekend day%s", l.n == 1 ? "" : "s"); 0 0 0
422 else {
423 1 sv_catpvs(out, " of ");
424 1 ▶ if (ord) tkr_d_ordinals(aTHX_ out, r);
Branch: 1 branch
BranchTrueFalseTotal
if (ord) tkr_d_ordinals(aTHX_ out, r); 0 1 1
425 1 else tkr_d_weekdays(aTHX_ out, w);
426 }
427 3 ▶ *monthly = r->freq == TKR_MONTHLY || r->freq == TKR_YEARLY;
Branch: 2 branches
BranchTrueFalseTotal
*monthly = r->freq == TKR_MONTHLY || r->freq == TKR_YEARLY; 0 3 3
*monthly = r->freq == TKR_MONTHLY || r->freq == TKR_YEARLY; 0 0 0
428 3 return 1;
429 }
430 92 ▶ if (r->by_monthday && (w || ord)) {
Branch: 3 branches
BranchTrueFalseTotal
if (r->by_monthday && (w || ord)) { 17 75 92
if (r->by_monthday && (w || ord)) { 12 5 17
if (r->by_monthday && (w || ord)) { 0 12 12
431 5 ▶ if (r->flags & TKR_F_VIXIE) { /* cron: either field */
Branch: 1 branch
BranchTrueFalseTotal
if (r->flags & TKR_F_VIXIE) { /* cron: either field */ 1 4 5
432 1 sv_catpvs(out, "on ");
433 1 tkr_d_monthdays(aTHX_ out, r->by_monthday);
434 1 sv_catpvs(out, " of the month, or on ");
435 1 tkr_d_weekdays(aTHX_ out, w);
436 }
437 6 ▶ else if (!ord && tkr_d_bits(w) == 1 && tkr_d_bits(r->by_monthday) == 1 && (r->by_monthday & TKR_CRON_ALL(1, 31))) {
Branch: 4 branches
BranchTrueFalseTotal
else if (!ord && tkr_d_bits(w) == 1 && tkr_d_bits(r->by_monthday) == 1 && (r->by_monthday & TKR_CRON_ALL(1, 31))) { 4 0 4
else if (!ord && tkr_d_bits(w) == 1 && tkr_d_bits(r->by_monthday) == 1 && (r->by_monthday & TKR_CRON_ALL(1, 31))) { 4 0 4
else if (!ord && tkr_d_bits(w) == 1 && tkr_d_bits(r->by_monthday) == 1 && (r->by_monthday & TKR_CRON_ALL(1, 31))) { 2 2 4
else if (!ord && tkr_d_bits(w) == 1 && tkr_d_bits(r->by_monthday) == 1 && (r->by_monthday & TKR_CRON_ALL(1, 31))) { 2 0 2
438 char buf[TKR_D_ITEM]; /* both, one of each: "on Friday the 13th" */
439 2 tkr_d_ordinal(buf, sizeof buf, tkr_d_lowest(r->by_monthday, 1, 31));
440 2 sv_catpvf(out, "on %s the %s", tkr_d_day[tkr_d_lowest(w, 0, 6)], buf);
441 }
442 else { /* both: "on a Monday that is the 1st or the 2nd" */
443 2 sv_catpvs(out, "on ");
444 2 ▶ if (ord) tkr_d_ordinals(aTHX_ out, r);
Branch: 1 branch
BranchTrueFalseTotal
if (ord) tkr_d_ordinals(aTHX_ out, r); 0 2 2
445 2 else { sv_catpvs(out, "a "); tkr_d_weekdays(aTHX_ out, w); }
446 2 sv_catpvs(out, " that is ");
447 2 tkr_d_monthdays(aTHX_ out, r->by_monthday);
448 }
449 5 return 1;
450 }
451 87 ▶ if (ord) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord) { 10 77 87
452 10 sv_catpvs(out, "on ");
453 10 tkr_d_ordinals(aTHX_ out, r);
454 10 *monthly = 1;
455 }
456 77 ▶ else if (r->by_monthday) {
Branch: 1 branch
BranchTrueFalseTotal
else if (r->by_monthday) { 12 65 77
457 12 sv_catpvs(out, "on ");
458 12 tkr_d_monthdays(aTHX_ out, r->by_monthday);
459 12 *monthly = 1;
460 }
461 65 ▶ else if (w) {
Branch: 1 branch
BranchTrueFalseTotal
else if (w) { 21 44 65
462 21 ▶ if (r->freq == TKR_WEEKLY || r->freq == TKR_DAILY || r->freq < TKR_DAILY) {
Branch: 3 branches
BranchTrueFalseTotal
if (r->freq == TKR_WEEKLY || r->freq == TKR_DAILY || r->freq < TKR_DAILY) { 12 9 21
if (r->freq == TKR_WEEKLY || r->freq == TKR_DAILY || r->freq < TKR_DAILY) { 12 0 12
if (r->freq == TKR_WEEKLY || r->freq == TKR_DAILY || r->freq < TKR_DAILY) { 6 6 12
463 15 ▶ if (!(w == 0x1f || tkr_d_run(w, 0, 6, &i, &i)) || tkr_d_bits(w) < 3) sv_catpvs(out, "on ");
Branch: 3 branches
BranchTrueFalseTotal
if (!(w == 0x1f || tkr_d_run(w, 0, 6, &i, &i)) || tkr_d_bits(w) < 3) sv_catpvs(out, "on "); 12 3 15
if (!(w == 0x1f || tkr_d_run(w, 0, 6, &i, &i)) || tkr_d_bits(w) < 3) sv_catpvs(out, "on "); 4 8 12
if (!(w == 0x1f || tkr_d_run(w, 0, 6, &i, &i)) || tkr_d_bits(w) < 3) sv_catpvs(out, "on "); 4 3 7
464 }
465 6 else sv_catpvs(out, "on ");
466 21 tkr_d_weekdays(aTHX_ out, w);
467 }
468 87 ▶ if (r->n_yearday) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->n_yearday) { 2 85 87
469 tkr_d_list l;
470 char buf[TKR_D_ITEM];
471 2 ▶ if (SvCUR(out) > at) sv_catpvs(out, ", ");
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(out) > at) sv_catpvs(out, ", "); 0 2 2
472 2 l.n = 0;
473 8 ▶ for (i = 0; i < r->n_yearday; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < r->n_yearday; i++) { 6 2 8
474 6 int v = r->by_yearday[i];
475 6 ▶ if (v > 0) tkr_d_add(&l, "%d", v);
Branch: 1 branch
BranchTrueFalseTotal
if (v > 0) tkr_d_add(&l, "%d", v); 6 0 6
476 0 else { tkr_d_nth_word(buf, sizeof buf, v); tkr_d_add(&l, "the %s", buf); }
477 }
478 2 ▶ sv_catpvf(out, "on day%s ", l.n == 1 ? "" : "s");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, "on day%s ", l.n == 1 ? "" : "s"); 0 2 2
479 2 tkr_d_join(aTHX_ out, &l, " and ");
480 2 sv_catpvs(out, " of the year");
481 }
482 87 ▶ if (r->n_weekno) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->n_weekno) { 2 85 87
483 tkr_d_list l;
484 2 ▶ if (SvCUR(out) > at) sv_catpvs(out, ", ");
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(out) > at) sv_catpvs(out, ", "); 2 0 2
485 2 l.n = 0;
486 4 ▶ for (i = 0; i < r->n_weekno; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < r->n_weekno; i++) 2 2 4
487 2 tkr_d_add(&l, "%d", (int)r->by_weekno[i]);
488 2 ▶ sv_catpvf(out, "in week%s ", l.n == 1 ? "" : "s");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, "in week%s ", l.n == 1 ? "" : "s"); 2 0 2
489 2 tkr_d_join(aTHX_ out, &l, " and ");
490 2 sv_catpvs(out, " of the year");
491 }
492 87 ▶ if (r->n_setpos && r->by_monthday) {
Branch: 2 branches
BranchTrueFalseTotal
if (r->n_setpos && r->by_monthday) { 0 87 87
if (r->n_setpos && r->by_monthday) { 0 0 0
493 tkr_d_list l;
494 char buf[TKR_D_ITEM];
495 0 l.n = 0;
496 0 ▶ for (i = 0; i < r->n_setpos; i++) { tkr_d_nth_word(buf, sizeof buf, r->by_setpos[i]); tkr_d_add(&l, "%s", buf); }
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < r->n_setpos; i++) { tkr_d_nth_word(buf, sizeof buf, r->by_setpos[i]); tkr_d_add(&l, "%s", buf); } 0 0 0
497 0 sv_catpvs(out, ", only the ");
498 0 tkr_d_join(aTHX_ out, &l, " and ");
499 0 sv_catpvs(out, " of these");
500 }
501 87 return SvCUR(out) > at;
502 }
503  
504 /* ---- the whole --------------------------------------------------------------- */
505  
506 static void
507 98 tkr_d_end(pTHX_ SV *out, const tkr_rule *r)
508 {
509 98 ▶ if (r->count) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->count) { 23 75 98
510 23 ▶ sv_catpvf(out, r->count == 1 ? ", once" : ", %" IVdf " times", (IV)r->count);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, r->count == 1 ? ", once" : ", %" IVdf " times", (IV)r->count); 1 22 23
511 23 return;
512 }
513 75 ▶ if (r->until_kind != TKR_UNTIL_NONE) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->until_kind != TKR_UNTIL_NONE) { 10 65 75
514 10 ▶ 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); 10 0 10
515 10 int64_t rem = r->until_sec - days * 86400, y;
516 unsigned mo, d;
517 10 tkr_civil_from_days(days, &y, &mo, &d);
518 10 sv_catpvf(out, ", until %04" IVdf "-%02u-%02u", (IV)y, mo, d);
519 10 ▶ if (r->until_kind != TKR_UNTIL_DATE)
Branch: 1 branch
BranchTrueFalseTotal
if (r->until_kind != TKR_UNTIL_DATE) 10 0 10
520 10 ▶ sv_catpvf(out, " %02d:%02d%s", (int)(rem / 3600), (int)(rem % 3600 / 60), r->until_kind == TKR_UNTIL_UTC ? " UTC" : "");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, " %02d:%02d%s", (int)(rem / 3600), (int)(rem % 3600 / 60), r->until_kind == TKR_UNTIL_UTC ? " UTC" : ""); 10 0 10
521 }
522 }
523  
524 static void
525 98 tkr_d_calendar(pTHX_ SV *out, const tkr_rule *r)
526 {
527 98 const char *id = NULL;
528 98 ▶ if (!(r->flags & TKR_F_RSCALE))
Branch: 1 branch
BranchTrueFalseTotal
if (!(r->flags & TKR_F_RSCALE)) 97 1 98
529 97 return;
530 1 ▶ 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) 1 0 1
if (r->calendar == 0 || (tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id) 1 0 1
if (r->calendar == 0 || (tkr_tk(aTHX)->calendar_id)(r->calendar, &id) != TIME_KEEPER_OK || !id) 0 1 1
531 0 id = "gregorian";
532 1 ▶ sv_catpvf(out, ", in the %c%s calendar", toUPPER(*id), id + 1);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(out, ", in the %c%s calendar", toUPPER(*id), id + 1); 1 0 1
533 }
534  
535 static void
536 98 tkr_describe(pTHX_ const tkr_rule *r, SV *out)
537 {
538 98 SV *days = sv_2mortal(newSVpvs(""));
539 98 SV *time = sv_2mortal(newSVpvs(""));
540 98 int has_days, has_time, monthly = 0;
541 98 unsigned n = r->interval;
542  
543 98 sv_setpvs(out, "");
544 98 ▶ if (r->flags & TKR_F_EVERY) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->flags & TKR_F_EVERY) { 2 96 98
545 2 int64_t s = r->every_sec;
546 2 ▶ if (s % 86400 == 0) sv_catpvf(out, "every %" IVdf " day%s", (IV)(s / 86400), s == 86400 ? "" : "s");
Branch: 2 branches
BranchTrueFalseTotal
if (s % 86400 == 0) sv_catpvf(out, "every %" IVdf " day%s", (IV)(s / 86400), s == 86400 ? "" : "s"); 0 2 2
if (s % 86400 == 0) sv_catpvf(out, "every %" IVdf " day%s", (IV)(s / 86400), s == 86400 ? "" : "s"); 0 0 0
547 2 ▶ else if (s % 3600 == 0) sv_catpvf(out, "every %" IVdf " hour%s", (IV)(s / 3600), s == 3600 ? "" : "s");
Branch: 2 branches
BranchTrueFalseTotal
else if (s % 3600 == 0) sv_catpvf(out, "every %" IVdf " hour%s", (IV)(s / 3600), s == 3600 ? "" : "s"); 1 1 2
else if (s % 3600 == 0) sv_catpvf(out, "every %" IVdf " hour%s", (IV)(s / 3600), s == 3600 ? "" : "s"); 0 1 1
548 1 ▶ else if (s % 60 == 0) sv_catpvf(out, "every %" IVdf " minute%s", (IV)(s / 60), s == 60 ? "" : "s");
Branch: 2 branches
BranchTrueFalseTotal
else if (s % 60 == 0) sv_catpvf(out, "every %" IVdf " minute%s", (IV)(s / 60), s == 60 ? "" : "s"); 1 0 1
else if (s % 60 == 0) sv_catpvf(out, "every %" IVdf " minute%s", (IV)(s / 60), s == 60 ? "" : "s"); 0 1 1
549 0 ▶ else sv_catpvf(out, "every %" IVdf " second%s", (IV)s, s == 1 ? "" : "s");
Branch: 1 branch
BranchTrueFalseTotal
else sv_catpvf(out, "every %" IVdf " second%s", (IV)s, s == 1 ? "" : "s"); 0 0 0
550 2 sv_catpvs(out, ", counted from the last run");
551 2 goto done;
552 }
553 96 has_time = tkr_d_time(aTHX_ time, r);
554 96 has_days = tkr_d_days(aTHX_ days, r, &monthly);
555  
556 96 switch (r->freq) {
557 17 case TKR_YEARLY:
558 17 ▶ if (has_days && monthly && !r->by_month && tkr_has_by_day_ordinal(r) && !r->by_monthday) {
Branch: 5 branches
BranchTrueFalseTotal
if (has_days && monthly && !r->by_month && tkr_has_by_day_ordinal(r) && !r->by_monthday) { 13 4 17
if (has_days && monthly && !r->by_month && tkr_has_by_day_ordinal(r) && !r->by_monthday) { 4 9 13
if (has_days && monthly && !r->by_month && tkr_has_by_day_ordinal(r) && !r->by_monthday) { 2 2 4
if (has_days && monthly && !r->by_month && tkr_has_by_day_ordinal(r) && !r->by_monthday) { 2 0 2
if (has_days && monthly && !r->by_month && tkr_has_by_day_ordinal(r) && !r->by_monthday) { 2 0 2
559 2 sv_catsv(out, days); /* "on the 20th Monday of every year" */
560 2 sv_catpvs(out, " of ");
561 2 tkr_d_every(aTHX_ out, n, "year", "years");
562 2 break;
563 }
564 15 ▶ if (has_days) {
Branch: 1 branch
BranchTrueFalseTotal
if (has_days) { 11 4 15
565 11 sv_catsv(out, days);
566 11 ▶ if (r->by_month) {
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_month) { 7 4 11
567 7 ▶ if (monthly) { sv_catpvs(out, " of "); tkr_d_months(aTHX_ out, r, 0); }
Branch: 1 branch
BranchTrueFalseTotal
if (monthly) { sv_catpvs(out, " of "); tkr_d_months(aTHX_ out, r, 0); } 2 5 7
568 5 ▶ else { sv_catpv(out, strEQ(SvPVX(days), "every day") ? " " : ", "); tkr_d_months(aTHX_ out, r, 1); }
Branch: 1 branch
BranchTrueFalseTotal
else { sv_catpv(out, strEQ(SvPVX(days), "every day") ? " " : ", "); tkr_d_months(aTHX_ out, r, 1); } 1 4 5
569 }
570 }
571 4 ▶ else if (r->by_month) tkr_d_months(aTHX_ out, r, 1);
Branch: 1 branch
BranchTrueFalseTotal
else if (r->by_month) tkr_d_months(aTHX_ out, r, 1); 3 1 4
572 15 ▶ if (SvCUR(out)) sv_catpvs(out, ", ");
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(out)) sv_catpvs(out, ", "); 14 1 15
573 15 tkr_d_every(aTHX_ out, n, "year", "years");
574 15 break;
575 23 case TKR_MONTHLY:
576 23 ▶ if (has_days) { sv_catsv(out, days); sv_catpv(out, monthly ? " of " : ", "); }
Branch: 2 branches
BranchTrueFalseTotal
if (has_days) { sv_catsv(out, days); sv_catpv(out, monthly ? " of " : ", "); } 22 1 23
if (has_days) { sv_catsv(out, days); sv_catpv(out, monthly ? " of " : ", "); } 18 4 22
577 23 tkr_d_every(aTHX_ out, n, "month", "months");
578 23 ▶ if (r->by_month) { sv_catpvs(out, ", "); tkr_d_months(aTHX_ out, r, 1); }
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_month) { sv_catpvs(out, ", "); tkr_d_months(aTHX_ out, r, 1); } 0 23 23
579 23 break;
580 12 case TKR_WEEKLY:
581 12 ▶ if (n == 1 && r->by_day_any && !monthly && !r->n_setpos && !tkr_has_by_day_ordinal(r)) {
Branch: 5 branches
BranchTrueFalseTotal
if (n == 1 && r->by_day_any && !monthly && !r->n_setpos && !tkr_has_by_day_ordinal(r)) { 6 6 12
if (n == 1 && r->by_day_any && !monthly && !r->n_setpos && !tkr_has_by_day_ordinal(r)) { 4 2 6
if (n == 1 && r->by_day_any && !monthly && !r->n_setpos && !tkr_has_by_day_ordinal(r)) { 4 0 4
if (n == 1 && r->by_day_any && !monthly && !r->n_setpos && !tkr_has_by_day_ordinal(r)) { 4 0 4
if (n == 1 && r->by_day_any && !monthly && !r->n_setpos && !tkr_has_by_day_ordinal(r)) { 4 0 4
582 4 sv_catpvs(out, "every ");
583 4 tkr_d_weekdays(aTHX_ out, r->by_day_any);
584 }
585 else {
586 8 tkr_d_every(aTHX_ out, n, "week", "weeks");
587 8 ▶ if (has_days) { sv_catpvs(out, " "); sv_catsv(out, days); }
Branch: 1 branch
BranchTrueFalseTotal
if (has_days) { sv_catpvs(out, " "); sv_catsv(out, days); } 5 3 8
588 }
589 12 ▶ if (r->by_month) { sv_catpvs(out, ", "); tkr_d_months(aTHX_ out, r, 1); }
Branch: 1 branch
BranchTrueFalseTotal
if (r->by_month) { sv_catpvs(out, ", "); tkr_d_months(aTHX_ out, r, 1); } 0 12 12
590 12 break;
591 11 case TKR_DAILY:
592 11 ▶ if (n != 1 || !has_days) tkr_d_every(aTHX_ out, n, "day", "days");
Branch: 2 branches
BranchTrueFalseTotal
if (n != 1 || !has_days) tkr_d_every(aTHX_ out, n, "day", "days"); 7 4 11
if (n != 1 || !has_days) tkr_d_every(aTHX_ out, n, "day", "days"); 7 0 7
593 11 ▶ if (has_days) { if (SvCUR(out)) sv_catpvs(out, ", "); sv_catsv(out, days); }
Branch: 2 branches
BranchTrueFalseTotal
if (has_days) { if (SvCUR(out)) sv_catpvs(out, ", "); sv_catsv(out, days); } 0 11 11
if (has_days) { if (SvCUR(out)) sv_catpvs(out, ", "); sv_catsv(out, days); } 0 0 0
594 11 ▶ if (monthly && r->by_month) { sv_catpvs(out, " of "); tkr_d_months(aTHX_ out, r, 0); }
Branch: 2 branches
BranchTrueFalseTotal
if (monthly && r->by_month) { sv_catpvs(out, " of "); tkr_d_months(aTHX_ out, r, 0); } 0 11 11
if (monthly && r->by_month) { sv_catpvs(out, " of "); tkr_d_months(aTHX_ out, r, 0); } 0 0 0
595 else {
596 11 ▶ if (monthly) sv_catpvs(out, " of the month");
Branch: 1 branch
BranchTrueFalseTotal
if (monthly) sv_catpvs(out, " of the month"); 0 11 11
597 11 ▶ if (r->by_month) { sv_catpv(out, has_days ? ", " : " "); tkr_d_months(aTHX_ out, r, 1); }
Branch: 2 branches
BranchTrueFalseTotal
if (r->by_month) { sv_catpv(out, has_days ? ", " : " "); tkr_d_months(aTHX_ out, r, 1); } 2 9 11
if (r->by_month) { sv_catpv(out, has_days ? ", " : " "); tkr_d_months(aTHX_ out, r, 1); } 0 2 2
598 }
599 11 break;
600 33 default: /* hourly and finer: the time says the cycle */
601 33 ▶ if (has_days) sv_catsv(out, days);
Branch: 1 branch
BranchTrueFalseTotal
if (has_days) sv_catsv(out, days); 10 23 33
602 33 ▶ if (monthly && r->by_month) { sv_catpvs(out, " of "); tkr_d_months(aTHX_ out, r, 0); }
Branch: 2 branches
BranchTrueFalseTotal
if (monthly && r->by_month) { sv_catpvs(out, " of "); tkr_d_months(aTHX_ out, r, 0); } 3 30 33
if (monthly && r->by_month) { sv_catpvs(out, " of "); tkr_d_months(aTHX_ out, r, 0); } 1 2 3
603 else {
604 32 ▶ if (monthly) sv_catpvs(out, " of the month");
Branch: 1 branch
BranchTrueFalseTotal
if (monthly) sv_catpvs(out, " of the month"); 2 30 32
605 32 ▶ if (r->by_month) { if (SvCUR(out)) sv_catpvs(out, ", "); tkr_d_months(aTHX_ out, r, 1); }
Branch: 2 branches
BranchTrueFalseTotal
if (r->by_month) { if (SvCUR(out)) sv_catpvs(out, ", "); tkr_d_months(aTHX_ out, r, 1); } 1 31 32
if (r->by_month) { if (SvCUR(out)) sv_catpvs(out, ", "); tkr_d_months(aTHX_ out, r, 1); } 0 1 1
606 }
607 33 break;
608 }
609 96 ▶ if (has_time) { /* the time first: "At 09:00, Monday to Friday" */
Branch: 1 branch
BranchTrueFalseTotal
if (has_time) { /* the time first: "At 09:00, Monday to Friday" */ 59 37 96
610 37 ▶ if (SvCUR(out)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(out)) { 15 22 37
611 15 SV *rest = sv_2mortal(newSVsv(out));
612 15 sv_setsv(out, time);
613 /* "At 09:30 every day", "At 09:00 every Monday to Friday"; else a comma */
614 15 ▶ sv_catpv(out, strnEQ(SvPVX(rest), "every ", 6) ? " " : ", ");
Branch: 1 branch
BranchTrueFalseTotal
sv_catpv(out, strnEQ(SvPVX(rest), "every ", 6) ? " " : ", "); 3 12 15
615 15 sv_catsv(out, rest);
616 }
617 else {
618 22 sv_setsv(out, time);
619 22 ▶ if (r->freq < TKR_DAILY && r->by_hour && r->by_minute && tkr_d_bits(r->by_hour) * tkr_d_bits(r->by_minute) <= 6)
Branch: 4 branches
BranchTrueFalseTotal
if (r->freq < TKR_DAILY && r->by_hour && r->by_minute && tkr_d_bits(r->by_hour) * tkr_d_bits(r->by_minute) <= 6) 0 22 22
if (r->freq < TKR_DAILY && r->by_hour && r->by_minute && tkr_d_bits(r->by_hour) * tkr_d_bits(r->by_minute) <= 6) 11 11 22
if (r->freq < TKR_DAILY && r->by_hour && r->by_minute && tkr_d_bits(r->by_hour) * tkr_d_bits(r->by_minute) <= 6) 2 9 11
if (r->freq < TKR_DAILY && r->by_hour && r->by_minute && tkr_d_bits(r->by_hour) * tkr_d_bits(r->by_minute) <= 6) 4 5 9
620 5 sv_catpvs(out, " every day");
621 }
622 }
623 76 done:
624 98 tkr_d_end(aTHX_ out, r);
625 98 tkr_d_calendar(aTHX_ out, r);
626 98 ▶ if (SvCUR(out))
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(out)) 98 0 98
627 98 ▶ SvPVX(out)[0] = toUPPER(SvPVX(out)[0]);
Branch: 1 branch
BranchTrueFalseTotal
SvPVX(out)[0] = toUPPER(SvPVX(out)[0]); 98 0 98
628 98 }
629  
630 #endif
« include/tkr/tkr_abi_impl.h ↑ Summary xs/set.xs »