From 569276fcdc883edc1f12ee6bea5de00c537152f4 Mon Sep 17 00:00:00 2001 From: Kim Gustyr Date: Thu, 4 Apr 2024 20:27:14 +0100 Subject: [PATCH] feat: Use RFC 3339, more lax datetime parsing (#122) * feat: use more lax datetime parsing * chore: Update Go version --- .github/workflows/go.yml | 12 +++++++++--- .github/workflows/lint.yml | 2 +- .github/workflows/release.yml | 2 +- flagengine/utils/time.go | 8 ++++---- go.mod | 2 ++ go.sum | 2 ++ 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5ab3f1d..91368cc 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -6,17 +6,23 @@ on: pull_request: jobs: - build: if: github.event.pull_request.draft == false name: Build runs-on: ubuntu-latest - steps: + strategy: + max-parallel: 2 + matrix: + go-version: + - stable + - oldstable + + steps: - name: Set up Go 1.x uses: actions/setup-go@v5 with: - go-version: '1.19' + go-version: ${{ matrix.go-version }} id: go - name: Check out code into the Go module directory diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bda339c..3c67148 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: 1.19 + go-version: stable - name: golangci-lint uses: golangci/golangci-lint-action@v4.0.0 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6bf060a..cdc322b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: - run: git fetch --force --tags - uses: actions/setup-go@v5 with: - go-version: 1.19 + go-version: stable cache: true - uses: goreleaser/goreleaser-action@v5 with: diff --git a/flagengine/utils/time.go b/flagengine/utils/time.go index 767dc27..74b7dcd 100644 --- a/flagengine/utils/time.go +++ b/flagengine/utils/time.go @@ -3,19 +3,19 @@ package utils import ( "strings" "time" -) -const iso8601 = "2006-01-02T15:04:05.999999" + "github.com/itlightning/dateparse" +) type ISOTime struct { time.Time } func (i *ISOTime) UnmarshalJSON(bytes []byte) (err error) { - i.Time, err = time.Parse(iso8601, strings.Trim(string(bytes), `"`)) + i.Time, err = dateparse.ParseAny(strings.Trim(string(bytes), `"`)) return } func (i *ISOTime) MarshalJSON() ([]byte, error) { - return []byte(`"` + i.Time.Format(iso8601) + `"`), nil + return []byte(`"` + i.Time.Format(time.RFC3339) + `"`), nil } diff --git a/go.mod b/go.mod index d77ec71..cdc6421 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,8 @@ require ( golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 ) +require github.com/itlightning/dateparse v0.2.0 + require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/go.sum b/go.sum index d6a6d46..e0b9551 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/itlightning/dateparse v0.2.0 h1:eOYLGZORnHweKdTZGOVjDXHhOwMQTNdP4g6+ErgPyeg= +github.com/itlightning/dateparse v0.2.0/go.mod h1:W2PH6/Sq+PuJJ6JUgx2nau+ew1KLGXwoGP1A240x204= 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/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=