diff --git a/rules/common/slash_dmy.go b/rules/common/slash_dmy.go index 31d0799..6c6668e 100644 --- a/rules/common/slash_dmy.go +++ b/rules/common/slash_dmy.go @@ -70,27 +70,24 @@ func SlashDMY(s rules.Strategy) rules.Rule { return true, nil } - if int(ref.Month()) > month { + if month < int(ref.Month()) { year = ref.Year() + 1 - goto WithYear - } + } else if month == int(ref.Month()) { + if day > getDays(ref.Year(), month) { + // invalid date: day is after last day of the month + return false, nil + } - if int(ref.Month()) == month { - if getDays(ref.Year(), month) >= day { - if day > ref.Day() { - year = ref.Year() - } else if day < ref.Day() { - year = ref.Year() + 1 - } else { - return false, nil - } - goto WithYear + if day >= ref.Day() { + year = ref.Year() } else { - return false, nil + year = ref.Year() + 1 } + } else { + year = ref.Year() } - return true, nil + goto WithYear }, } } diff --git a/rules/common/slash_dmy_test.go b/rules/common/slash_dmy_test.go index d2b09f9..60144a6 100644 --- a/rules/common/slash_dmy_test.go +++ b/rules/common/slash_dmy_test.go @@ -27,6 +27,10 @@ func TestSlashDMY(t *testing.T) { // prev day will be added to the future {"The Deadline is 14/07", 16, "14/07", (195 + 366 - OFFSET) * 24 * time.Hour}, + + // Existing doesn't work for a month in the future + {"The Deadline is 14/08", 16, "14/08", time.Date(2016, 8, 14, 0, 0, 0, 0, time.UTC).Sub(null)}, + {"The Deadline is 15/07", 16, "15/07", time.Date(2016, 7, 15, 0, 0, 0, 0, time.UTC).Sub(null)}, } w := when.New(nil)