| 1 |
|
| #ifndef TKR_OBJ_H |
| 2 |
|
| #define TKR_OBJ_H |
| 3 |
|
| |
| 4 |
|
| /* A rule object: a blessed reference to a scalar holding one tkr_rule, as a |
| 5 |
|
| * Time::Keeper value holds its struct. Never read-only (a serialiser that |
| 6 |
|
| * re-blesses before FREEZE cannot bless a read-only referent), never |
| 7 |
|
| * changed after it is made: every method that would change one returns a |
| 8 |
|
| * new one. */ |
| 9 |
|
| |
| 10 |
|
| static SV * |
| 11 |
2857 |
| tkr_rule_new_sv(pTHX_ HV *stash, const tkr_rule *r) |
| 12 |
|
| { |
| 13 |
2857 |
| SV *body = newSVpvn((const char *)r, sizeof *r); |
| 14 |
2857 |
| SV *rv = newRV_noinc(body); |
| 15 |
2857 |
| sv_bless(rv, stash); |
| 16 |
2857 |
| return rv; |
| 17 |
|
| } |
| 18 |
|
| |
| 19 |
|
| static tkr_rule * |
| 20 |
14631 |
| tkr_rule_of(pTHX_ SV *sv, const char *what) |
| 21 |
|
| { |
| 22 |
14631 |
▶ | if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Time::Keeper::Recurrence") || !SvPOK(SvRV(sv)) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Time::Keeper::Recurrence") || !SvPOK(SvRV(sv)) |
14631 |
0 |
14631 |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Time::Keeper::Recurrence") || !SvPOK(SvRV(sv)) |
14630 |
1 |
14631 |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Time::Keeper::Recurrence") || !SvPOK(SvRV(sv)) |
14630 |
0 |
14630 |
| if (!sv || !SvROK(sv) || !sv_derived_from(sv, "Time::Keeper::Recurrence") || !SvPOK(SvRV(sv)) |
14630 |
0 |
14630 |
|
| 23 |
14630 |
▶ | || SvCUR(SvRV(sv)) != sizeof(tkr_rule)) |
Branch: 1 branch
| Branch | True | False | Total |
| || SvCUR(SvRV(sv)) != sizeof(tkr_rule)) |
0 |
14630 |
14630 |
|
| 24 |
1 |
| croak("%s: not a Time::Keeper::Recurrence", what); |
| 25 |
14630 |
| return (tkr_rule *)SvPVX(SvRV(sv)); |
| 26 |
|
| } |
| 27 |
|
| |
| 28 |
|
| /* ---- the arguments the doors take ---------------------------------------- */ |
| 29 |
|
| |
| 30 |
|
| typedef struct tkr_opts { |
| 31 |
|
| SV *rrule, *start, *zone, *gap, *overlap, *on, *at, *until, *count, *calendar; |
| 32 |
|
| } tkr_opts; |
| 33 |
|
| |
| 34 |
|
| static void |
| 35 |
2876 |
| tkr_opts_parse(pTHX_ SV **st, I32 n, tkr_opts *o, const char *allowed, const char *what) |
| 36 |
|
| { |
| 37 |
|
| I32 i; |
| 38 |
2876 |
| memset(o, 0, sizeof *o); |
| 39 |
2876 |
▶ | if (n % 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (n % 2) |
1 |
2875 |
2876 |
|
| 40 |
1 |
| croak("%s: the arguments are key and value pairs", what); |
| 41 |
8028 |
▶ | for (i = 0; i < n; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i += 2) { |
5156 |
2872 |
8028 |
|
| 42 |
|
| STRLEN len; |
| 43 |
5156 |
| const char *k = SvPV(st[i], len); |
| 44 |
5156 |
| SV **slot = NULL; |
| 45 |
|
| char tag; |
| 46 |
5156 |
▶ | if (strEQ(k, "rrule")) { slot = &o->rrule; tag = 'r'; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(k, "rrule")) { slot = &o->rrule; tag = 'r'; } |
2397 |
2759 |
5156 |
|
| 47 |
2759 |
▶ | else if (strEQ(k, "start")) { slot = &o->start; tag = 's'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "start")) { slot = &o->start; tag = 's'; } |
2435 |
324 |
2759 |
|
| 48 |
324 |
▶ | else if (strEQ(k, "zone")) { slot = &o->zone; tag = 'z'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "zone")) { slot = &o->zone; tag = 'z'; } |
267 |
57 |
324 |
|
| 49 |
57 |
▶ | else if (strEQ(k, "gap")) { slot = &o->gap; tag = 'g'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "gap")) { slot = &o->gap; tag = 'g'; } |
13 |
44 |
57 |
|
| 50 |
44 |
▶ | else if (strEQ(k, "overlap")) { slot = &o->overlap; tag = 'o'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "overlap")) { slot = &o->overlap; tag = 'o'; } |
11 |
33 |
44 |
|
| 51 |
33 |
▶ | else if (strEQ(k, "on")) { slot = &o->on; tag = 'n'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "on")) { slot = &o->on; tag = 'n'; } |
12 |
21 |
33 |
|
| 52 |
21 |
▶ | else if (strEQ(k, "at")) { slot = &o->at; tag = 'a'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "at")) { slot = &o->at; tag = 'a'; } |
5 |
16 |
21 |
|
| 53 |
16 |
▶ | else if (strEQ(k, "until")) { slot = &o->until; tag = 'u'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "until")) { slot = &o->until; tag = 'u'; } |
6 |
10 |
16 |
|
| 54 |
10 |
▶ | else if (strEQ(k, "count")) { slot = &o->count; tag = 'c'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "count")) { slot = &o->count; tag = 'c'; } |
3 |
7 |
10 |
|
| 55 |
7 |
▶ | else if (strEQ(k, "calendar")) { slot = &o->calendar; tag = 'C'; } |
Branch: 1 branch
| Branch | True | False | Total |
| else if (strEQ(k, "calendar")) { slot = &o->calendar; tag = 'C'; } |
6 |
1 |
7 |
|
| 56 |
1 |
| else croak("%s: unknown argument '%s'", what, k); |
| 57 |
5155 |
▶ | if (!strchr(allowed, tag)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!strchr(allowed, tag)) |
2 |
5153 |
5155 |
|
| 58 |
2 |
| croak("%s: '%s' is not an argument here", what, k); |
| 59 |
5153 |
▶ | if (*slot) |
Branch: 1 branch
| Branch | True | False | Total |
| if (*slot) |
0 |
5153 |
5153 |
|
| 60 |
0 |
| croak("%s: '%s' is given twice", what, k); |
| 61 |
5153 |
| *slot = st[i + 1]; |
| 62 |
|
| } |
| 63 |
2872 |
| } |
| 64 |
|
| |
| 65 |
|
| /* The start: a Time::Keeper value's instant, zone and locale. */ |
| 66 |
|
| static void |
| 67 |
2431 |
| tkr_start_from_sv(pTHX_ SV *sv, tkr_rule *r, const char *what) |
| 68 |
|
| { |
| 69 |
2431 |
| const time_keeper_abi *T = tkr_tk(aTHX); |
| 70 |
2431 |
▶ | if ((T->from_sv)(aTHX_ sv, &r->start, &r->zone, &r->locale) != TIME_KEEPER_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((T->from_sv)(aTHX_ sv, &r->start, &r->zone, &r->locale) != TIME_KEEPER_OK) |
1 |
2430 |
2431 |
|
| 71 |
1 |
| croak("%s: start is not a Time::Keeper value", what); |
| 72 |
2430 |
| r->flags |= TKR_F_HAS_START; |
| 73 |
2430 |
| } |
| 74 |
|
| |
| 75 |
|
| static void |
| 76 |
266 |
| tkr_zone_from_sv(pTHX_ SV *sv, tkr_rule *r, const char *what) |
| 77 |
|
| { |
| 78 |
266 |
| const time_keeper_abi *T = tkr_tk(aTHX); |
| 79 |
|
| STRLEN len; |
| 80 |
266 |
| const char *s = SvPV(sv, len); |
| 81 |
266 |
▶ | if ((T->zone_parse)(aTHX_ s, len, &r->zone) != TIME_KEEPER_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((T->zone_parse)(aTHX_ s, len, &r->zone) != TIME_KEEPER_OK) |
1 |
265 |
266 |
|
| 82 |
1 |
| croak("%s: '%s' is not a time zone", what, s); |
| 83 |
265 |
| } |
| 84 |
|
| |
| 85 |
|
| static void |
| 86 |
2786 |
| tkr_gap_overlap(pTHX_ const tkr_opts *o, tkr_rule *r, const char *what) |
| 87 |
|
| { |
| 88 |
|
| int i; |
| 89 |
2786 |
▶ | if (o->gap) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->gap) { |
13 |
2773 |
2786 |
|
| 90 |
13 |
| const char *s = SvPV_nolen(o->gap); |
| 91 |
37 |
▶ | for (i = 0; i < 4; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < 4; i++) |
36 |
1 |
37 |
|
| 92 |
36 |
▶ | if (strEQ(s, tkr_gap_names[i])) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(s, tkr_gap_names[i])) |
12 |
24 |
36 |
|
| 93 |
12 |
| break; |
| 94 |
13 |
▶ | if (i == 4) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i == 4) |
1 |
12 |
13 |
|
| 95 |
1 |
| croak("%s: gap is forward, backward, skip or fail, not '%s'", what, s); |
| 96 |
12 |
| r->gap = (uint8_t)i; |
| 97 |
|
| } |
| 98 |
2785 |
▶ | if (o->overlap) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->overlap) { |
11 |
2774 |
2785 |
|
| 99 |
11 |
| const char *s = SvPV_nolen(o->overlap); |
| 100 |
26 |
▶ | for (i = 0; i < 3; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < 3; i++) |
25 |
1 |
26 |
|
| 101 |
25 |
▶ | if (strEQ(s, tkr_overlap_names[i])) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(s, tkr_overlap_names[i])) |
10 |
15 |
25 |
|
| 102 |
10 |
| break; |
| 103 |
11 |
▶ | if (i == 3) |
Branch: 1 branch
| Branch | True | False | Total |
| if (i == 3) |
1 |
10 |
11 |
|
| 104 |
1 |
| croak("%s: overlap is earlier, later or both, not '%s'", what, s); |
| 105 |
10 |
| r->overlap = (uint8_t)i; |
| 106 |
|
| } |
| 107 |
2784 |
| } |
| 108 |
|
| |
| 109 |
|
| /* UNTIL's form against the start's: a zoned start takes UNTIL in UTC, a |
| 110 |
|
| * floating start a floating UNTIL; a DATE suits either. */ |
| 111 |
|
| static void |
| 112 |
2368 |
| tkr_check_until_form(pTHX_ const tkr_rule *r, const char *what) |
| 113 |
|
| { |
| 114 |
2368 |
▶ | if (r->until_kind == TKR_UNTIL_FLOATING && r->zone.kind != TIME_KEEPER_ZONE_FLOATING) |
Branch: 2 branches
| Branch | True | False | Total |
| if (r->until_kind == TKR_UNTIL_FLOATING && r->zone.kind != TIME_KEEPER_ZONE_FLOATING) |
5 |
2363 |
2368 |
| if (r->until_kind == TKR_UNTIL_FLOATING && r->zone.kind != TIME_KEEPER_ZONE_FLOATING) |
2 |
3 |
5 |
|
| 115 |
2 |
| croak("%s: UNTIL must be in UTC (end in Z) when the start has a zone", what); |
| 116 |
2366 |
▶ | if (r->until_kind == TKR_UNTIL_UTC && r->zone.kind == TIME_KEEPER_ZONE_FLOATING) |
Branch: 2 branches
| Branch | True | False | Total |
| if (r->until_kind == TKR_UNTIL_UTC && r->zone.kind == TIME_KEEPER_ZONE_FLOATING) |
52 |
2314 |
2366 |
| if (r->until_kind == TKR_UNTIL_UTC && r->zone.kind == TIME_KEEPER_ZONE_FLOATING) |
1 |
51 |
52 |
|
| 117 |
1 |
| croak("%s: UNTIL must be floating (no Z) when the start is", what); |
| 118 |
2365 |
| } |
| 119 |
|
| |
| 120 |
|
| /* calendar => a Time::Keeper calendar id: the rule walks in it (RSCALE). */ |
| 121 |
|
| static void |
| 122 |
5 |
| tkr_calendar_opt(pTHX_ SV *sv, tkr_rule *r, const char *what) |
| 123 |
|
| { |
| 124 |
|
| STRLEN len; |
| 125 |
5 |
| const char *s = SvPV(sv, len); |
| 126 |
5 |
| int c = (tkr_tk(aTHX)->calendar_find)(s, len); |
| 127 |
5 |
▶ | if (c < 0 || c > 255) |
Branch: 2 branches
| Branch | True | False | Total |
| if (c < 0 || c > 255) |
4 |
1 |
5 |
| if (c < 0 || c > 255) |
0 |
4 |
4 |
|
| 128 |
1 |
| croak("%s: calendar => '%s' names no calendar Time::Keeper knows", what, s); |
| 129 |
4 |
▶ | if (r->n_weekno) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r->n_weekno) |
0 |
4 |
4 |
|
| 130 |
0 |
| croak("%s: BYWEEKNO cannot be given with a calendar: no calendar here numbers weeks but the Gregorian", what); |
| 131 |
4 |
| r->calendar = (uint8_t)c; |
| 132 |
4 |
| r->flags |= TKR_F_RSCALE; |
| 133 |
4 |
| } |
| 134 |
|
| |
| 135 |
|
| /* The named door: n units, on, at. */ |
| 136 |
|
| static void |
| 137 |
33 |
| tkr_every_build(pTHX_ IV n, const char *unit, const tkr_opts *o, tkr_rule *r, const char *what) |
| 138 |
|
| { |
| 139 |
|
| static const struct { const char *name; int freq; } units[] = { |
| 140 |
|
| { "seconds", TKR_SECONDLY }, { "second", TKR_SECONDLY }, { "minutes", TKR_MINUTELY }, { "minute", TKR_MINUTELY }, |
| 141 |
|
| { "hours", TKR_HOURLY }, { "hour", TKR_HOURLY }, { "days", TKR_DAILY }, { "day", TKR_DAILY }, |
| 142 |
|
| { "weeks", TKR_WEEKLY }, { "week", TKR_WEEKLY }, { "months", TKR_MONTHLY }, { "month", TKR_MONTHLY }, |
| 143 |
|
| { "years", TKR_YEARLY }, { "year", TKR_YEARLY }, |
| 144 |
|
| }; |
| 145 |
|
| unsigned k; |
| 146 |
309 |
▶ | for (k = 0; k < sizeof units / sizeof *units; k++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (k = 0; k < sizeof units / sizeof *units; k++) |
308 |
1 |
309 |
|
| 147 |
308 |
▶ | if (strEQ(unit, units[k].name)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (strEQ(unit, units[k].name)) |
32 |
276 |
308 |
|
| 148 |
32 |
| break; |
| 149 |
33 |
▶ | if (k == sizeof units / sizeof *units) |
Branch: 1 branch
| Branch | True | False | Total |
| if (k == sizeof units / sizeof *units) |
1 |
32 |
33 |
|
| 150 |
1 |
| croak("%s: the unit is seconds, minutes, hours, days, weeks, months or years, not '%s'", what, unit); |
| 151 |
32 |
▶ | if (n < 1 || n > 0x7fffffff) |
Branch: 2 branches
| Branch | True | False | Total |
| if (n < 1 || n > 0x7fffffff) |
31 |
1 |
32 |
| if (n < 1 || n > 0x7fffffff) |
0 |
31 |
31 |
|
| 152 |
1 |
| croak("%s: every how many? %" IVdf " is not a count above zero", what, n); |
| 153 |
31 |
| r->freq = (uint8_t)units[k].freq; |
| 154 |
31 |
| r->interval = (uint32_t)n; |
| 155 |
31 |
▶ | if (o->on) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->on) { |
12 |
19 |
31 |
|
| 156 |
12 |
| AV *list = NULL; |
| 157 |
|
| I32 i, top; |
| 158 |
12 |
▶ | if (SvROK(o->on) && SvTYPE(SvRV(o->on)) == SVt_PVAV) |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvROK(o->on) && SvTYPE(SvRV(o->on)) == SVt_PVAV) |
4 |
8 |
12 |
| if (SvROK(o->on) && SvTYPE(SvRV(o->on)) == SVt_PVAV) |
4 |
0 |
4 |
|
| 159 |
4 |
| list = (AV *)SvRV(o->on); |
| 160 |
12 |
▶ | top = list ? av_len(list) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| top = list ? av_len(list) : 0; |
4 |
8 |
12 |
|
| 161 |
25 |
▶ | for (i = 0; i <= top; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= top; i++) { |
17 |
8 |
25 |
|
| 162 |
17 |
▶ | SV **e = list ? av_fetch(list, i, 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **e = list ? av_fetch(list, i, 0) : NULL; |
9 |
8 |
17 |
|
| 163 |
17 |
▶ | SV *item = list ? (e ? *e : &PL_sv_undef) : o->on; |
Branch: 2 branches
| Branch | True | False | Total |
| SV *item = list ? (e ? *e : &PL_sv_undef) : o->on; |
9 |
8 |
17 |
| SV *item = list ? (e ? *e : &PL_sv_undef) : o->on; |
9 |
0 |
9 |
|
| 164 |
|
| STRLEN len; |
| 165 |
17 |
| const char *s = SvPV(item, len), *p = s, *end = s + len; |
| 166 |
17 |
| int ord = 0, oneg = 0, w = -1, num; |
| 167 |
|
| long v; |
| 168 |
17 |
▶ | if (looks_like_number(item)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (looks_like_number(item)) { |
5 |
12 |
17 |
|
| 169 |
5 |
| v = SvIV(item); |
| 170 |
5 |
▶ | if (v == 0 || v > 31 || v < -31) |
Branch: 3 branches
| Branch | True | False | Total |
| if (v == 0 || v > 31 || v < -31) |
5 |
0 |
5 |
| if (v == 0 || v > 31 || v < -31) |
4 |
1 |
5 |
| if (v == 0 || v > 31 || v < -31) |
0 |
4 |
4 |
|
| 171 |
1 |
| croak("%s: on => %ld is not a day of the month, 1 to 31 or -1 to -31", what, v); |
| 172 |
4 |
▶ | if (r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY) |
Branch: 2 branches
| Branch | True | False | Total |
| if (r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY) |
1 |
3 |
4 |
| if (r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY) |
1 |
0 |
1 |
|
| 173 |
1 |
| croak("%s: on => a day of the month needs months or years", what); |
| 174 |
3 |
▶ | r->by_monthday |= UINT64_C(1) << (v < 0 ? 32 - v : v); |
Branch: 1 branch
| Branch | True | False | Total |
| r->by_monthday |= UINT64_C(1) << (v < 0 ? 32 - v : v); |
1 |
2 |
3 |
|
| 175 |
3 |
| continue; |
| 176 |
|
| } |
| 177 |
12 |
▶ | while (p < end && isSPACE(*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isSPACE(*p)) p++; |
12 |
0 |
12 |
| while (p < end && isSPACE(*p)) p++; |
0 |
12 |
12 |
|
| 178 |
12 |
▶ | if (end - p >= 4 && tkr_ieq(p, "last", 4)) { ord = 1; oneg = 1; p += 4; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (end - p >= 4 && tkr_ieq(p, "last", 4)) { ord = 1; oneg = 1; p += 4; } |
8 |
4 |
12 |
| if (end - p >= 4 && tkr_ieq(p, "last", 4)) { ord = 1; oneg = 1; p += 4; } |
3 |
5 |
8 |
|
| 179 |
9 |
▶ | else if (p < end && isDIGIT(*p)) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (p < end && isDIGIT(*p)) { |
9 |
0 |
9 |
| else if (p < end && isDIGIT(*p)) { |
2 |
7 |
9 |
|
| 180 |
4 |
▶ | while (p < end && isDIGIT(*p)) ord = ord * 10 + (*p++ - '0'); |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isDIGIT(*p)) ord = ord * 10 + (*p++ - '0'); |
4 |
0 |
4 |
| while (p < end && isDIGIT(*p)) ord = ord * 10 + (*p++ - '0'); |
2 |
2 |
4 |
|
| 181 |
2 |
▶ | if (end - p >= 2 && (tkr_ieq(p, "st", 2) || tkr_ieq(p, "nd", 2) || tkr_ieq(p, "rd", 2) || tkr_ieq(p, "th", 2))) |
Branch: 5 branches
| Branch | True | False | Total |
| if (end - p >= 2 && (tkr_ieq(p, "st", 2) || tkr_ieq(p, "nd", 2) || tkr_ieq(p, "rd", 2) || tkr_ieq(p, "th", 2))) |
2 |
0 |
2 |
| if (end - p >= 2 && (tkr_ieq(p, "st", 2) || tkr_ieq(p, "nd", 2) || tkr_ieq(p, "rd", 2) || tkr_ieq(p, "th", 2))) |
1 |
1 |
2 |
| if (end - p >= 2 && (tkr_ieq(p, "st", 2) || tkr_ieq(p, "nd", 2) || tkr_ieq(p, "rd", 2) || tkr_ieq(p, "th", 2))) |
1 |
0 |
1 |
| if (end - p >= 2 && (tkr_ieq(p, "st", 2) || tkr_ieq(p, "nd", 2) || tkr_ieq(p, "rd", 2) || tkr_ieq(p, "th", 2))) |
0 |
1 |
1 |
| if (end - p >= 2 && (tkr_ieq(p, "st", 2) || tkr_ieq(p, "nd", 2) || tkr_ieq(p, "rd", 2) || tkr_ieq(p, "th", 2))) |
0 |
0 |
0 |
|
| 182 |
2 |
| p += 2; |
| 183 |
|
| } |
| 184 |
7 |
▶ | else if (p < end && *p == '-') { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (p < end && *p == '-') { |
7 |
0 |
7 |
| else if (p < end && *p == '-') { |
1 |
6 |
7 |
|
| 185 |
1 |
| p++; |
| 186 |
2 |
▶ | while (p < end && isDIGIT(*p)) ord = ord * 10 + (*p++ - '0'); |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isDIGIT(*p)) ord = ord * 10 + (*p++ - '0'); |
2 |
0 |
2 |
| while (p < end && isDIGIT(*p)) ord = ord * 10 + (*p++ - '0'); |
1 |
1 |
2 |
|
| 187 |
1 |
| oneg = 1; |
| 188 |
|
| } |
| 189 |
18 |
▶ | while (p < end && isSPACE(*p)) p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && isSPACE(*p)) p++; |
18 |
0 |
18 |
| while (p < end && isSPACE(*p)) p++; |
6 |
12 |
18 |
|
| 190 |
12 |
▶ | if (end - p >= 3) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (end - p >= 3) { |
12 |
0 |
12 |
|
| 191 |
50 |
▶ | for (num = 0; num < 7; num++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (num = 0; num < 7; num++) |
49 |
1 |
50 |
|
| 192 |
49 |
▶ | if (tkr_ieq(p, tkr_cron_days[num], 3)) { w = num == 0 ? 6 : num - 1; break; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (tkr_ieq(p, tkr_cron_days[num], 3)) { w = num == 0 ? 6 : num - 1; break; } |
11 |
38 |
49 |
| if (tkr_ieq(p, tkr_cron_days[num], 3)) { w = num == 0 ? 6 : num - 1; break; } |
10 |
1 |
11 |
|
| 193 |
|
| } |
| 194 |
12 |
▶ | if (w < 0 || (ord && (ord < 1 || ord > 53)) || (ord && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY)) |
Branch: 7 branches
| Branch | True | False | Total |
| if (w < 0 || (ord && (ord < 1 || ord > 53)) || (ord && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY)) |
11 |
1 |
12 |
| if (w < 0 || (ord && (ord < 1 || ord > 53)) || (ord && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY)) |
6 |
5 |
11 |
| if (w < 0 || (ord && (ord < 1 || ord > 53)) || (ord && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY)) |
6 |
0 |
6 |
| if (w < 0 || (ord && (ord < 1 || ord > 53)) || (ord && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY)) |
6 |
0 |
6 |
| if (w < 0 || (ord && (ord < 1 || ord > 53)) || (ord && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY)) |
6 |
5 |
11 |
| if (w < 0 || (ord && (ord < 1 || ord > 53)) || (ord && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY)) |
2 |
4 |
6 |
| if (w < 0 || (ord && (ord < 1 || ord > 53)) || (ord && r->freq != TKR_MONTHLY && r->freq != TKR_YEARLY)) |
1 |
1 |
2 |
|
| 195 |
2 |
| croak("%s: on => '%s' is not a weekday, with 1st to 5th or last before it for months or years", what, s); |
| 196 |
10 |
▶ | if (!ord) r->by_day_any |= (uint8_t)(1u << w); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ord) r->by_day_any |= (uint8_t)(1u << w); |
5 |
5 |
10 |
|
| 197 |
5 |
▶ | else if (oneg) r->by_day_neg[w] |= UINT64_C(1) << ord; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (oneg) r->by_day_neg[w] |= UINT64_C(1) << ord; |
3 |
2 |
5 |
|
| 198 |
2 |
| else r->by_day_pos[w] |= UINT64_C(1) << ord; |
| 199 |
|
| } |
| 200 |
|
| } |
| 201 |
27 |
▶ | if (o->at) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->at) { |
5 |
22 |
27 |
|
| 202 |
|
| STRLEN len; |
| 203 |
5 |
| const char *s = SvPV(o->at, len); |
| 204 |
5 |
| int h = -1, m = -1, sec = 0, got; |
| 205 |
5 |
▶ | got = len >= 5 && isDIGIT(s[0]) && isDIGIT(s[1]) && s[2] == ':' && isDIGIT(s[3]) && isDIGIT(s[4]); |
Branch: 6 branches
| Branch | True | False | Total |
| got = len >= 5 && isDIGIT(s[0]) && isDIGIT(s[1]) && s[2] == ':' && isDIGIT(s[3]) && isDIGIT(s[4]); |
4 |
1 |
5 |
| got = len >= 5 && isDIGIT(s[0]) && isDIGIT(s[1]) && s[2] == ':' && isDIGIT(s[3]) && isDIGIT(s[4]); |
4 |
0 |
4 |
| got = len >= 5 && isDIGIT(s[0]) && isDIGIT(s[1]) && s[2] == ':' && isDIGIT(s[3]) && isDIGIT(s[4]); |
4 |
0 |
4 |
| got = len >= 5 && isDIGIT(s[0]) && isDIGIT(s[1]) && s[2] == ':' && isDIGIT(s[3]) && isDIGIT(s[4]); |
4 |
0 |
4 |
| got = len >= 5 && isDIGIT(s[0]) && isDIGIT(s[1]) && s[2] == ':' && isDIGIT(s[3]) && isDIGIT(s[4]); |
4 |
0 |
4 |
| got = len >= 5 && isDIGIT(s[0]) && isDIGIT(s[1]) && s[2] == ':' && isDIGIT(s[3]) && isDIGIT(s[4]); |
4 |
0 |
4 |
|
| 206 |
5 |
▶ | if (got) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (got) { |
4 |
1 |
5 |
|
| 207 |
4 |
| h = (s[0] - '0') * 10 + (s[1] - '0'); |
| 208 |
4 |
| m = (s[3] - '0') * 10 + (s[4] - '0'); |
| 209 |
4 |
▶ | if (len == 8 && s[5] == ':' && isDIGIT(s[6]) && isDIGIT(s[7])) sec = (s[6] - '0') * 10 + (s[7] - '0'); |
Branch: 4 branches
| Branch | True | False | Total |
| if (len == 8 && s[5] == ':' && isDIGIT(s[6]) && isDIGIT(s[7])) sec = (s[6] - '0') * 10 + (s[7] - '0'); |
1 |
3 |
4 |
| if (len == 8 && s[5] == ':' && isDIGIT(s[6]) && isDIGIT(s[7])) sec = (s[6] - '0') * 10 + (s[7] - '0'); |
1 |
0 |
1 |
| if (len == 8 && s[5] == ':' && isDIGIT(s[6]) && isDIGIT(s[7])) sec = (s[6] - '0') * 10 + (s[7] - '0'); |
1 |
0 |
1 |
| if (len == 8 && s[5] == ':' && isDIGIT(s[6]) && isDIGIT(s[7])) sec = (s[6] - '0') * 10 + (s[7] - '0'); |
1 |
0 |
1 |
|
| 210 |
3 |
▶ | else if (len != 5) got = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (len != 5) got = 0; |
0 |
3 |
3 |
|
| 211 |
|
| } |
| 212 |
5 |
▶ | if (!got || h > 23 || m > 59 || sec > 59) |
Branch: 4 branches
| Branch | True | False | Total |
| if (!got || h > 23 || m > 59 || sec > 59) |
4 |
1 |
5 |
| if (!got || h > 23 || m > 59 || sec > 59) |
3 |
1 |
4 |
| if (!got || h > 23 || m > 59 || sec > 59) |
3 |
0 |
3 |
| if (!got || h > 23 || m > 59 || sec > 59) |
0 |
3 |
3 |
|
| 213 |
2 |
| croak("%s: at => '%s' is not a time of day, HH:MM or HH:MM:SS", what, s); |
| 214 |
3 |
| r->by_hour = 1u << h; |
| 215 |
3 |
| r->by_minute = UINT64_C(1) << m; |
| 216 |
3 |
| r->by_second = UINT64_C(1) << sec; |
| 217 |
|
| } |
| 218 |
25 |
▶ | if (o->count) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->count) { |
3 |
22 |
25 |
|
| 219 |
3 |
| IV c = SvIV(o->count); |
| 220 |
3 |
▶ | if (c < 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (c < 1) |
1 |
2 |
3 |
|
| 221 |
1 |
| croak("%s: count => %" IVdf " is not a count above zero", what, c); |
| 222 |
2 |
| r->count = c; |
| 223 |
|
| } |
| 224 |
24 |
▶ | if (o->until) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->until) { |
6 |
18 |
24 |
|
| 225 |
6 |
| const time_keeper_abi *T = tkr_tk(aTHX); |
| 226 |
|
| time_keeper_instant u; |
| 227 |
|
| time_keeper_zone z; |
| 228 |
6 |
▶ | if ((T->from_sv)(aTHX_ o->until, &u, &z, NULL) != TIME_KEEPER_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((T->from_sv)(aTHX_ o->until, &u, &z, NULL) != TIME_KEEPER_OK) |
1 |
5 |
6 |
|
| 229 |
1 |
| croak("%s: until is not a Time::Keeper value", what); |
| 230 |
5 |
▶ | r->until_kind = z.kind == TIME_KEEPER_ZONE_FLOATING ? TKR_UNTIL_FLOATING : TKR_UNTIL_UTC; |
Branch: 1 branch
| Branch | True | False | Total |
| r->until_kind = z.kind == TIME_KEEPER_ZONE_FLOATING ? TKR_UNTIL_FLOATING : TKR_UNTIL_UTC; |
2 |
3 |
5 |
|
| 231 |
5 |
| r->until_sec = u.sec; |
| 232 |
5 |
▶ | if (r->count) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r->count) |
1 |
4 |
5 |
|
| 233 |
1 |
| croak("%s: until and count cannot both be given", what); |
| 234 |
|
| } |
| 235 |
22 |
| } |
| 236 |
|
| |
| 237 |
|
| /* The name of the rule's zone, as Time::Keeper would write it. */ |
| 238 |
|
| static SV * |
| 239 |
396 |
| tkr_zone_name_sv(pTHX_ const tkr_rule *r) |
| 240 |
|
| { |
| 241 |
396 |
| switch (r->zone.kind) { |
| 242 |
10 |
| case TIME_KEEPER_ZONE_UTC: return newSVpvs("UTC"); |
| 243 |
10 |
| case TIME_KEEPER_ZONE_FLOATING: return newSVpvs("floating"); |
| 244 |
7 |
| case TIME_KEEPER_ZONE_FIXED: { |
| 245 |
7 |
| int32_t v = r->zone.value, a = v < 0 ? -v : v; |
| 246 |
0 |
▶ | return a % 60 ? newSVpvf("%c%02d:%02d:%02d", v < 0 ? '-' : '+', a / 3600, a % 3600 / 60, a % 60) |
Branch: 1 branch
| Branch | True | False | Total |
| return a % 60 ? newSVpvf("%c%02d:%02d:%02d", v < 0 ? '-' : '+', a / 3600, a % 3600 / 60, a % 60) |
0 |
0 |
0 |
|
| 247 |
7 |
▶ | : newSVpvf("%c%02d:%02d", v < 0 ? '-' : '+', a / 3600, a % 3600 / 60); |
Branch: 2 branches
| Branch | True | False | Total |
| : newSVpvf("%c%02d:%02d", v < 0 ? '-' : '+', a / 3600, a % 3600 / 60); |
0 |
7 |
7 |
| : newSVpvf("%c%02d:%02d", v < 0 ? '-' : '+', a / 3600, a % 3600 / 60); |
0 |
7 |
7 |
|
| 248 |
|
| } |
| 249 |
369 |
| default: { |
| 250 |
369 |
| const char *n = (tkr_tkz(aTHX)->name)(r->zone.value); |
| 251 |
369 |
▶ | return newSVpv(n ? n : "?", 0); |
Branch: 1 branch
| Branch | True | False | Total |
| return newSVpv(n ? n : "?", 0); |
369 |
0 |
369 |
|
| 252 |
|
| } |
| 253 |
|
| } |
| 254 |
|
| } |
| 255 |
|
| |
| 256 |
|
| /* UNTIL as a Time::Keeper value in the rule's zone: a UTC instant, a |
| 257 |
|
| * floating wall time, or the last second of a DATE in the zone. */ |
| 258 |
|
| static SV * |
| 259 |
6 |
| tkr_until_sv(pTHX_ const tkr_rule *r, const char *what) |
| 260 |
|
| { |
| 261 |
6 |
| const time_keeper_abi *T = tkr_tk(aTHX); |
| 262 |
|
| time_keeper_instant u; |
| 263 |
|
| time_keeper_zone fl; |
| 264 |
|
| SV *sv; |
| 265 |
6 |
| u.nsec = 0; |
| 266 |
6 |
| switch (r->until_kind) { |
| 267 |
2 |
| case TKR_UNTIL_UTC: |
| 268 |
2 |
| u.sec = r->until_sec; |
| 269 |
2 |
| sv = (T->new_sv)(aTHX_ &u, &r->zone, r->locale); |
| 270 |
2 |
| break; |
| 271 |
1 |
| case TKR_UNTIL_FLOATING: |
| 272 |
1 |
| u.sec = r->until_sec; |
| 273 |
1 |
| fl.kind = TIME_KEEPER_ZONE_FLOATING; |
| 274 |
1 |
| fl.value = 0; |
| 275 |
1 |
| sv = (T->new_sv)(aTHX_ &u, &fl, r->locale); |
| 276 |
1 |
| break; |
| 277 |
1 |
| case TKR_UNTIL_DATE: { |
| 278 |
|
| time_keeper_civil c; |
| 279 |
|
| int64_t y; |
| 280 |
|
| unsigned m, d; |
| 281 |
1 |
| memset(&c, 0, sizeof c); |
| 282 |
1 |
| tkr_civil_from_days(r->until_sec / 86400, &y, &m, &d); |
| 283 |
1 |
| c.year = y; c.month = (int)m; c.day = (int)d; c.hour = 23; c.minute = 59; c.second = 59; |
| 284 |
1 |
▶ | if ((T->from_civil)(aTHX_ &c, &r->zone, TIME_KEEPER_GAP_FORWARD, TIME_KEEPER_OVERLAP_EARLIER, &u) != TIME_KEEPER_OK) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((T->from_civil)(aTHX_ &c, &r->zone, TIME_KEEPER_GAP_FORWARD, TIME_KEEPER_OVERLAP_EARLIER, &u) != TIME_KEEPER_OK) |
0 |
1 |
1 |
|
| 285 |
0 |
| croak("%s: UNTIL is outside the years Time::Keeper holds", what); |
| 286 |
1 |
| sv = (T->new_sv)(aTHX_ &u, &r->zone, r->locale); |
| 287 |
1 |
| break; |
| 288 |
|
| } |
| 289 |
2 |
| default: |
| 290 |
2 |
| return &PL_sv_undef; |
| 291 |
|
| } |
| 292 |
4 |
▶ | if (!sv) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv) |
0 |
4 |
4 |
|
| 293 |
0 |
| croak("%s: UNTIL is outside the years Time::Keeper holds", what); |
| 294 |
4 |
| return sv; |
| 295 |
|
| } |
| 296 |
|
| |
| 297 |
|
| #endif |