Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for weekday validator #31

Merged
merged 1 commit into from
Jul 27, 2023
Merged

Bugfix for weekday validator #31

merged 1 commit into from
Jul 27, 2023

Conversation

philodavies
Copy link
Contributor

Output from go test:

--- FAIL: TestNextTickAfter (0.01s)
    --- FAIL: TestNextTickAfter/next_run_after (0.01s)
        --- FAIL: TestNextTickAfter/next_run_after/next_run_after_excl_#63:_0_0_*_*_1#1 (0.00s)
            next_test.go:66: [0 0 * * 1#1][2009-11-23 00:00:00] expected 2009-12-07 00:00:00, got 2010-01-04 00:00:00

I haven't had time to dig into why this case is not working as expected, but I noticed something really weird here. If I say the first Monday of the month it doesn't always give the right answer:

Go Playground example: https://go.dev/play/p/0GJnCNPWCWC

@philodavies
Copy link
Contributor Author

Actually got a better repro.. Anytime the first x-day of the month is the 7th, it gets skipped
https://go.dev/play/p/yoI2lcTtyRY

Output from go test before:
```
--- FAIL: TestNextTickAfter (0.01s)
    --- FAIL: TestNextTickAfter/next_run_after (0.01s)
        --- FAIL: TestNextTickAfter/next_run_after/next_run_after_excl_#63:_0_0_*_*_1#1 (0.00s)
            next_test.go:66: [0 0 * * 1#1][2009-11-23 00:00:00] expected 2009-12-07 00:00:00, got 2010-01-04 00:00:00
```

Now it all passes
@codecov-commenter
Copy link

codecov-commenter commented Jul 27, 2023

Codecov Report

Merging #31 (ec435a0) into main (5a6b134) will not change coverage.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@           Coverage Diff           @@
##             main      #31   +/-   ##
=======================================
  Coverage   94.78%   94.78%           
=======================================
  Files           9        9           
  Lines         594      594           
=======================================
  Hits          563      563           
  Misses         16       16           
  Partials       15       15           
Files Changed Coverage Δ
validator.go 100.00% <100.00%> (ø)

@@ -142,5 +142,5 @@ func isValidWeekDay(val string, last int, ref time.Time) (bool, error) {
return false, nil
}

return ref.Day()/7 == nth-1, nil
return (ref.Day()-1)/7 == nth-1, nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange this change still has all tests passed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an edge case that wasn't covered in the previous unit tests. If we use a cron string that does first/second/etc monday/tuesday/etc of the month, then we get in a situation where days 1-6 are in week 0, but day 7 is week 1. This change makes it that days 1-7 are in week 0.

@philodavies philodavies changed the title New unit tests to demonstrate bug Bugfix for weekday validator Jul 27, 2023
@adhocore
Copy link
Owner

thank you very much (and yes cron (parsing) is not nearly as simple as it looks)

@adhocore adhocore merged commit f878463 into adhocore:main Jul 27, 2023
10 checks passed
@adhocore
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants