diff options
| author | Maciej Borzecki <maciej.zenon.borzecki@canonical.com> | 2017-12-22 12:11:20 +0100 |
|---|---|---|
| committer | Maciej Borzecki <maciej.zenon.borzecki@canonical.com> | 2017-12-22 12:11:20 +0100 |
| commit | c9a5241f41bef0143c06a4e06208938cd4a60605 (patch) | |
| tree | effc8c898c436f6b81b85632156077a2e8ff4b9a /timeutil | |
| parent | f144537687b8daea3865e3507d618e69d443e059 (diff) | |
timeutil: replace event separator .. with ,,
Improve readability and replace the original double-dot .. event separator with double-comma ,, Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Diffstat (limited to 'timeutil')
| -rw-r--r-- | timeutil/schedule.go | 12 | ||||
| -rw-r--r-- | timeutil/schedule_test.go | 18 |
2 files changed, 17 insertions, 13 deletions
diff --git a/timeutil/schedule.go b/timeutil/schedule.go index 32f91f4c9c..726d29661b 100644 --- a/timeutil/schedule.go +++ b/timeutil/schedule.go @@ -478,7 +478,7 @@ func ParseLegacySchedule(scheduleSpec string) ([]*Schedule, error) { // ParseSchedule parses a schedule in V2 format. The format is described as: // -// eventlist = eventset *( ".." eventset ) +// eventlist = eventset *( ",," eventset ) // eventset = wdaylist / timelist / wdaylist "," timelist // // wdaylist = wdayset *( "," wdayset ) @@ -493,22 +493,22 @@ func ParseLegacySchedule(scheduleSpec string) ([]*Schedule, error) { // count = 1*DIGIT // // Examples: -// mon,10:00..fri,15:00 (Monday at 10:00, Friday at 15:00) +// mon,10:00,,fri,15:00 (Monday at 10:00, Friday at 15:00) // mon,fri,10:00,15:00 (Monday at 10:00 and 15:00, Friday at 10:00 and 15:00) // mon-wed,fri,9:00-11:00/2 (Monday to Wednesday and on Friday, twice between // 9:00 and 11:00) -// mon,9:00~11:00..wed,22:00~23:00 (Monday, sometime between 9:00 and 11:00, and +// mon,9:00~11:00,,wed,22:00~23:00 (Monday, sometime between 9:00 and 11:00, and // on Wednesday, sometime between 22:00 and 23:00) // mon,wed (Monday and on Wednesday) -// mon..wed (same as above) +// mon,,wed (same as above) // // Returns a slice of schedules or an error if parsing failed func ParseSchedule(scheduleSpec string) ([]*Schedule, error) { var schedule []*Schedule - for _, s := range strings.Split(scheduleSpec, "..") { + for _, s := range strings.Split(scheduleSpec, ",,") { // cut the schedule in event sets - // eventlist = eventset *( ".." eventset ) + // eventlist = eventset *( ",," eventset ) sched, err := parseEventSet(s) if err != nil { return nil, err diff --git a/timeutil/schedule_test.go b/timeutil/schedule_test.go index c766370eaa..2c700f31fc 100644 --- a/timeutil/schedule_test.go +++ b/timeutil/schedule_test.go @@ -313,7 +313,8 @@ func (ts *timeutilSuite) TestParseSchedule(c *C) { {"9:00,mon", nil, `cannot parse "mon": expected time spec`}, {"mon~wed", nil, `cannot parse "mon~wed": "mon~wed" is not a valid weekday`}, {"mon--wed", nil, `cannot parse "mon--wed": invalid week span`}, - {"mon-wed/2..9:00", nil, `cannot parse "mon-wed/2": "wed/2" is not a valid weekday`}, + {"mon-wed/2,,9:00", nil, `cannot parse "mon-wed/2": "wed/2" is not a valid weekday`}, + {"mon..wed", nil, `cannot parse "mon..wed": "mon..wed" is not a valid weekday`}, {"mon9,9:00", nil, `cannot parse "mon9": "mon9" is not a valid weekday`}, {"mon0,9:00", nil, `cannot parse "mon0": "mon0" is not a valid weekday`}, {"mon5-mon1,9:00", nil, `cannot parse "mon5-mon1": unsupported schedule`}, @@ -324,6 +325,9 @@ func (ts *timeutilSuite) TestParseSchedule(c *C) { {"9:00-11:00/3/3/3", nil, `cannot parse "9:00-11:00/3/3/3": not a valid interval`}, {"9:00-11:00///3", nil, `cannot parse "9:00-11:00///3": not a valid interval`}, {"9:00-9:00-10:00/3", nil, `cannot parse "9:00-9:00-10:00/3": not a valid time`}, + {"9:00,,,9:00-10:00/3", nil, `cannot parse ",9:00-10:00/3": not a valid event`}, + {",,,", nil, `cannot parse "": not a valid event`}, + {",,", nil, `cannot parse "": not a valid event`}, {":", nil, `cannot parse ":": not a valid time`}, // valid { @@ -354,7 +358,7 @@ func (ts *timeutilSuite) TestParseSchedule(c *C) { {Start: timeutil.Week{Weekday: time.Monday}, End: timeutil.Week{Weekday: time.Monday}}}, }}, }, { - in: "9:00-11:00..20:00-22:00", + in: "9:00-11:00,,20:00-22:00", expected: []*timeutil.Schedule{{ ClockSpans: []timeutil.ClockSpan{ {Start: timeutil.Clock{Hour: 9}, End: timeutil.Clock{Hour: 11}}}, @@ -363,7 +367,7 @@ func (ts *timeutilSuite) TestParseSchedule(c *C) { {Start: timeutil.Clock{Hour: 20}, End: timeutil.Clock{Hour: 22}}}}, }, }, { - in: "mon,9:00-11:00..wed,22:00-23:00", + in: "mon,9:00-11:00,,wed,22:00-23:00", expected: []*timeutil.Schedule{{ ClockSpans: []timeutil.ClockSpan{ {Start: timeutil.Clock{Hour: 9}, End: timeutil.Clock{Hour: 11}}}, @@ -395,7 +399,7 @@ func (ts *timeutilSuite) TestParseSchedule(c *C) { }}, }, { // same as above - in: "mon..wed", + in: "mon,,wed", expected: []*timeutil.Schedule{{ WeekSpans: []timeutil.WeekSpan{ {Start: timeutil.Week{Weekday: time.Monday}, End: timeutil.Week{Weekday: time.Monday}}}, @@ -498,7 +502,7 @@ func (ts *timeutilSuite) TestScheduleNext(c *C) { randomized bool }{ { - schedule: "mon,10:00..fri,15:00", + schedule: "mon,10:00,,fri,15:00", // sun 22:00 last: "2017-02-05 22:00", // mon 9:00 @@ -579,13 +583,13 @@ func (ts *timeutilSuite) TestScheduleNext(c *C) { // of 'spreading' randomized: false, }, { - schedule: "mon,10:00~12:00..fri,15:00", + schedule: "mon,10:00~12:00,,fri,15:00", last: "2017-02-05 22:00", now: "2017-02-06 9:00", next: "1h-3h", randomized: true, }, { - schedule: "mon,10:00-12:00..fri,15:00", + schedule: "mon,10:00-12:00,,fri,15:00", last: "2017-02-06 12:00", // tue 12:00 now: "2017-02-07 12:00", |
