mirror of
https://github.com/araddon/dateparse.git
synced 2025-04-25 10:10:31 +08:00
Merge pull request #1 from itlightning/prerelease/v0.1.0
Prepare v0.1.0 release
This commit is contained in:
commit
69f12a31e3
8
.github/workflows/releaser.yml
vendored
8
.github/workflows/releaser.yml
vendored
@ -10,13 +10,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: 1.19
|
go-version: 1.20
|
||||||
- name: Cache-Go
|
- name: Cache-Go
|
||||||
uses: actions/cache@v1
|
uses: actions/cache@v1
|
||||||
with:
|
with:
|
||||||
@ -30,7 +30,7 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: go test ./...
|
run: go test ./...
|
||||||
- name: Run GoReleaser
|
- name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v2
|
uses: goreleaser/goreleaser-action@v5
|
||||||
with:
|
with:
|
||||||
distribution: goreleaser
|
distribution: goreleaser
|
||||||
version: latest
|
version: latest
|
||||||
|
2
.github/workflows/test.yaml
vendored
2
.github/workflows/test.yaml
vendored
@ -4,7 +4,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [1.19.x]
|
go-version: [1.20.x]
|
||||||
os: [ubuntu-latest]
|
os: [ubuntu-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
*.pprof
|
||||||
|
*.test
|
||||||
|
dist
|
||||||
|
vendor
|
@ -18,16 +18,19 @@ checksum:
|
|||||||
snapshot:
|
snapshot:
|
||||||
name_template: "{{ .Tag }}-next"
|
name_template: "{{ .Tag }}-next"
|
||||||
changelog:
|
changelog:
|
||||||
|
use: github-native
|
||||||
sort: asc
|
sort: asc
|
||||||
filters:
|
filters:
|
||||||
|
include:
|
||||||
|
- "^feat:"
|
||||||
exclude:
|
exclude:
|
||||||
- '^docs:'
|
- '^docs:'
|
||||||
- '^test:'
|
- '^test:'
|
||||||
nfpms:
|
nfpms:
|
||||||
-
|
-
|
||||||
vendor: dateparse
|
vendor: dateparse
|
||||||
homepage: https://github.com/araddon/dateparse
|
homepage: https://github.com/itlightning/dateparse
|
||||||
maintainer: n/a <someone@eample.com>
|
maintainer: IT Lightning, LLC <opensource@itlightning.com>
|
||||||
description: NA
|
description: NA
|
||||||
formats:
|
formats:
|
||||||
- apk
|
- apk
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.13.x
|
- 1.20.x
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- go get -t -v ./...
|
- go get -t -v ./...
|
||||||
|
1
LICENSE
1
LICENSE
@ -1,6 +1,7 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015-2017 Aaron Raddon
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
41
README.md
41
README.md
@ -1,15 +1,29 @@
|
|||||||
Go Date Parser
|
Go Date Parser
|
||||||
---------------------------
|
---------------------------
|
||||||
|
[](http://godoc.org/github.com/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.
|
||||||
|
|
||||||
|
|
||||||
[](https://codecov.io/gh/araddon/dateparse)
|
History and Contributors
|
||||||
[](http://godoc.org/github.com/araddon/dateparse)
|
----------------------------------
|
||||||
[](https://travis-ci.org/araddon/dateparse)
|
|
||||||
[](https://goreportcard.com/report/araddon/dateparse)
|
|
||||||
|
|
||||||
**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
|
```go
|
||||||
|
|
||||||
@ -21,14 +35,17 @@ t, err := dateparse.ParseStrict("3/1/2014")
|
|||||||
> returns error
|
> returns error
|
||||||
|
|
||||||
// Return a string that represents the layout to parse the given date-time.
|
// Return a string that represents the layout to parse the given date-time.
|
||||||
// For certain highly complex date formats, ParseFormat may not be accurate,
|
// For certain highly complex date formats, ParseFormat's return value may
|
||||||
// even if ParseAny is able to correctly parse it (e.g., anything that starts
|
// not be accurate (if this is the case, the returned format string will be a
|
||||||
// with a weekday).
|
// 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")
|
layout, err := dateparse.ParseFormat("May 8, 2009 5:57:51 PM")
|
||||||
> "Jan 2, 2006 3:04:05 PM"
|
> "Jan 2, 2006 3:04:05 PM"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Performance Considerations
|
Performance Considerations
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
@ -42,7 +59,7 @@ option is off (default)).
|
|||||||
Timezone Considerations
|
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:
|
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.
|
* 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
|
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
|
Extended example
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
https://github.com/araddon/dateparse/blob/master/example/main.go
|
https://github.com/itlightning/dateparse/blob/main/example/main.go
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
@ -6,7 +6,7 @@ Simple CLI to test out dateparse.
|
|||||||
|
|
||||||
```sh
|
```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
|
# which method you use to parse
|
||||||
|
|
||||||
$ dateparse --timezone="America/Denver" "2017-07-19 03:21:00"
|
$ dateparse --timezone="America/Denver" "2017-07-19 03:21:00"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/araddon/dateparse"
|
"github.com/itlightning/dateparse"
|
||||||
"github.com/scylladb/termtables"
|
"github.com/scylladb/termtables"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/araddon/dateparse"
|
"github.com/itlightning/dateparse"
|
||||||
"github.com/scylladb/termtables"
|
"github.com/scylladb/termtables"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user