Skip to content

Commit

Permalink
update(go.mod): upgrade go version to 1.22 in go.mod (#45)
Browse files Browse the repository at this point in the history
* chore(.gitignore): Add `go.work` and `go.work.sum` to ignore list

* update(go.mod): upgrade go version to 1.22 in go.mod

* build(.github/workflows/test.yml): update Go version matrix to 1.22.x and 1.23.x

* refactor(parser.go): Rename variables for clarity and consistency
  • Loading branch information
flc1125 authored Dec 2, 2024
1 parent 2c98a04 commit 84b563a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: "go test"
strategy:
matrix:
go-version: [ 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x ]
go-version: [ 1.22.x, 1.23.x ]
platform: [ ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.platform }}

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

# Dependency directories (remove the comment below to include it)
vendor/
go.work
go.work.sum
.idea
_backup
.todo
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cron

![Supported Go Versions](https://img.shields.io/badge/Go-%3E%3D1.18-blue)
![Supported Go Versions](https://img.shields.io/badge/Go-%3E%3D1.22-blue)
[![Package Version](https://badgen.net/github/release/flc1125/go-cron/stable)](https://github.com/flc1125/go-cron/releases)
[![GoDoc](https://pkg.go.dev/badge/github.com/flc1125/go-cron/v4)](https://pkg.go.dev/github.com/flc1125/go-cron/v4)
[![codecov](https://codecov.io/gh/flc1125/go-cron/graph/badge.svg?token=mXNvrv22JH)](https://codecov.io/gh/flc1125/go-cron)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/flc1125/go-cron/v4

go 1.18
go 1.22

require github.com/stretchr/testify v1.10.0

Expand Down
16 changes: 8 additions & 8 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,24 +172,24 @@ func normalizeFields(fields []string, options ParseOption) ([]string, error) {
}

// Figure out how many fields we need
max := 0
_max := 0
for _, place := range places {
if options&place > 0 {
max++
_max++
}
}
min := max - optionals
_min := _max - optionals

// Validate number of fields
if count := len(fields); count < min || count > max {
if min == max {
return nil, fmt.Errorf("expected exactly %d fields, found %d: %s", min, count, fields)
if count := len(fields); count < _min || count > _max {
if _min == _max {
return nil, fmt.Errorf("expected exactly %d fields, found %d: %s", _min, count, fields)
}
return nil, fmt.Errorf("expected %d to %d fields, found %d: %s", min, max, count, fields)
return nil, fmt.Errorf("expected %d to %d fields, found %d: %s", _min, _max, count, fields)
}

// Populate the optional field if not provided
if min < max && len(fields) == min {
if _min < _max && len(fields) == _min {
switch {
case options&DowOptional > 0:
fields = append(fields, defaults[5]) // TODO: improve access to default
Expand Down

0 comments on commit 84b563a

Please sign in to comment.