Skip to content

Commit

Permalink
Merge pull request #44 from winebarrel/fix_L_bug
Browse files Browse the repository at this point in the history
Fix "L" in day-of-week bug
  • Loading branch information
winebarrel authored Sep 30, 2023
2 parents bed85d8 + ea39eed commit aed887e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

N/A

## [1.9.2] - 2023-09-30

### Fixed

* Fix bug for "L" without wday in day-of-week.

## [1.9.1] - 2023-09-29

### Added
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ However, if you do not specify the day of the week before "L", the behavior will

```
# cron(0 0 ? * L *) = cron(0 0 ? * SAT *)
Sun, 01 Oct 2023 00:00:00
Sun, 08 Oct 2023 00:00:00
Sun, 15 Oct 2023 00:00:00
Sun, 22 Oct 2023 00:00:00
Sun, 29 Oct 2023 00:00:00
Sat, 07 Oct 2023 00:00:00
Sat, 14 Oct 2023 00:00:00
Sat, 21 Oct 2023 00:00:00
Sat, 28 Oct 2023 00:00:00
Sat, 04 Nov 2023 00:00:00
```

# cronplan CLI
Expand Down
2 changes: 1 addition & 1 deletion match.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func (v *LastDayOfWeek) Match(t time.Time) bool {
if v.Wday == nil {
// NOTE: If the day of the week is not specified,
// it will be the same as when SAT is specified.
return t.Weekday() == time.Sunday
return t.Weekday() == time.Saturday
} else {
return util.LastWdayOfMonth(t, v.Weekday()) == t.Day()
}
Expand Down
35 changes: 17 additions & 18 deletions match_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,24 +333,23 @@ func TestIntegrationMatch(t *testing.T) {
tm time.Time
expected bool
}{
{time.Date(2023, 10, 1, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 10, 8, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 10, 15, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 10, 29, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 11, 5, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 11, 12, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 11, 19, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 11, 26, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 12, 3, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 10, 2, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 10, 9, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 10, 16, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 10, 30, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 11, 4, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 11, 11, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 11, 18, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 11, 25, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 12, 2, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 10, 7, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 10, 14, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 10, 28, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 11, 4, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 11, 11, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 11, 18, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 11, 25, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 12, 2, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 12, 9, 0, 0, 0, 0, time.UTC), true},
{time.Date(2023, 10, 8, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 10, 15, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 10, 29, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 11, 3, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 11, 10, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 11, 17, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 11, 24, 0, 0, 0, 0, time.UTC), false},
{time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC), false},
},
},
}
Expand Down
20 changes: 10 additions & 10 deletions next_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,16 @@ func TestNextN_10_LastWdayWithoutWday(t *testing.T) {
schedule := cron.NextN(time.Date(2023, 10, 1, 0, 0, 0, 0, time.UTC), 10)
assert.Equal(
[]time.Time{
time.Date(2023, time.October, 1, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.October, 8, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.October, 15, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.October, 22, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.October, 29, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.November, 05, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.November, 12, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.November, 19, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.November, 26, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.December, 03, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.October, 7, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.October, 14, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.October, 21, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.October, 28, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.November, 04, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.November, 11, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.November, 18, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.November, 25, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.December, 2, 0, 0, 0, 0, time.UTC),
time.Date(2023, time.December, 9, 0, 0, 0, 0, time.UTC),
},
schedule,
)
Expand Down

0 comments on commit aed887e

Please sign in to comment.