Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pprof
*.test
dist
vendor
7 changes: 5 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <someone@eample.com>
homepage: https://github.com/itlightning/dateparse
maintainer: IT Lightning, LLC <opensource@itlightning.com>
description: NA
formats:
- apk
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.13.x
- 1.20.x

before_install:
- go get -t -v ./...
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
41 changes: 29 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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! ⚡

[![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)
🐛💡 Find a bug or have an idea with this package? [Issues](https://github.com/itlightning/dateparse/issues) and pull requests are welcome.

**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`.

History and Contributors
----------------------------------

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

Expand All @@ -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
----------------------------------

Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dateparse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion dateparse/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"time"

"github.com/araddon/dateparse"
"github.com/itlightning/dateparse"
"github.com/scylladb/termtables"
)

Expand Down
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/araddon/dateparse"
"github.com/itlightning/dateparse"
"github.com/scylladb/termtables"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/araddon/dateparse
module github.com/itlightning/dateparse

go 1.20

Expand Down