diff --git a/.github/workflows/releaser.yml b/.github/workflows/releaser.yml index cc06e22..f6830ef 100644 --- a/.github/workflows/releaser.yml +++ b/.github/workflows/releaser.yml @@ -10,13 +10,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: 1.20 - name: Cache-Go uses: actions/cache@v1 with: @@ -30,7 +30,7 @@ jobs: - name: Test run: go test ./... - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser version: latest diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a882731..d266d8f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.19.x] + go-version: [1.20.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3503c41 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.pprof +*.test +dist +vendor \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index dab3f5c..4826342 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -18,16 +18,19 @@ checksum: snapshot: name_template: "{{ .Tag }}-next" changelog: + use: github-native sort: asc filters: + include: + - "^feat:" exclude: - '^docs:' - '^test:' nfpms: - vendor: dateparse - homepage: https://github.com/araddon/dateparse - maintainer: n/a + homepage: https://github.com/itlightning/dateparse + maintainer: IT Lightning, LLC description: NA formats: - apk diff --git a/.travis.yml b/.travis.yml index 3b4b177..9fe9ae6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.13.x + - 1.20.x before_install: - go get -t -v ./... diff --git a/LICENSE b/LICENSE index f675ed3..f1cf09a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2015-2017 Aaron Raddon +Copyright (c) 2023-2024 IT Lightning, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 4e0f1aa..2c12166 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,29 @@ Go Date Parser --------------------------- +[![GoDoc](https://godoc.org/github.com/itlightning/dateparse?status.svg)](http://godoc.org/github.com/itlightning/dateparse) +![Test Status](https://github.com/itlightning/dateparse/actions/workflows/test.yaml/badge.svg) +[![Go ReportCard](https://goreportcard.com/badge/itlightning/dateparse)](https://goreportcard.com/report/itlightning/dateparse) -Parse many date strings without knowing format in advance. Validates comprehensively to avoid false positives. Uses a scanner to read bytes with a state machine to find format. Much faster than shotgun based parse methods. See [bench_test.go](https://github.com/araddon/dateparse/blob/master/bench_test.go) for performance comparison. See the critical note below about timezones. +Parse date/time strings without knowing the format in advance. Supports 100+ formats. Validates comprehensively to avoid false positives. Very fast (~single-pass state-machine based approach). See [bench_test.go](https://github.com/itlightning/dateparse/blob/main/bench_test.go) for performance comparison. See the critical note below about timezones. + +⚡ Maintained by [IT Lightning](https://itlightning.com/), a cloud-first logging platform that's uniquely powerful, super-easy (schemaless, point-and-shoot ingestion), and affordable. It automatically extracts and classifies structured data out of your unstructured log messages. Enjoy visual pattern-analysis and robust SQL-like search. It's unique architecture means you can log more and pay less. Check it out and give us feedback! ⚡ + +🐛💡 Find a bug or have an idea with this package? [Issues](https://github.com/itlightning/dateparse/issues) and pull requests are welcome. -[![Code Coverage](https://codecov.io/gh/araddon/dateparse/branch/master/graph/badge.svg)](https://codecov.io/gh/araddon/dateparse) -[![GoDoc](https://godoc.org/github.com/araddon/dateparse?status.svg)](http://godoc.org/github.com/araddon/dateparse) -[![Build Status](https://travis-ci.org/araddon/dateparse.svg?branch=master)](https://travis-ci.org/araddon/dateparse) -[![Go ReportCard](https://goreportcard.com/badge/araddon/dateparse)](https://goreportcard.com/report/araddon/dateparse) +History and Contributors +---------------------------------- -**MM/DD/YYYY VS DD/MM/YYYY** Right now this uses mm/dd/yyyy WHEN ambiguous if this is not desired behavior, use `ParseStrict` which will fail on ambiguous date strings. This can be adjusted using the `PreferMonthFirst` parser option. Some ambiguous formats can fail (e.g., trying to parse 31/03/2023 as the default month-first format `MM/DD/YYYY`), but can be automatically retried with `RetryAmbiguousDateWithSwap`. +This is an actively maintained fork of the excellent [original dateparse package](https://github.com/araddon/dateparse) by [@araddon](https://github.com/araddon). +This fork [incorporates](https://github.com/araddon/dateparse/pull/159) many bugfixes from the community, and adds comprehensive validation and extensive performance optimizations. +A special thanks to [@araddon](https://github.com/araddon), other contributors to the original project, as well as those who contributed fixes that got incorporated into this version: +[@arran4](https://github.com/arran4), [@bizy01](https://github.com/bizy01), [@BrianLeishman](https://github.com/BrianLeishman), [@dferstay](https://github.com/dferstay), [@jiangxin](https://github.com/jiangxin), [@jmdacruz](https://github.com/jmdacruz), [@krhubert](https://github.com/krhubert), [@mehanizm](https://github.com/mehanizm), [@xwjdsh](https://github.com/xwjdsh), and [@zifengyu](https://github.com/zifengyu). + + +Ambiguous Date Formats +---------------------------------- + +**MM/DD/YYYY VS DD/MM/YYYY** Right now this uses mm/dd/yyyy *when* ambiguous. If this is not desired behavior, use `ParseStrict` which will fail on ambiguous date strings. This behavior can be adjusted using the `PreferMonthFirst` parser option. Some ambiguous formats can fail (e.g., trying to parse 31/03/2023 as the default month-first format `MM/DD/YYYY`), but can be automatically retried with `RetryAmbiguousDateWithSwap`. ```go @@ -21,14 +35,17 @@ t, err := dateparse.ParseStrict("3/1/2014") > returns error // Return a string that represents the layout to parse the given date-time. -// For certain highly complex date formats, ParseFormat may not be accurate, -// even if ParseAny is able to correctly parse it (e.g., anything that starts -// with a weekday). +// For certain highly complex date formats, ParseFormat's return value may +// not be accurate (if this is the case, the returned format string will be a +// different length, than the input). In these cases, ParseAny will still be +// able to successfully parse the format, but this return value will fail to +// parse. For example, anything that starts with a full weekday will fail. layout, err := dateparse.ParseFormat("May 8, 2009 5:57:51 PM") > "Jan 2, 2006 3:04:05 PM" ``` + Performance Considerations ---------------------------------- @@ -42,7 +59,7 @@ option is off (default)). Timezone Considerations ---------------------------------- -**Timezones** The location your server is configured affects the results! See example or https://play.golang.org/p/IDHRalIyXh and last paragraph here https://golang.org/pkg/time/#Parse. +The location that your server is configured to affects the results! See example or https://play.golang.org/p/IDHRalIyXh and last paragraph here https://golang.org/pkg/time/#Parse. Important points to understand: * If you are parsing a date string that does *not* reference a timezone, if you use `Parse` it will assume UTC, or for `ParseIn` it will use the specified location. @@ -56,13 +73,13 @@ Important points to understand: cli tool for testing dateformats ---------------------------------- -[Date Parse CLI](https://github.com/araddon/dateparse/blob/master/dateparse) +[Date Parse CLI](https://github.com/itlightning/dateparse/tree/main/dateparse) Extended example ------------------- -https://github.com/araddon/dateparse/blob/master/example/main.go +https://github.com/itlightning/dateparse/blob/main/example/main.go ```go package main diff --git a/dateparse/README.md b/dateparse/README.md index cfc001c..f6b99a6 100644 --- a/dateparse/README.md +++ b/dateparse/README.md @@ -6,7 +6,7 @@ Simple CLI to test out dateparse. ```sh -# Since this date string has no timezone/offset so is more effected by +# Since this date string has no timezone/offset it's more affected by # which method you use to parse $ dateparse --timezone="America/Denver" "2017-07-19 03:21:00" diff --git a/dateparse/main.go b/dateparse/main.go index f103658..ff532e5 100644 --- a/dateparse/main.go +++ b/dateparse/main.go @@ -6,7 +6,7 @@ import ( "os" "time" - "github.com/araddon/dateparse" + "github.com/itlightning/dateparse" "github.com/scylladb/termtables" ) diff --git a/example/main.go b/example/main.go index b10857c..7956573 100644 --- a/example/main.go +++ b/example/main.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/araddon/dateparse" + "github.com/itlightning/dateparse" "github.com/scylladb/termtables" ) diff --git a/go.mod b/go.mod index 8268462..2cbd24d 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/araddon/dateparse +module github.com/itlightning/dateparse go 1.20