Skip to content

Commit

Permalink
fix issue 37, honor TZID when evaluating UNTIL
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferix9288 committed Feb 26, 2020
1 parent c4b1bf2 commit 3c634b3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/teambition/rrule-go

go 1.12

require github.com/stretchr/testify v1.5.1
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
9 changes: 9 additions & 0 deletions rruleset_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package rrule

import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
"time"
)
Expand Down Expand Up @@ -440,3 +442,10 @@ func TestRuleSetChangeDTStartTimezoneRespected(t *testing.T) {
}
}
}

func TestStrToRRuleSetWithUntilForRecurrence(t *testing.T) {
str := "DTSTART;TZID=America/Los_Angeles:20200225T060000\nRRULE:FREQ=WEEKLY;INTERVAL=1;WKST=MO;BYDAY=TU;UNTIL=20200303T063000"
r, err := StrToRRuleSet(str)
require.NoError(t, err, "should successfully parse the RRULE")
assert.Equal(t, 2, len(r.All()), "should find two recurrences and treat UNTIL in specified TIMEZONE")
}
2 changes: 1 addition & 1 deletion str.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func StrSliceToRRuleSetInLoc(ss []string, defaultLoc *time.Location) (*Set, erro

switch name {
case "RRULE", "EXRULE":
rOpt, err := StrToROption(rule)
rOpt, err := StrToROptionInLocation(rule, defaultLoc)
if err != nil {
return nil, fmt.Errorf("StrToROption failed: %v", err)
}
Expand Down
14 changes: 10 additions & 4 deletions str_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestSetStr(t *testing.T) {
t.Fatalf("StrToRRuleSet(%s) returned error: %v", setStr, err)
}

assertRulesMatch(set, t)
assertRulesMatch(set, t, false)
}

func TestStrToDtStart(t *testing.T) {
Expand Down Expand Up @@ -281,7 +281,7 @@ func TestRFCSetStr(t *testing.T) {
t.Errorf("dtstart time wrong should be %s but is %s", dtWantTime, dtstart)
}

assertRulesMatch(set, t)
assertRulesMatch(set, t, true)

dtWantAfter := time.Date(2018, 1, 2, 9, 0, 0, 0, nyLoc)
dtAfter := set.After(dtWantTime, false)
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestStrSetParseErrors(t *testing.T) {
}

// Helper for TestRFCSetStr and TestSetStr
func assertRulesMatch(set *Set, t *testing.T) {
func assertRulesMatch(set *Set, t *testing.T, withLocale bool) {
// matching parsed RRules
rRules := set.GetRRule()
if len(rRules) != 3 {
Expand All @@ -417,7 +417,13 @@ func assertRulesMatch(set *Set, t *testing.T) {
if rRules[1].String() != "FREQ=WEEKLY;INTERVAL=2;BYDAY=MO,TU" {
t.Errorf("Unexpected rrule: %s", rRules[0].String())
}
if rRules[2].String() != "FREQ=MONTHLY;UNTIL=20180520T000000Z;BYMONTHDAY=1,2,3" {

expectedRRule3 := "FREQ=MONTHLY;UNTIL=20180520T000000Z;BYMONTHDAY=1,2,3"
if withLocale {
expectedRRule3 = "FREQ=MONTHLY;UNTIL=20180520T040000Z;BYMONTHDAY=1,2,3"
}

if rRules[2].String() != expectedRRule3 {
t.Errorf("Unexpected rrule: %s", rRules[2].String())
}

Expand Down

0 comments on commit 3c634b3

Please sign in to comment.