-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschedule.go
1183 lines (1077 loc) · 23.8 KB
/
schedule.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package crong
import (
"errors"
"fmt"
"log/slog"
"math/rand"
"slices"
"strconv"
"strings"
"time"
)
const (
// Cron special characters
Any = '*'
ListSeparator = ','
Range = '-'
Step = '/'
Blank = '?'
Last = 'L'
// Cron macros
Yearly = "@yearly"
Annually = "@annually"
Monthly = "@monthly"
Weekly = "@weekly"
Daily = "@daily"
Midnight = "@midnight"
Hourly = "@hourly"
// String representations for weekdays
Sunday = "SUN"
Monday = "MON"
Tuesday = "TUE"
Wednesday = "WED"
Thursday = "THU"
Friday = "FRI"
Saturday = "SAT"
// String representations for months
January = "JAN"
February = "FEB"
March = "MAR"
April = "APR"
May = "MAY"
June = "JUN"
July = "JUL"
August = "AUG"
September = "SEP"
October = "OCT"
November = "NOV"
December = "DEC"
)
// cron expression positions
const (
minuteInd int = iota
hourInd
dayInd
monthInd
weekdayInd
)
// weekday indices
const (
sundayInd int = iota
mondayInd
tuesdayInd
wednesdayInd
thursdayInd
fridayInd
saturdayInd
)
// month indices
const (
januaryInd int = iota + 1
februaryInd
marchInd
aprilInd
mayInd
juneInd
julyInd
augustInd
septemberInd
octoberInd
novemberInd
decemberInd
)
var (
macros = []string{
Yearly,
Annually,
Monthly,
Weekly,
Daily,
Midnight,
Hourly,
}
minuteOpts = field{
Name: "minute",
Index: minuteInd,
Allowed: []int{
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
},
}
hourOpts = field{
Name: "hour",
Index: hourInd,
Allowed: []int{
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
},
}
dayOpts = field{
Name: "day",
Index: dayInd,
Allowed: []int{
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
},
}
monthOpts = field{
Name: "month",
Index: monthInd,
Allowed: []int{
januaryInd,
februaryInd,
marchInd,
aprilInd,
mayInd,
juneInd,
julyInd,
augustInd,
septemberInd,
octoberInd,
novemberInd,
decemberInd,
},
Conversions: map[string]int{
January: januaryInd,
February: februaryInd,
March: marchInd,
April: aprilInd,
May: mayInd,
June: juneInd,
July: julyInd,
August: augustInd,
September: septemberInd,
October: octoberInd,
November: novemberInd,
December: decemberInd,
},
}
weekdayOpts = field{
Name: "weekday",
Index: weekdayInd,
Allowed: []int{
sundayInd,
mondayInd,
tuesdayInd,
wednesdayInd,
thursdayInd,
fridayInd,
saturdayInd,
},
Conversions: map[string]int{
Sunday: sundayInd,
Monday: mondayInd,
Tuesday: tuesdayInd,
Wednesday: wednesdayInd,
Thursday: thursdayInd,
Friday: fridayInd,
Saturday: saturdayInd,
},
}
// cronShortcut is a map of cron macros to their
// respective cron expressions
cronShortcut = map[string]string{
Yearly: "0 0 1 1 *",
Annually: "0 0 1 1 *",
Monthly: "0 0 1 * *",
Weekly: "0 0 * * 0",
Daily: "0 0 * * *",
Midnight: "0 0 * * *",
Hourly: "0 * * * *",
}
)
// Schedule is a cron schedule created from a cron expression
//
// # Usage
//
// To create a new Schedule, use the New function:
//
// s, err := crong.New("0 0 * * *", time.UTC)
// if err != nil {
// log.Fatal(err)
// }
//
// To get the next scheduled time after a given time, use the Next method:
//
// next := s.Next(time.Now())
//
// To check if a time matches the schedule, use the Matches method:
//
// if s.Matches(time.Now()) {
// fmt.Println("It's time!")
// }
type Schedule struct {
// values holds the parsed cron expression
values [5]string
// loc is the timezone/location to use
loc *time.Location
// created is the time this cron schedule was initialized
created time.Time
// minute is the string value of the minute field
minute string
// minutes is the parsed values of the minute field
minutes []int
minutesDesc []int
// allowAnyMinute indicates a wildcard minute
allowAnyMinute bool
// hour is the string value of the hour field
hour string
// hours is the parsed values of the hour field
hours []int
// allowAnyHour indicates a wildcard hour
allowAnyHour bool
// day is the string value of the day field
day string
// days is the parsed values of the day field
days []int
// allowAnyDay indicates a wildcard day
allowAnyDay bool
// month is the string value of the month field
month string
// months is the parsed values of the month field
months []int
// allowAnyMonth indicates a wildcard month
allowAnyMonth bool
// weekday is the string value of the weekday field
weekday string
// weekdays is the parsed values of the weekday field
weekdays []int
// allowAnyWeekday indicates a wildcard weekday
allowAnyWeekday bool
}
// New creates a new Schedule from a cron expression. loc is the
// location to use for the schedule (if nil, defaults to time.UTC)
func New(cron string, loc *time.Location) (*Schedule, error) {
if loc == nil {
loc = time.UTC
}
s := &Schedule{values: [5]string{}, loc: loc}
s.created = time.Now().In(s.loc)
cron = strings.TrimSpace(cron)
cs, ok := cronShortcut[cron]
if ok {
cron = cs
}
values := strings.Split(cron, " ")
if len(values) != 5 {
return nil, fmt.Errorf(
"invalid cron schedule '%s' (expected 5 values, got %d): %s",
cron,
len(values),
cron,
)
}
for i, v := range values {
s.values[i] = v
}
err := s.validate()
return s, err
}
// NewRandom creates a new Schedule with a random cron expression
func NewRandom(r *rand.Rand) (string, error) {
if r == nil {
r = rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
}
m := r.Intn(100)
if m == 1 {
return macros[r.Intn(len(macros))], nil
}
cronFields := make([]string, 5)
errs := []error{}
minuteVal, err := minuteOpts.random(r)
errs = append(errs, err)
cronFields[minuteInd] = minuteVal
hourVal, err := hourOpts.random(r)
errs = append(errs, err)
cronFields[hourInd] = hourVal
dayVal, err := dayOpts.random(r)
errs = append(errs, err)
cronFields[dayInd] = dayVal
monthVal, err := monthOpts.random(r)
errs = append(errs, err)
cronFields[monthInd] = monthVal
weekdayVal, err := weekdayOpts.random(r)
errs = append(errs, err)
cronFields[weekdayInd] = weekdayVal
return strings.Join(cronFields, " "), errors.Join(errs...)
}
// Next returns the next scheduled time after the given time
func (s *Schedule) Next(t time.Time) time.Time {
return s.nextNoTruncate(t.In(s.loc).Truncate(time.Minute))
}
// Prev returns the previous scheduled time before the given time
func (s *Schedule) Prev(t time.Time) time.Time {
t = t.In(s.loc).Truncate(time.Minute)
for {
t = t.Add(-time.Minute)
if s.Matches(t) {
return t
}
}
}
// nextNoTruncate does the same thing as Next, but assumes
// that the given time had already been truncated to the minute
// and does not truncate it again
func (s *Schedule) nextNoTruncate(t time.Time) time.Time {
// Given we already know all the months/days/weekdays/hours/minutes
// in the schedule, there's probably a more efficient or clever
// way to do a lot of this. For now, I'll stick to checking
// for the 'heavy' calls (@yearly, @monthly), and increment
// the rest. Adding a minute is a cheap operation, and
// I feel like hourly/daily schedules are probably the
// most common
switch cronExpr := s.String(); cronExpr {
case cronShortcut[Yearly]:
// if the schedule is yearly, we can just add a year
// to the given time and return it
return time.Date(
t.Year()+1,
time.Month(januaryInd),
1,
0,
0,
0,
0,
t.Location(),
)
case Monthly:
if int(t.Month()) == decemberInd {
return time.Date(
t.Year()+1,
time.Month(januaryInd),
1,
0,
0,
0,
0,
t.Location(),
)
}
return time.Date(
t.Year(),
t.Month()+1,
1,
0,
0,
0,
0,
t.Location(),
)
}
// if s.allowAnyMonth {
// maxMonth = decemberInd
// minMonth = januaryInd
// } else {
// maxMonth = slices.Max(s.months)
// minMonth = slices.Min(s.months)
// }
for {
// if !s.isMonth(t) {
// currentMonth := int(t.Month())
// if currentMonth < minMonth {
// t = time.Date(
// t.Year(),
// time.Month(minMonth),
// 1,
// 0,
// 0,
// 0,
// 0,
// t.Location(),
// )
// } else if currentMonth > maxMonth {
// t = time.Date(
// t.Year()+1,
// time.Month(minMonth),
// 1,
// 0,
// 0,
// 0,
// 0,
// t.Location(),
// )
// } else {
// var foundMonth int
// for _, m := range s.months {
// if m > currentMonth {
// foundMonth = m
// break
//
// }
// }
// if foundMonth == 0 {
// panic("couldn't find month")
// }
// t = time.Date(
// t.Year(),
// time.Month(foundMonth),
// 1,
// 0,
// 0,
// 0,
// 0,
// t.Location(),
// )s
// }
// }
t = t.Add(time.Minute)
if s.Matches(t) {
return t
}
}
}
// UntilNext returns the duration until the next scheduled time
// after the given time
func (s *Schedule) UntilNext(t time.Time) time.Duration {
return s.Next(t).Sub(t)
}
// Matches returns true if the schedule matches the given time
func (s *Schedule) Matches(t time.Time) bool {
// return s.isMinute(t) && s.isHour(t) && s.isDay(t) && s.isMonth(t) && s.isWeekday(t)
return s.isWeekday(t) && s.isMonth(t) && s.isDay(t) && s.isHour(t) && s.isMinute(t)
}
// String returns the string representation of the schedule
func (s *Schedule) String() string {
return strings.Join(s.values[:], " ")
}
// Minute returns the minute value of the schedule
func (s *Schedule) Minute() string {
return s.values[minuteInd]
}
// Hour returns the hour value of the schedule
func (s *Schedule) Hour() string {
return s.values[hourInd]
}
// Day returns the day value of the schedule
func (s *Schedule) Day() string {
return s.values[dayInd]
}
// Month returns the month value of the schedule
func (s *Schedule) Month() string {
return s.values[monthInd]
}
// Weekday returns the weekday value of the schedule
func (s *Schedule) Weekday() string {
return s.values[weekdayInd]
}
func (s *Schedule) LogValue() slog.Value {
return slog.StringValue(s.String())
}
// isMinute returns true if the given time is a minute
// included in the schedule
func (s *Schedule) isMinute(t time.Time) bool {
if s.allowAnyMinute {
return true
}
m := t.Minute()
for _, includedMinute := range s.minutes {
if m == includedMinute {
return true
}
}
return false
}
// isHour returns true if the given time is an hour
// included in the schedule
func (s *Schedule) isHour(t time.Time) bool {
if s.allowAnyHour {
return true
}
h := t.Hour()
for _, includedHour := range s.hours {
if h == includedHour {
return true
}
}
return false
}
// isDay returns true if the given time is a day
// included in the schedule. If "L" is used as
// the day, it will be interpreted as the last
// day of the month
func (s *Schedule) isDay(t time.Time) bool {
if s.allowAnyDay {
return true
}
d := t.Day()
for _, includedDay := range s.days {
if d == includedDay {
return true
}
}
if s.Day() == string(Last) {
targetMonth := t.Month() + 1
nextMonth := time.Date(
t.Year(),
targetMonth,
1,
0,
0,
0,
0,
t.Location(),
)
lastOfThisMonth := nextMonth.Add(-24 * time.Hour)
return lastOfThisMonth.Day() == t.Day()
}
return false
}
// isMonth returns true if the given time is a month
// included in the schedule
func (s *Schedule) isMonth(t time.Time) bool {
if s.allowAnyMonth {
return true
}
m := int(t.Month())
for _, includedMonth := range s.months {
if m == includedMonth {
return true
}
}
return false
}
// isWeekday returns true if the given time is a weekday
// included in the schedule
func (s *Schedule) isWeekday(t time.Time) bool {
if s.allowAnyWeekday {
return true
}
w := int(t.Weekday())
for _, includedWeekday := range s.weekdays {
if w == includedWeekday {
return true
}
}
return false
}
// validate checks the schedule for errors, and
// assigns the parsed values to the schedule
func (s *Schedule) validate() error {
errs := make([]error, 0, 5)
var minutes []int
var hours []int
var days []int
var months []int
var weekdays []int
var err error
anyStr := string(Any)
blankStr := string(Blank)
switch ms := s.Minute(); ms {
case anyStr:
s.allowAnyMinute = true
default:
minutes, err = minuteOpts.parse(ms)
s.minutes = minutes
errs = append(errs, err)
revSlice := make([]int, len(minutes))
for i, j := 0, len(minutes)-1; i < j; i, j = i+1, j-1 {
revSlice[i], revSlice[j] = minutes[j], minutes[i]
}
s.minutesDesc = revSlice
}
switch hs := s.Hour(); hs {
case anyStr:
s.allowAnyHour = true
default:
hours, err = hourOpts.parse(hs)
errs = append(errs, err)
s.hours = hours
}
switch ds := s.Day(); ds {
case anyStr, blankStr:
s.allowAnyDay = true
default:
days, err = dayOpts.parse(ds)
errs = append(errs, err)
s.days = days
}
switch ms := s.Month(); ms {
case anyStr, blankStr:
s.allowAnyMonth = true
default:
months, err = monthOpts.parse(ms)
errs = append(errs, err)
s.months = months
}
switch ws := s.Weekday(); ws {
case string(Any), string(Blank):
s.allowAnyWeekday = true
default:
weekdays, err = weekdayOpts.parse(ws)
errs = append(errs, err)
s.weekdays = weekdays
}
return errors.Join(errs...)
}
// field defines a cron field
type field struct {
// Name is the name of the field
Name string
// Index is the field position in the cron expression
Index int
// Allowed is the list of allowed values for the field
// (ex: for days, 1-31, months, 1-12, etc.)
Allowed []int
// Conversions is a map of string values to their
// allowed int values (ex: "JAN" -> 1, "FEB" -> 2, etc.)
Conversions map[string]int
}
// Min returns the minimum allowed value for the field
func (f field) Min() int {
return f.Allowed[0]
}
// Max returns the maximum allowed value for the field
func (f field) Max() int {
return f.Allowed[len(f.Allowed)-1]
}
// error returns an error with a field-specific prefixed message
func (f field) error(msg string) error {
return fmt.Errorf("invalid %s entry: %s", f.Name, msg)
}
// wrapErr wraps an error with a field-specific message
func (f field) wrapErr(err error) error {
return fmt.Errorf("invalid %s entry: %w", f.Name, err)
}
// parse parses a string value for the field, returning
// the parsed values (ints to trigger on) or an error
func (f field) parse(s string) ([]int, error) {
var values []int
defer func() {
if values != nil {
slices.Sort(values)
values = slices.Compact(values)
}
}()
if s == "" {
return nil, f.error("empty")
}
// if the string is a wildcard, we can just return all
if s == string(Blank) && f.Index != dayInd && f.Index != monthInd && f.Index != weekdayInd {
return nil, f.error("wildcard ? only supported for day, month, and weekday fields")
}
switch s {
case string(Any), string(Blank):
for i := f.Min(); i <= f.Max(); i++ {
values = append(values, i)
}
return values, nil
}
// may be a value such as JAN, FEB, FRI, etc., where
// we need the int equivalent
s = strings.ToUpper(s)
if f.Conversions != nil {
v, ok := f.Conversions[s]
if ok {
values = append(values, v)
return values, nil
}
}
// if we successfully parse the string as an int, we
// don't have to worry about parsing steps, etc
m, err := strconv.Atoi(s)
if err == nil {
switch {
case m < f.Min():
return nil, f.error(fmt.Sprintf("'%s' is less than %d", s, f.Min()))
case m > f.Max():
return nil, f.error(
fmt.Sprintf(
"'%s' is greater than %d",
s,
f.Max(),
),
)
}
values = append(values, m)
return values, nil
} else {
// but if it fails, we should have a special character in
// the string
switch {
case strings.ContainsRune(s, ListSeparator):
case strings.ContainsRune(s, Range):
case strings.ContainsRune(s, Step):
case strings.ContainsRune(s, Last):
default:
return nil, f.wrapErr(err)
}
}
// Check for the list separator next
// If we have a value like `1,2,3/10`, we want to pull out
// 1 and 2 first, then parse 3/10
if strings.ContainsRune(s, ListSeparator) {
values, err = f.parseList(s)
return values, err
}
// Process step values next, further parsing the string
// prior to the separator to get the initial value to
// Start from
// A minute expression would look like:
// */10 (every 10th minute, so 4:00, 4:10, 4:20...)
// 1-40/10 (every 10th minute from 1-50, so 4:01, 4:11, 4:21, 4:31)
// 5/10 (non-standard, interpreted as every 10th minute from 5-19, so 4:05, 4:15...)
beforeStep, afterStep, stepFound := strings.Cut(s, string(Step))
if stepFound {
values, err = f.parseStep(beforeStep, afterStep)
return values, err
}
before, after, rangeFound := strings.Cut(s, string(Range))
if rangeFound {
values, err = f.parseRange(before, after)
return values, err
}
// the above cases may fall through in case of
// the "L" (Last) special character
return values, nil
}
// parseStep returns the values specified for the pre-delimiter
// and post-delimiter step entry
func (f field) parseStep(stepRange string, step string) ([]int, error) {
if stepRange == "" || step == "" {
return nil, f.error("empty step entry")
}
stepVal, err := strconv.Atoi(step)
if err != nil {
return nil, f.wrapErr(
fmt.Errorf(
"invalid step entry '%s' ('%s')",
stepRange,
step,
),
)
}
if stepVal < 1 {
return nil, f.error("step must be greater than 0")
}
stepRangeValues, err := f.parse(stepRange)
if err != nil {
return nil, f.wrapErr(err)
}
// Though non-standard, this accounts for cron entries
// like "5/10 * * * *" which is interpreted here as
// "every 10th minute from 5-59" as neither a wildcard
// nor a list was supplied
if len(stepRangeValues) == 1 {
minVal := stepRangeValues[0]
for _, av := range f.Allowed {
if av > minVal {
stepRangeValues = append(stepRangeValues, av)
}
}
}
values := stepValues(stepRangeValues, stepVal)
if len(values) == 1 {
return nil, f.wrapErr(fmt.Errorf("step only occurs once"))
}
return values, nil
}
// parseRange returns the specified values for the given values
// specified before and after the range delimiter.
// Ex: "1-5" will [1, 2, 3, 4, 5]
func (f field) parseRange(beforeRange string, afterRange string) (
[]int,
error,
) {
if afterRange == "" {
return nil, f.error("empty end range")
}
startMin, err := f.parse(beforeRange)
if err != nil {
return nil, f.wrapErr(err)
}
if startMin == nil {
return nil, f.error("empty Start range")
}
if len(startMin) > 1 {
return nil, f.error("multiple Start range values")
}
endMin, err := f.parse(afterRange)
if err != nil {
return nil, f.wrapErr(err)
}
if endMin == nil {
return nil, f.error("empty end range")
}
if len(endMin) > 1 {
return nil, f.error("multiple end range values")
}