Merge de86b79126d3fd4ea441450face8181300834ca4 into 6b43995a97dee4b2c7fc0bdff8e124da9f31a57e

This commit is contained in:
klondikedragon 2025-04-18 16:21:38 -06:00 committed by GitHub
commit 82b04c8f43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 3886 additions and 1512 deletions

28
.github/workflows/lint.yaml vendored Normal file
View File

@ -0,0 +1,28 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- main
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache-Go
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
~/Library/Caches/go-build # Build cache (Mac)
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: latest

39
.github/workflows/releaser.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: releaser
on:
push:
tags:
- 'v*.*.*'
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.20.x
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Cache-Go
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
~/Library/Caches/go-build # Build cache (Mac)
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- name: Test
run: go test ./...
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

28
.github/workflows/test.yaml vendored Normal file
View File

@ -0,0 +1,28 @@
on: [push, pull_request]
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.20.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Cache-Go
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod # Module download cache
~/.cache/go-build # Build cache (Linux)
~/Library/Caches/go-build # Build cache (Mac)
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
- name: Test
run: go test ./...

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
*.pprof
*.test
dist
vendor
dateparse/dateparse
example/example

41
.goreleaser.yml Normal file
View File

@ -0,0 +1,41 @@
project_name: dateparse
builds:
-
id: "dateparse"
binary: "dateparse"
dir: dateparse
-
id: "example"
binary: "example"
dir: example
archives:
-
format_overrides:
- goos: windows
format: zip
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
use: github-native
sort: asc
filters:
include:
- "^feat:"
exclude:
- '^docs:'
- '^test:'
nfpms:
-
vendor: dateparse
homepage: https://github.com/itlightning/dateparse
maintainer: IT Lightning, LLC <opensource@itlightning.com>
description: NA
formats:
- apk
- deb
- rpm
release: 1
section: default
priority: extra

View File

@ -1,13 +0,0 @@
language: go
go:
- 1.13.x
before_install:
- go get -t -v ./...
script:
- go test -race -coverprofile=coverage.txt -covermode=atomic
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

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

635
README.md
View File

@ -1,18 +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. Uses a scanner to read bytes and use 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.
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 [SparkLogs](https://sparklogs.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! SparkLogs is developed by [IT Lightning](https://itlightning.com/). ⚡
🐛💡 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 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).
**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.
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
@ -24,21 +35,59 @@ 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'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
----------------------------------
Internally a memory pool is used to minimize allocation overhead. If you could
be frequently parsing text that does not match any format, consider turning on
the the `SimpleErrorMessages` option. This will make error messages have no
contextual details, but will reduce allocation overhead 13x and will be 4x
faster (most of the time is spent in generating a complex error message if the
option is off (default)).
Timezone Considerations
----------------------------------
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.
* If you are parsing a date string that *does* reference a timezone and *does* specify an explicit offset (e.g., `2012-08-03 13:31:59 -0600 MST`), then it will return a time object with a location that represents a fixed timezone that has the given offset and name (it will not validate that the timezone abbreviation specified in the date string is a potential valid match for the given offset).
* This can lead to some potentially unexpected results, for example consider the date string `2012-08-03 18:31:59.000+00:00 PST` -- this string has an explicit offset of `+00:00` (UTC), and so the returned time will have a location with a zero offset (18:31:59.000 UTC) even though the name of the fixed time zone associated with the returned time is `PST`. Essentially, it will always prioritize an explicit offset as accurate over an explicit
* If you are parsing a date string that *does* reference a timezone but *without* an explicit offset (e.g., `2012-08-03 14:32:59 MST`), then it will only recognize and map the timezone name and add an offset if you are using `ParseIn` and specify a location that knows about the given time zone abbreviation (e.g., in this example, you would need to pass the `America/Denver` location and it will recognize the `MST` and `MDT` time zone names)
* If a time zone abbreviation is recognized based on the passed location, then it will use the appropriate offset, and make any appropriate adjustment for daylight saving time (e.g., in the above example, the parsed time would actually contain a zone name of `MDT` because the date is within the range when daylight savings time is active).
* If a time zone abbreviation is *not* recognized for the passed location, then it will create a fake time zone with a *zero* offset but with the specified name. This requires further processing if you are trying to actually get the correct absolute time in the UTC time zone.
* If you receive a parsed time that has a zero offset but a non-UTC timezone name, then you should use a method to map the (sometimes ambiguous) timezone name (e.g., `"EEG"`) into a location name (e.g., `"Africa/Cairo"` or `"Europe/Bucharest"`), and then reconstruct a new time object with the same date/time/nanosecond but with the properly mapped location. (Do not use the `time.In` method to convert it to the new location, as this will treat the original time as if it was in UTC with a zero offset -- you need to reconstruct the time as if it was constructed with the proper location in the first place.)
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)
Running the tests
----------------------------------
Make sure for your Linux distribution you've installed the relevant package that includes older timezone name links (e.g., `US/Pacific`). For example, on Ubuntu:
```bash
sudo apt install tzdata-legacy
```
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
@ -48,61 +97,108 @@ import (
"fmt"
"time"
"github.com/itlightning/dateparse"
"github.com/scylladb/termtables"
"github.com/araddon/dateparse"
)
var examples = []string{
// mon day year (time)
"May 8, 2009 5:57:51 PM",
"oct 7, 1970",
"oct 7, '70",
"oct. 7, 1970",
"oct. 7, 70",
"Mon Jan 2 15:04:05 2006",
"Mon Jan 2 15:04:05 MST 2006",
"Mon Jan 02 15:04:05 -0700 2006",
"Monday, 02-Jan-06 15:04:05 MST",
"Mon, 02 Jan 2006 15:04:05 MST",
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
"Mon, 02 Jan 2006 15:04:05 -0700",
"Mon 30 Sep 2018 09:09:09 PM UTC",
"Mon Aug 10 15:44:11 UTC+0100 2015",
"Thu, 4 Jan 2018 17:53:36 +0000",
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
"Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00)",
"September 17, 2012 10:09am",
"September 17, 2012 at 10:09am PST-08",
"September 17, 2012, 10:10:09",
"October 7, 1970",
"October 7th, 1970",
"Sept. 7, 1970 11:15:26pm",
"Sep 7 2009 11:15:26.123 PM PST",
"September 3rd, 2009 11:15:26.123456789pm",
"September 17 2012 10:09am",
"September 17, 2012, 10:10:09",
"Sep 17, 2012 at 10:02am (EST)",
// (PST-08 will have an offset of -0800, and a zone name of "PST")
"September 17, 2012 at 10:09am PST-08",
// (UTC-0700 has the same offset as -0700, and the returned zone name will be empty)
"September 17 2012 5:00pm UTC-0700",
"September 17 2012 5:00pm GMT-0700",
// (weekday) day mon year (time)
"7 oct 70",
"7 Oct 1970",
"7 September 1970 23:15",
"7 September 1970 11:15:26pm",
"03 February 2013",
"12 Feb 2006, 19:17",
"12 Feb 2006 19:17",
"14 May 2019 19:11:40.164",
"7 oct 70",
"7 oct 1970",
"03 February 2013",
"1 July 2013",
"2013-Feb-03",
// dd/Mon/yyy alpha Months
"06/Jan/2008:15:04:05 -0700",
"4th Sep 2012",
"1st February 2018 13:58:24",
"Mon, 02 Jan 2006 15:04:05 MST", // RFC1123
"Mon, 02 Jan 2006 15:04:05 -0700",
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
"Mon 30 Sep 2018 09:09:09 PM UTC",
"Sun, 07 Jun 2020 00:00:00 +0100",
"Wed, 8 Feb 2023 19:00:46 +1100 (AEDT)",
// ANSIC and UnixDate - weekday month day time year
"Mon Jan 2 15:04:05 2006",
"Mon Jan 2 15:04:05 MST 2006",
"Monday Jan 02 15:04:05 -0700 2006",
"Mon Jan 2 15:04:05.103786 2006",
// RubyDate - weekday month day time offset year
"Mon Jan 02 15:04:05 -0700 2006",
// ANSIC_GLIBC - weekday day month year time
"Mon 02 Jan 2006 03:04:05 PM UTC",
"Monday 02 Jan 2006 03:04:05 PM MST",
// weekday month day time timezone-offset year
"Mon Aug 10 15:44:11 UTC+0000 2015",
// git log default date format
"Thu Apr 7 15:13:13 2005 -0700",
// variants of git log default date format
"Thu Apr 7 15:13:13 2005 -07:00",
"Thu Apr 7 15:13:13 2005 -07:00 PST",
"Thu Apr 7 15:13:13 2005 -07:00 PST (Pacific Standard Time)",
"Thu Apr 7 15:13:13 -0700 2005",
"Thu Apr 7 15:13:13 -07:00 2005",
"Thu Apr 7 15:13:13 -0700 PST 2005",
"Thu Apr 7 15:13:13 -07:00 PST 2005",
"Thu Apr 7 15:13:13 PST 2005",
// Variants of the above with a (full time zone description)
"Fri Jul 3 2015 06:04:07 PST-0700 (Pacific Daylight Time)",
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
"Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00)",
// year month day
"2013 May 2",
"2013 May 02 11:37:55",
// dd/Mon/year alpha Months
"06/Jan/2008 15:04:05 -0700",
// mm/dd/yy
"06/January/2008 15:04:05 -0700",
"06/Jan/2008:15:04:05 -0700", // ngnix-log
"06/January/2008:08:11:17 -0700",
// mm/dd/year (see also PreferMonthFirst and RetryAmbiguousDateWithSwap options)
"3/31/2014",
"03/31/2014",
"08/21/71",
"8/1/71",
"4/8/2014 22:05",
"04/08/2014 22:05",
"04/08/2014, 22:05",
"4/8/14 22:05",
"04/2/2014 03:00:51",
"8/8/1965 12:00:00 AM",
"8/8/1965 01:00:01 PM",
"8/8/1965 01:00 PM",
"8/8/1965 1:00 PM",
"8/8/1965 01:00 PM",
"8/8/1965 12:00 AM",
"8/8/1965 12:00:00AM",
"8/8/1965 01:00:01 PM",
"8/8/1965 01:00:01PM -0700",
"8/8/1965 13:00:01 -0700 PST",
"8/8/1965 01:00:01 PM -0700 PST",
"8/8/1965 01:00:01 PM -07:00 PST (Pacific Standard Time)",
"4/02/2014 03:00:51",
"03/19/2012 10:11:59",
"03/19/2012 10:11:59.3186369",
// mon/dd/year
"Oct/ 7/1970",
"Oct/03/1970 22:33:44",
"February/03/1970 11:33:44.555 PM PST",
// yyyy/mm/dd
"2014/3/31",
"2014/03/31",
@ -112,6 +208,78 @@ var examples = []string{
"2014/4/02 03:00:51",
"2012/03/19 10:11:59",
"2012/03/19 10:11:59.3186369",
// weekday, day-mon-yy time
"Fri, 03-Jul-15 08:08:08 CEST",
"Monday, 02-Jan-06 15:04:05 MST", // RFC850
"Monday, 02 Jan 2006 15:04:05 -0600",
"02-Jan-06 15:04:05 MST",
// RFC3339 - yyyy-mm-ddThh
"2006-01-02T15:04:05+0000",
"2009-08-12T22:15:09-07:00",
"2009-08-12T22:15:09",
"2009-08-12T22:15:09.988",
"2009-08-12T22:15:09Z",
"2009-08-12T22:15:09.52Z",
"2017-07-19T03:21:51:897+0100",
"2019-05-29T08:41-04", // no seconds, 2 digit TZ offset
// yyyy-mm-dd hh:mm:ss
"2014-04-26 17:24:37.3186369",
"2012-08-03 18:31:59.257000000",
"2014-04-26 17:24:37.123",
"2014-04-01 12:01am",
"2014-04-01 12:01:59.765 AM",
"2014-04-01 12:01:59,765",
"2014-04-01 22:43",
"2014-04-01 22:43:22",
"2014-12-16 06:20:00 UTC",
"2014-12-16 06:20:00 GMT",
"2014-04-26 05:24:37 PM",
"2014-04-26 13:13:43 +0800",
"2014-04-26 13:13:43 +0800 +08",
"2014-04-26 13:13:44 +09:00",
"2012-08-03 18:31:59.257000000 +0000 UTC",
"2015-09-30 18:48:56.35272715 +0000 UTC",
"2015-02-18 00:12:00 +0000 GMT", // golang native format
"2015-02-18 00:12:00 +0000 UTC",
"2015-02-08 03:02:00 +0300 MSK m=+0.000000001",
"2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001",
"2017-07-19 03:21:51+00:00",
"2017-04-03 22:32:14.322 CET",
"2017-04-03 22:32:14,322 CET",
"2017-04-03 22:32:14:322 CET",
"2018-09-30 08:09:13.123PM PMDT", // PMDT time zone
"2018-09-30 08:09:13.123 am AMT", // AMT time zone
"2014-04-26",
"2014-04",
"2014",
// yyyy-mm-dd(offset)
"2020-07-20+08:00",
"2020-07-20+0800",
// year-mon-dd
"2013-Feb-03",
"2013-February-03 09:07:08.123",
// dd-mon-year
"03-Feb-13",
"03-Feb-2013",
"07-Feb-2004 09:07:07 +0200",
"07-February-2004 09:07:07 +0200",
// dd-mm-year (this format (common in Europe) always puts the day first, regardless of PreferMonthFirst)
"28-02-02",
"28-02-02 15:16:17",
"28-02-2002",
"28-02-2002 15:16:17",
// mm.dd.yy (see also PreferMonthFirst and RetryAmbiguousDateWithSwap options)
"3.31.2014",
"03.31.14",
"03.31.2014",
"03.31.2014 10:11:59 MST",
"03.31.2014 10:11:59.3186369Z",
// year.mm.dd
"2014.03",
"2014.03.30",
"2014.03.30 08:33pm",
"2014.03.30T08:33:44.555 PM -0700 MST",
"2014.03.30-0600",
// yyyy:mm:dd
"2014:3:31",
"2014:03:31",
@ -121,58 +289,53 @@ var examples = []string{
"2014:4:02 03:00:51",
"2012:03:19 10:11:59",
"2012:03:19 10:11:59.3186369",
// Chinese
"2014年04月08日",
// yyyy-mm-ddThh
"2006-01-02T15:04:05+0000",
"2009-08-12T22:15:09-07:00",
"2009-08-12T22:15:09",
"2009-08-12T22:15:09.988",
"2009-08-12T22:15:09Z",
"2017-07-19T03:21:51:897+0100",
"2019-05-29T08:41-04", // no seconds, 2 digit TZ offset
// yyyy-mm-dd hh:mm:ss
"2014-04-26 17:24:37.3186369",
"2012-08-03 18:31:59.257000000",
"2014-04-26 17:24:37.123",
"2013-04-01 22:43",
"2013-04-01 22:43:22",
"2014-12-16 06:20:00 UTC",
"2014-12-16 06:20:00 GMT",
"2014-04-26 05:24:37 PM",
"2014-04-26 13:13:43 +0800",
"2014-04-26 13:13:43 +0800 +08",
"2014-04-26 13:13:44 +09:00",
"2012-08-03 18:31:59.257000000 +0000 UTC",
"2015-09-30 18:48:56.35272715 +0000 UTC",
"2015-02-18 00:12:00 +0000 GMT",
"2015-02-18 00:12:00 +0000 UTC",
"2015-02-08 03:02:00 +0300 MSK m=+0.000000001",
"2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001",
"2017-07-19 03:21:51+00:00",
"2014-04-26",
"2014-04",
"2014",
"2014-05-11 08:20:13,787",
// yyyy-mm-dd-07:00
"2020-07-20+08:00",
// mm.dd.yy
"3.31.2014",
"03.31.2014",
"08.21.71",
"2014.03",
"2014.03.30",
// yyyymmdd and similar
// mm:dd:yyyy (see also PreferMonthFirst and RetryAmbiguousDateWithSwap options)
"08:03:2012",
"08:04:2012 18:31:59+00:00",
// yyyymmdd and similar
"20140601",
"20140722105203",
// yymmdd hh:mm:yy mysql log
"20140722105203.364",
// Chinese
"2014年4月25日",
"2014年04月08日",
"2014年04月08日 19:17:22 -0700",
// RabbitMQ log format
"8-Mar-2018::14:09:27",
"08-03-2018::02:09:29 PM",
// yymmdd hh:mm:yy mysql log
// 080313 05:21:55 mysqld started
"171113 14:14:20",
"190910 11:51:49",
// unix seconds, ms, micro, nano
"1332151919",
"1384216367189",
"1384216367111222",
"1384216367111222333",
// syslog RFC3164 (and non-conformant variants)
"Apr 9 12:37:24",
"Apr 9 12:37:24-10",
"Apr 9 12:37:24-1000",
"Apr 9 12:37:24 UTC-10",
"Apr 9 12:37:24 MST",
"Apr 9 12:37:24 MST-07:00",
"Apr 9 12:37:24 TZ-10",
"Apr 9 12:37:24 TZ+02:00",
"Apr 9 12:37:24+10",
"Apr 9 12:37:24+10:00",
"Apr 9 12:37:24 CEST",
"Apr 9 12:37:24 CEST+0200",
"Apr 9 12:37:24 2025",
"Apr 9 12:37:24 2025 +02:00",
"Apr 9 2025 12:37:24",
"Apr 9 2025 12:37:24 -0700",
// syslog RFC5424 (and non-conformant variants)
"2025-04-09T12:37:24Z",
"2025-04-09T12:37:24.123Z",
"2025-04-09T12:37:24.123456Z",
"2025-04-09T12:37:24-10:00",
"2025-04-09T12:37:24.123 +0200",
"2025-04-09T12:37:24.123456 -0700 MDT",
}
var (
@ -207,117 +370,209 @@ func main() {
}
/*
+-------------------------------------------------------+-----------------------------------------+
| Input | Parsed, and Output as %v |
+-------------------------------------------------------+-----------------------------------------+
| May 8, 2009 5:57:51 PM | 2009-05-08 17:57:51 +0000 UTC |
| oct 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| oct 7, '70 | 1970-10-07 00:00:00 +0000 UTC |
| oct. 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| oct. 7, 70 | 1970-10-07 00:00:00 +0000 UTC |
| Mon Jan 2 15:04:05 2006 | 2006-01-02 15:04:05 +0000 UTC |
| Mon Jan 2 15:04:05 MST 2006 | 2006-01-02 15:04:05 +0000 MST |
| Mon Jan 02 15:04:05 -0700 2006 | 2006-01-02 15:04:05 -0700 -0700 |
| Monday, 02-Jan-06 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 +0200 |
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
| Mon 30 Sep 2018 09:09:09 PM UTC | 2018-09-30 21:09:09 +0000 UTC |
| Mon Aug 10 15:44:11 UTC+0100 2015 | 2015-08-10 15:44:11 +0000 UTC |
| Thu, 4 Jan 2018 17:53:36 +0000 | 2018-01-04 17:53:36 +0000 UTC |
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 GMT |
| Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00) | 2021-01-03 00:12:23 +0800 +0800 |
| September 17, 2012 10:09am | 2012-09-17 10:09:00 +0000 UTC |
| September 17, 2012 at 10:09am PST-08 | 2012-09-17 10:09:00 -0800 PST |
| September 17, 2012, 10:10:09 | 2012-09-17 10:10:09 +0000 UTC |
| October 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| October 7th, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| 12 Feb 2006, 19:17 | 2006-02-12 19:17:00 +0000 UTC |
| 12 Feb 2006 19:17 | 2006-02-12 19:17:00 +0000 UTC |
| 14 May 2019 19:11:40.164 | 2019-05-14 19:11:40.164 +0000 UTC |
| 7 oct 70 | 1970-10-07 00:00:00 +0000 UTC |
| 7 oct 1970 | 1970-10-07 00:00:00 +0000 UTC |
| 03 February 2013 | 2013-02-03 00:00:00 +0000 UTC |
| 1 July 2013 | 2013-07-01 00:00:00 +0000 UTC |
| 2013-Feb-03 | 2013-02-03 00:00:00 +0000 UTC |
| 06/Jan/2008:15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 06/Jan/2008 15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 3/31/2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03/31/2014 | 2014-03-31 00:00:00 +0000 UTC |
| 08/21/71 | 1971-08-21 00:00:00 +0000 UTC |
| 8/1/71 | 1971-08-01 00:00:00 +0000 UTC |
| 4/8/2014 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/08/2014 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 4/8/14 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/2/2014 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 8/8/1965 12:00:00 AM | 1965-08-08 00:00:00 +0000 UTC |
| 8/8/1965 01:00:01 PM | 1965-08-08 13:00:01 +0000 UTC |
| 8/8/1965 01:00 PM | 1965-08-08 13:00:00 +0000 UTC |
| 8/8/1965 1:00 PM | 1965-08-08 13:00:00 +0000 UTC |
| 8/8/1965 12:00 AM | 1965-08-08 00:00:00 +0000 UTC |
| 4/02/2014 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 03/19/2012 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 03/19/2012 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| 2014/3/31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014/03/31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014/4/8 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014/04/08 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014/04/2 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2014/4/02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2012/03/19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 2012/03/19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| 2014:3:31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014:03:31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014:4:8 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014:04:08 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014:04:2 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2014:4:02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2012:03:19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 2012:03:19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| 2014年04月08日 | 2014-04-08 00:00:00 +0000 UTC |
| 2006-01-02T15:04:05+0000 | 2006-01-02 15:04:05 +0000 UTC |
| 2009-08-12T22:15:09-07:00 | 2009-08-12 22:15:09 -0700 -0700 |
| 2009-08-12T22:15:09 | 2009-08-12 22:15:09 +0000 UTC |
| 2009-08-12T22:15:09.988 | 2009-08-12 22:15:09.988 +0000 UTC |
| 2009-08-12T22:15:09Z | 2009-08-12 22:15:09 +0000 UTC |
| 2017-07-19T03:21:51:897+0100 | 2017-07-19 03:21:51.897 +0100 +0100 |
| 2019-05-29T08:41-04 | 2019-05-29 08:41:00 -0400 -0400 |
| 2014-04-26 17:24:37.3186369 | 2014-04-26 17:24:37.3186369 +0000 UTC |
| 2012-08-03 18:31:59.257000000 | 2012-08-03 18:31:59.257 +0000 UTC |
| 2014-04-26 17:24:37.123 | 2014-04-26 17:24:37.123 +0000 UTC |
| 2013-04-01 22:43 | 2013-04-01 22:43:00 +0000 UTC |
| 2013-04-01 22:43:22 | 2013-04-01 22:43:22 +0000 UTC |
| 2014-12-16 06:20:00 UTC | 2014-12-16 06:20:00 +0000 UTC |
| 2014-12-16 06:20:00 GMT | 2014-12-16 06:20:00 +0000 UTC |
| 2014-04-26 05:24:37 PM | 2014-04-26 17:24:37 +0000 UTC |
| 2014-04-26 13:13:43 +0800 | 2014-04-26 13:13:43 +0800 +0800 |
| 2014-04-26 13:13:43 +0800 +08 | 2014-04-26 13:13:43 +0800 +0800 |
| 2014-04-26 13:13:44 +09:00 | 2014-04-26 13:13:44 +0900 +0900 |
| 2012-08-03 18:31:59.257000000 +0000 UTC | 2012-08-03 18:31:59.257 +0000 UTC |
| 2015-09-30 18:48:56.35272715 +0000 UTC | 2015-09-30 18:48:56.35272715 +0000 UTC |
| 2015-02-18 00:12:00 +0000 GMT | 2015-02-18 00:12:00 +0000 UTC |
| 2015-02-18 00:12:00 +0000 UTC | 2015-02-18 00:12:00 +0000 UTC |
| 2015-02-08 03:02:00 +0300 MSK m=+0.000000001 | 2015-02-08 03:02:00 +0300 +0300 |
| 2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001 | 2015-02-08 03:02:00.001 +0300 +0300 |
| 2017-07-19 03:21:51+00:00 | 2017-07-19 03:21:51 +0000 UTC |
| 2014-04-26 | 2014-04-26 00:00:00 +0000 UTC |
| 2014-04 | 2014-04-01 00:00:00 +0000 UTC |
| 2014 | 2014-01-01 00:00:00 +0000 UTC |
| 2014-05-11 08:20:13,787 | 2014-05-11 08:20:13.787 +0000 UTC |
| 2020-07-20+08:00 | 2020-07-20 00:00:00 +0800 +0800 |
| 3.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
| 2014.03 | 2014-03-01 00:00:00 +0000 UTC |
| 2014.03.30 | 2014-03-30 00:00:00 +0000 UTC |
| 20140601 | 2014-06-01 00:00:00 +0000 UTC |
| 20140722105203 | 2014-07-22 10:52:03 +0000 UTC |
| 171113 14:14:20 | 2017-11-13 14:14:20 +0000 UTC |
| 1332151919 | 2012-03-19 10:11:59 +0000 UTC |
| 1384216367189 | 2013-11-12 00:32:47.189 +0000 UTC |
| 1384216367111222 | 2013-11-12 00:32:47.111222 +0000 UTC |
| 1384216367111222333 | 2013-11-12 00:32:47.111222333 +0000 UTC |
+-------------------------------------------------------+-----------------------------------------+
+------------------------------------------------------------+-----------------------------------------+
| Input | Parsed, and Output as %v |
+------------------------------------------------------------+-----------------------------------------+
| May 8, 2009 5:57:51 PM | 2009-05-08 17:57:51 +0000 UTC |
| oct 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| oct 7, '70 | 1970-10-07 00:00:00 +0000 UTC |
| oct. 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| oct. 7, 70 | 1970-10-07 00:00:00 +0000 UTC |
| October 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| October 7th, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| Sept. 7, 1970 11:15:26pm | 1970-09-07 23:15:26 +0000 UTC |
| Sep 7 2009 11:15:26.123 PM PST | 2009-09-07 23:15:26.123 +0000 PST |
| September 3rd, 2009 11:15:26.123456789pm | 2009-09-03 23:15:26.123456789 +0000 UTC |
| September 17 2012 10:09am | 2012-09-17 10:09:00 +0000 UTC |
| September 17, 2012, 10:10:09 | 2012-09-17 10:10:09 +0000 UTC |
| Sep 17, 2012 at 10:02am (EST) | 2012-09-17 10:02:00 +0000 EST |
| September 17, 2012 at 10:09am PST-08 | 2012-09-17 10:09:00 -0800 PST |
| September 17 2012 5:00pm UTC-0700 | 2012-09-17 17:00:00 -0700 -0700 |
| September 17 2012 5:00pm GMT-0700 | 2012-09-17 17:00:00 -0700 -0700 |
| 7 oct 70 | 1970-10-07 00:00:00 +0000 UTC |
| 7 Oct 1970 | 1970-10-07 00:00:00 +0000 UTC |
| 7 September 1970 23:15 | 1970-09-07 23:15:00 +0000 UTC |
| 7 September 1970 11:15:26pm | 1970-09-07 23:15:26 +0000 UTC |
| 03 February 2013 | 2013-02-03 00:00:00 +0000 UTC |
| 12 Feb 2006, 19:17 | 2006-02-12 19:17:00 +0000 UTC |
| 12 Feb 2006 19:17 | 2006-02-12 19:17:00 +0000 UTC |
| 14 May 2019 19:11:40.164 | 2019-05-14 19:11:40.164 +0000 UTC |
| 4th Sep 2012 | 2012-09-04 00:00:00 +0000 UTC |
| 1st February 2018 13:58:24 | 2018-02-01 13:58:24 +0000 UTC |
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 CEST |
| Mon 30 Sep 2018 09:09:09 PM UTC | 2018-09-30 21:09:09 +0000 UTC |
| Sun, 07 Jun 2020 00:00:00 +0100 | 2020-06-07 00:00:00 +0100 +0100 |
| Wed, 8 Feb 2023 19:00:46 +1100 (AEDT) | 2023-02-08 19:00:46 +1100 AEDT |
| Mon Jan 2 15:04:05 2006 | 2006-01-02 15:04:05 +0000 UTC |
| Mon Jan 2 15:04:05 MST 2006 | 2006-01-02 15:04:05 +0000 MST |
| Monday Jan 02 15:04:05 -0700 2006 | 2006-01-02 15:04:05 -0700 -0700 |
| Mon Jan 2 15:04:05.103786 2006 | 2006-01-02 15:04:05.103786 +0000 UTC |
| Mon Jan 02 15:04:05 -0700 2006 | 2006-01-02 15:04:05 -0700 -0700 |
| Mon 02 Jan 2006 03:04:05 PM UTC | 2006-01-02 15:04:05 +0000 UTC |
| Monday 02 Jan 2006 03:04:05 PM MST | 2006-01-02 15:04:05 +0000 MST |
| Mon Aug 10 15:44:11 UTC+0000 2015 | 2015-08-10 15:44:11 +0000 UTC |
| Thu Apr 7 15:13:13 2005 -0700 | 2005-04-07 15:13:13 -0700 -0700 |
| Thu Apr 7 15:13:13 2005 -07:00 | 2005-04-07 15:13:13 -0700 -0700 |
| Thu Apr 7 15:13:13 2005 -07:00 PST | 2005-04-07 15:13:13 -0700 PST |
| Thu Apr 7 15:13:13 2005 -07:00 PST (Pacific Standard Time) | 2005-04-07 15:13:13 -0700 PST |
| Thu Apr 7 15:13:13 -0700 2005 | 2005-04-07 15:13:13 -0700 -0700 |
| Thu Apr 7 15:13:13 -07:00 2005 | 2005-04-07 15:13:13 -0700 -0700 |
| Thu Apr 7 15:13:13 -0700 PST 2005 | 2005-04-07 15:13:13 -0700 PST |
| Thu Apr 7 15:13:13 -07:00 PST 2005 | 2005-04-07 15:13:13 -0700 PST |
| Thu Apr 7 15:13:13 PST 2005 | 2005-04-07 15:13:13 +0000 PST |
| Fri Jul 3 2015 06:04:07 PST-0700 (Pacific Daylight Time) | 2015-07-03 06:04:07 -0700 PST |
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 +0100 |
| Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00) | 2021-01-03 00:12:23 +0800 +0800 |
| 2013 May 2 | 2013-05-02 00:00:00 +0000 UTC |
| 2013 May 02 11:37:55 | 2013-05-02 11:37:55 +0000 UTC |
| 06/Jan/2008 15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 06/January/2008 15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 06/Jan/2008:15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 06/January/2008:08:11:17 -0700 | 2008-01-06 08:11:17 -0700 -0700 |
| 3/31/2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03/31/2014 | 2014-03-31 00:00:00 +0000 UTC |
| 08/21/71 | 1971-08-21 00:00:00 +0000 UTC |
| 8/1/71 | 1971-08-01 00:00:00 +0000 UTC |
| 4/8/2014 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/08/2014 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/08/2014, 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 4/8/14 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/2/2014 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 8/8/1965 1:00 PM | 1965-08-08 13:00:00 +0000 UTC |
| 8/8/1965 01:00 PM | 1965-08-08 13:00:00 +0000 UTC |
| 8/8/1965 12:00 AM | 1965-08-08 00:00:00 +0000 UTC |
| 8/8/1965 12:00:00AM | 1965-08-08 00:00:00 +0000 UTC |
| 8/8/1965 01:00:01 PM | 1965-08-08 13:00:01 +0000 UTC |
| 8/8/1965 01:00:01PM -0700 | 1965-08-08 13:00:01 -0700 -0700 |
| 8/8/1965 13:00:01 -0700 PST | 1965-08-08 13:00:01 -0700 PST |
| 8/8/1965 01:00:01 PM -0700 PST | 1965-08-08 13:00:01 -0700 PST |
| 8/8/1965 01:00:01 PM -07:00 PST (Pacific Standard Time) | 1965-08-08 13:00:01 -0700 PST |
| 4/02/2014 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 03/19/2012 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 03/19/2012 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| Oct/ 7/1970 | 1970-10-07 00:00:00 +0000 UTC |
| Oct/03/1970 22:33:44 | 1970-10-03 22:33:44 +0000 UTC |
| February/03/1970 11:33:44.555 PM PST | 1970-02-03 23:33:44.555 +0000 PST |
| 2014/3/31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014/03/31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014/4/8 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014/04/08 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014/04/2 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2014/4/02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2012/03/19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 2012/03/19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| Fri, 03-Jul-15 08:08:08 CEST | 2015-07-03 08:08:08 +0000 CEST |
| Monday, 02-Jan-06 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| Monday, 02 Jan 2006 15:04:05 -0600 | 2006-01-02 15:04:05 -0600 -0600 |
| 02-Jan-06 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| 2006-01-02T15:04:05+0000 | 2006-01-02 15:04:05 +0000 UTC |
| 2009-08-12T22:15:09-07:00 | 2009-08-12 22:15:09 -0700 -0700 |
| 2009-08-12T22:15:09 | 2009-08-12 22:15:09 +0000 UTC |
| 2009-08-12T22:15:09.988 | 2009-08-12 22:15:09.988 +0000 UTC |
| 2009-08-12T22:15:09Z | 2009-08-12 22:15:09 +0000 UTC |
| 2009-08-12T22:15:09.52Z | 2009-08-12 22:15:09.52 +0000 UTC |
| 2017-07-19T03:21:51:897+0100 | 2017-07-19 03:21:51.897 +0100 +0100 |
| 2019-05-29T08:41-04 | 2019-05-29 08:41:00 -0400 -0400 |
| 2014-04-26 17:24:37.3186369 | 2014-04-26 17:24:37.3186369 +0000 UTC |
| 2012-08-03 18:31:59.257000000 | 2012-08-03 18:31:59.257 +0000 UTC |
| 2014-04-26 17:24:37.123 | 2014-04-26 17:24:37.123 +0000 UTC |
| 2014-04-01 12:01am | 2014-04-01 00:01:00 +0000 UTC |
| 2014-04-01 12:01:59.765 AM | 2014-04-01 00:01:59.765 +0000 UTC |
| 2014-04-01 12:01:59,765 | 2014-04-01 12:01:59.765 +0000 UTC |
| 2014-04-01 22:43 | 2014-04-01 22:43:00 +0000 UTC |
| 2014-04-01 22:43:22 | 2014-04-01 22:43:22 +0000 UTC |
| 2014-12-16 06:20:00 UTC | 2014-12-16 06:20:00 +0000 UTC |
| 2014-12-16 06:20:00 GMT | 2014-12-16 06:20:00 +0000 GMT |
| 2014-04-26 05:24:37 PM | 2014-04-26 17:24:37 +0000 UTC |
| 2014-04-26 13:13:43 +0800 | 2014-04-26 13:13:43 +0800 +0800 |
| 2014-04-26 13:13:43 +0800 +08 | 2014-04-26 13:13:43 +0800 +0800 |
| 2014-04-26 13:13:44 +09:00 | 2014-04-26 13:13:44 +0900 +0900 |
| 2012-08-03 18:31:59.257000000 +0000 UTC | 2012-08-03 18:31:59.257 +0000 UTC |
| 2015-09-30 18:48:56.35272715 +0000 UTC | 2015-09-30 18:48:56.35272715 +0000 UTC |
| 2015-02-18 00:12:00 +0000 GMT | 2015-02-18 00:12:00 +0000 GMT |
| 2015-02-18 00:12:00 +0000 UTC | 2015-02-18 00:12:00 +0000 UTC |
| 2015-02-08 03:02:00 +0300 MSK m=+0.000000001 | 2015-02-08 03:02:00 +0300 MSK |
| 2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001 | 2015-02-08 03:02:00.001 +0300 MSK |
| 2017-07-19 03:21:51+00:00 | 2017-07-19 03:21:51 +0000 UTC |
| 2017-04-03 22:32:14.322 CET | 2017-04-03 22:32:14.322 +0000 CET |
| 2017-04-03 22:32:14,322 CET | 2017-04-03 22:32:14.322 +0000 CET |
| 2017-04-03 22:32:14:322 CET | 2017-04-03 22:32:14.322 +0000 CET |
| 2018-09-30 08:09:13.123PM PMDT | 2018-09-30 20:09:13.123 +0000 PMDT |
| 2018-09-30 08:09:13.123 am AMT | 2018-09-30 08:09:13.123 +0000 AMT |
| 2014-04-26 | 2014-04-26 00:00:00 +0000 UTC |
| 2014-04 | 2014-04-01 00:00:00 +0000 UTC |
| 2014 | 2014-01-01 00:00:00 +0000 UTC |
| 2020-07-20+08:00 | 2020-07-20 00:00:00 +0800 +0800 |
| 2020-07-20+0800 | 2020-07-20 00:00:00 +0800 +0800 |
| 2013-Feb-03 | 2013-02-03 00:00:00 +0000 UTC |
| 2013-February-03 09:07:08.123 | 2013-02-03 09:07:08.123 +0000 UTC |
| 03-Feb-13 | 2013-02-03 00:00:00 +0000 UTC |
| 03-Feb-2013 | 2013-02-03 00:00:00 +0000 UTC |
| 07-Feb-2004 09:07:07 +0200 | 2004-02-07 09:07:07 +0200 +0200 |
| 07-February-2004 09:07:07 +0200 | 2004-02-07 09:07:07 +0200 +0200 |
| 28-02-02 | 2002-02-28 00:00:00 +0000 UTC |
| 28-02-02 15:16:17 | 2002-02-28 15:16:17 +0000 UTC |
| 28-02-2002 | 2002-02-28 00:00:00 +0000 UTC |
| 28-02-2002 15:16:17 | 2002-02-28 15:16:17 +0000 UTC |
| 3.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03.31.14 | 2014-03-31 00:00:00 +0000 UTC |
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03.31.2014 10:11:59 MST | 2014-03-31 10:11:59 +0000 MST |
| 03.31.2014 10:11:59.3186369Z | 2014-03-31 10:11:59.3186369 +0000 UTC |
| 2014.03 | 2014-03-01 00:00:00 +0000 UTC |
| 2014.03.30 | 2014-03-30 00:00:00 +0000 UTC |
| 2014.03.30 08:33pm | 2014-03-30 20:33:00 +0000 UTC |
| 2014.03.30T08:33:44.555 PM -0700 MST | 2014-03-30 20:33:44.555 -0700 MST |
| 2014.03.30-0600 | 2014-03-30 00:00:00 -0600 -0600 |
| 2014:3:31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014:03:31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014:4:8 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014:04:08 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014:04:2 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2014:4:02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2012:03:19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 2012:03:19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| 08:03:2012 | 2012-08-03 00:00:00 +0000 UTC |
| 08:04:2012 18:31:59+00:00 | 2012-08-04 18:31:59 +0000 UTC |
| 20140601 | 2014-06-01 00:00:00 +0000 UTC |
| 20140722105203 | 2014-07-22 10:52:03 +0000 UTC |
| 20140722105203.364 | 2014-07-22 10:52:03.364 +0000 UTC |
| 2014年4月25日 | 2014-04-25 00:00:00 +0000 UTC |
| 2014年04月08日 | 2014-04-08 00:00:00 +0000 UTC |
| 2014年04月08日 19:17:22 -0700 | 2014-04-08 19:17:22 -0700 -0700 |
| 8-Mar-2018::14:09:27 | 2018-03-08 14:09:27 +0000 UTC |
| 08-03-2018::02:09:29 PM | 2018-03-08 14:09:29 +0000 UTC |
| 171113 14:14:20 | 2017-11-13 14:14:20 +0000 UTC |
| 190910 11:51:49 | 2019-09-10 11:51:49 +0000 UTC |
| 1332151919 | 2012-03-19 10:11:59 +0000 UTC |
| 1384216367189 | 2013-11-12 00:32:47.189 +0000 UTC |
| 1384216367111222 | 2013-11-12 00:32:47.111222 +0000 UTC |
| 1384216367111222333 | 2013-11-12 00:32:47.111222333 +0000 UTC |
| Apr 9 12:37:24 | 0000-04-09 12:37:24 +0000 UTC |
| Apr 9 12:37:24-10 | 0000-04-09 12:37:24 -1000 -1000 |
| Apr 9 12:37:24-1000 | 0000-04-09 12:37:24 -1000 -1000 |
| Apr 9 12:37:24 UTC-10 | 0000-04-09 12:37:24 -1000 -1000 |
| Apr 9 12:37:24 MST | 0000-04-09 12:37:24 +0000 MST |
| Apr 9 12:37:24 MST-07:00 | 0000-04-09 12:37:24 -0700 MST |
| Apr 9 12:37:24 TZ-10 | 0000-04-09 12:37:24 -1000 -1000 |
| Apr 9 12:37:24 TZ+02:00 | 0000-04-09 12:37:24 +0200 +0200 |
| Apr 9 12:37:24+10 | 0000-04-09 12:37:24 +1000 +1000 |
| Apr 9 12:37:24+10:00 | 0000-04-09 12:37:24 +1000 +1000 |
| Apr 9 12:37:24 CEST | 0000-04-09 12:37:24 +0000 CEST |
| Apr 9 12:37:24 CEST+0200 | 0000-04-09 12:37:24 +0200 CEST |
| Apr 9 12:37:24 2025 | 2025-04-09 12:37:24 +0000 UTC |
| Apr 9 12:37:24 2025 +02:00 | 2025-04-09 12:37:24 +0200 +0200 |
| Apr 9 2025 12:37:24 | 2025-04-09 12:37:24 +0000 UTC |
| Apr 9 2025 12:37:24 -0700 | 2025-04-09 12:37:24 -0700 -0700 |
| 2025-04-09T12:37:24Z | 2025-04-09 12:37:24 +0000 UTC |
| 2025-04-09T12:37:24.123Z | 2025-04-09 12:37:24.123 +0000 UTC |
| 2025-04-09T12:37:24.123456Z | 2025-04-09 12:37:24.123456 +0000 UTC |
| 2025-04-09T12:37:24-10:00 | 2025-04-09 12:37:24 -1000 -1000 |
| 2025-04-09T12:37:24.123 +0200 | 2025-04-09 12:37:24.123 +0200 +0200 |
| 2025-04-09T12:37:24.123456 -0700 MDT | 2025-04-09 12:37:24.123456 -0700 MDT |
+------------------------------------------------------------+-----------------------------------------+
*/
```

View File

@ -7,12 +7,8 @@ import (
)
/*
go test -bench Parse
BenchmarkShotgunParse 50000 37588 ns/op 13258 B/op 167 allocs/op
BenchmarkDateparseParseAny 500000 5752 ns/op 0 B/op 0 allocs/op
// Aarons Laptop Lenovo 900 Feb 2018
BenchmarkShotgunParse-4 50000 30045 ns/op 13136 B/op 169 allocs/op
BenchmarkParseAny-4 200000 8627 ns/op 144 B/op 3 allocs/op
@ -22,13 +18,26 @@ BenchmarkShotgunParse-8 50000 33940 ns/op 13136 B/op 169 allo
BenchmarkParseAny-8 200000 10146 ns/op 912 B/op 29 allocs/op
BenchmarkParseDateString-8 10000 123077 ns/op 208 B/op 13 allocs/op
// Klondike Dragon Dec 2023
cpu: 12th Gen Intel(R) Core(TM) i7-1255U
BenchmarkShotgunParse-12 62788 18113 ns/op 19448 B/op 474 allocs/op
BenchmarkParseAny-12 347020 3455 ns/op 48 B/op 2 allocs/op
BenchmarkBigShotgunParse-12 1226 951271 ns/op 1214937 B/op 27245 allocs/op
BenchmarkBigParseAny-12 4234 267893 ns/op 27492 B/op 961 allocs/op
BenchmarkBigParseIn-12 4032 280900 ns/op 30422 B/op 1033 allocs/op
BenchmarkBigParseRetryAmbiguous-12 4453 282475 ns/op 29558 B/op 1030 allocs/op
BenchmarkShotgunParseErrors-12 19240 62641 ns/op 67080 B/op 1679 allocs/op
BenchmarkParseAnyErrors-12 185677 6179 ns/op 752 B/op 23 allocs/op
BenchmarkBigParseAnyErrors-12 26688 44885 ns/op 480 B/op 94 allocs/op
BenchmarkParseAmbiguous-12 1590302 752.9 ns/op 296 B/op 7 allocs/op
BenchmarkParseWeekdayAndFullMonth-12 2141109 555.0 ns/op 16 B/op 2 allocs/op
*/
func BenchmarkShotgunParse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for _, dateStr := range testDates {
// This is the non dateparse traditional approach
parseShotgunStyle(dateStr)
_, _ = parseShotgunStyle(dateStr)
}
}
}
@ -37,11 +46,115 @@ func BenchmarkParseAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for _, dateStr := range testDates {
ParseAny(dateStr)
_, _ = ParseAny(dateStr)
}
}
}
func BenchmarkBigShotgunParse(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for _, t := range testInputs {
// This is the non dateparse traditional approach
_, _ = parseShotgunStyle(t.in)
}
}
}
func BenchmarkBigParseAny(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for _, t := range testInputs {
_, _ = ParseAny(t.in)
}
}
}
func BenchmarkBigParseIn(b *testing.B) {
b.ReportAllocs()
loc, _ := time.LoadLocation("America/New_York")
for i := 0; i < b.N; i++ {
for _, t := range testInputs {
_, _ = ParseIn(t.in, loc)
}
}
}
func BenchmarkBigParseRetryAmbiguous(b *testing.B) {
b.ReportAllocs()
opts := []ParserOption{RetryAmbiguousDateWithSwap(true)}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, t := range testInputs {
_, _ = ParseAny(t.in, opts...)
}
}
}
func BenchmarkShotgunParseErrors(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for _, t := range testParseErrors {
// This is the non dateparse traditional approach
_, _ = parseShotgunStyle(t.in)
}
}
}
func BenchmarkParseAnyErrors(b *testing.B) {
b.ReportAllocs()
opts := []ParserOption{SimpleErrorMessages(true)}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, t := range testParseErrors {
_, _ = ParseAny(t.in, opts...)
}
}
}
func BenchmarkBigParseAnyErrors(b *testing.B) {
b.ReportAllocs()
opts := []ParserOption{SimpleErrorMessages(true)}
// manufacture a bunch of different tests with random errors put in them
var testBigErrorInputs []string
for index, t := range testInputs {
b := []byte(t.in)
spread := 4 + (index % 4)
startingIndex := spread % len(b)
for i := startingIndex; i < len(b); i += spread {
b[i] = '?'
}
testBigErrorInputs = append(testBigErrorInputs, string(b))
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, in := range testBigErrorInputs {
_, err := ParseAny(in, opts...)
if err == nil {
panic(fmt.Sprintf("expected parsing to fail: %s", in))
}
}
}
}
func BenchmarkParseAmbiguous(b *testing.B) {
b.ReportAllocs()
opts := []ParserOption{RetryAmbiguousDateWithSwap(true)}
b.ResetTimer()
for i := 0; i < b.N; i++ {
MustParse("13/02/2014 04:08:09 +0000 UTC", opts...)
}
}
func BenchmarkParseWeekdayAndFullMonth(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
MustParse("Monday 02 December 2006 03:04:05 PM UTC")
}
}
/*
func BenchmarkParseDateString(b *testing.B) {
b.ReportAllocs()
@ -70,7 +183,7 @@ var (
"2014-04-26",
}
ErrDateFormat = fmt.Errorf("Invalid Date Format")
ErrDateFormat = fmt.Errorf("invalid date format")
timeFormats = []string{
// ISO 8601ish formats

View File

@ -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"
@ -169,4 +169,44 @@ Your Using time.Local set to location=America/New_York EDT
| ParseAny | time.Local = time.UTC | 2017-03-03 00:00:00 +0000 UTC | 2017-03-03 00:00:00 +0000 UTC day=5 |
+-------------+---------------------------+----------------------------------------------------+----------------------------------------------------+
# Automatically retry date formats that are ambiguous mm/dd vs dd/mm
$ ./dateparse --retry-ambiguous "28.09.2024"
Your Current time.Local zone is MDT
Layout String: dateparse.ParseFormat() => 02.01.2006
+-------------+-----------------------+----------------------------------------------------+----------------------------------------------------+
| method | Zone Source | Parsed | Parsed: t.In(time.UTC) |
+-------------+-----------------------+----------------------------------------------------+----------------------------------------------------+
| ParseIn | time.Local = nil | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC |
| ParseIn | time.Local = time.UTC | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC |
| ParseLocal | time.Local = nil | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC |
| ParseLocal | time.Local = time.UTC | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC |
| ParseStrict | time.Local = nil | this date has ambiguous mm/dd vs dd/mm type format | this date has ambiguous mm/dd vs dd/mm type format |
| ParseStrict | time.Local = time.UTC | this date has ambiguous mm/dd vs dd/mm type format | this date has ambiguous mm/dd vs dd/mm type format |
| ParseAny | time.Local = nil | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC day=6 |
| ParseAny | time.Local = time.UTC | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC day=6 |
+-------------+-----------------------+----------------------------------------------------+----------------------------------------------------+
# Force dates to be interpreted as day-first instead of month-first
$ ./dateparse --prefer-day-first "28.09.2024"
Your Current time.Local zone is MDT
Layout String: dateparse.ParseFormat() => 02.01.2006
+-------------+-----------------------+----------------------------------------------------+----------------------------------------------------+
| method | Zone Source | Parsed | Parsed: t.In(time.UTC) |
+-------------+-----------------------+----------------------------------------------------+----------------------------------------------------+
| ParseAny | time.Local = nil | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC day=6 |
| ParseAny | time.Local = time.UTC | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC day=6 |
| ParseIn | time.Local = nil | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC |
| ParseIn | time.Local = time.UTC | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC |
| ParseLocal | time.Local = nil | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC |
| ParseLocal | time.Local = time.UTC | 2024-09-28 00:00:00 +0000 UTC | 2024-09-28 00:00:00 +0000 UTC |
| ParseStrict | time.Local = nil | this date has ambiguous mm/dd vs dd/mm type format | this date has ambiguous mm/dd vs dd/mm type format |
| ParseStrict | time.Local = time.UTC | this date has ambiguous mm/dd vs dd/mm type format | this date has ambiguous mm/dd vs dd/mm type format |
+-------------+-----------------------+----------------------------------------------------+----------------------------------------------------+
```

View File

@ -6,17 +6,32 @@ import (
"os"
"time"
"github.com/itlightning/dateparse"
"github.com/scylladb/termtables"
"github.com/araddon/dateparse"
)
var (
timezone = ""
datestr = ""
timezone = ""
datestr = ""
retryAmbiguousDateWithSwap = false
preferDayFirst = false
parserOptions = []dateparse.ParserOption{}
)
func buildParserOptions() {
parserOptions = []dateparse.ParserOption{}
if retryAmbiguousDateWithSwap {
parserOptions = append(parserOptions, dateparse.RetryAmbiguousDateWithSwap(true))
}
if preferDayFirst {
parserOptions = append(parserOptions, dateparse.PreferMonthFirst(false))
}
}
func main() {
flag.StringVar(&timezone, "timezone", "", "Timezone aka `America/Los_Angeles` formatted time-zone")
flag.BoolVar(&retryAmbiguousDateWithSwap, "retry-ambiguous", false, "Retry ambiguous date/time formats (day-first vs month-first)")
flag.BoolVar(&preferDayFirst, "prefer-day-first", false, "Prefer day-first date format")
flag.Parse()
if len(flag.Args()) == 0 {
@ -25,13 +40,17 @@ func main() {
./dateparse "2009-08-12T22:15:09.99Z"
./dateparse --timezone="America/Denver" "2017-07-19 03:21:51+00:00"
./dateparse --prefer-day-first "28.09.2024"
./dateparse --retry-ambiguous "28.09.2024"
`)
return
}
buildParserOptions()
datestr = flag.Args()[0]
layout, err := dateparse.ParseFormat(datestr)
layout, err := dateparse.ParseFormat(datestr, parserOptions...)
if err != nil {
fatal(err)
}
@ -82,7 +101,7 @@ type parser func(datestr string, loc *time.Location, utc bool) string
func parseLocal(datestr string, loc *time.Location, utc bool) string {
time.Local = loc
t, err := dateparse.ParseLocal(datestr)
t, err := dateparse.ParseLocal(datestr, parserOptions...)
if err != nil {
return err.Error()
}
@ -93,7 +112,7 @@ func parseLocal(datestr string, loc *time.Location, utc bool) string {
}
func parseIn(datestr string, loc *time.Location, utc bool) string {
t, err := dateparse.ParseIn(datestr, loc)
t, err := dateparse.ParseIn(datestr, loc, parserOptions...)
if err != nil {
return err.Error()
}
@ -104,7 +123,7 @@ func parseIn(datestr string, loc *time.Location, utc bool) string {
}
func parseAny(datestr string, loc *time.Location, utc bool) string {
t, err := dateparse.ParseAny(datestr)
t, err := dateparse.ParseAny(datestr, parserOptions...)
if err != nil {
return err.Error()
}
@ -115,7 +134,7 @@ func parseAny(datestr string, loc *time.Location, utc bool) string {
}
func parseStrict(datestr string, loc *time.Location, utc bool) string {
t, err := dateparse.ParseStrict(datestr)
t, err := dateparse.ParseStrict(datestr, parserOptions...)
if err != nil {
return err.Error()
}

View File

@ -5,61 +5,108 @@ import (
"fmt"
"time"
"github.com/araddon/dateparse"
"github.com/itlightning/dateparse"
"github.com/scylladb/termtables"
)
var examples = []string{
// mon day year (time)
"May 8, 2009 5:57:51 PM",
"oct 7, 1970",
"oct 7, '70",
"oct. 7, 1970",
"oct. 7, 70",
"Mon Jan 2 15:04:05 2006",
"Mon Jan 2 15:04:05 MST 2006",
"Mon Jan 02 15:04:05 -0700 2006",
"Monday, 02-Jan-06 15:04:05 MST",
"Mon, 02 Jan 2006 15:04:05 MST",
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
"Mon, 02 Jan 2006 15:04:05 -0700",
"Mon 30 Sep 2018 09:09:09 PM UTC",
"Mon Aug 10 15:44:11 UTC+0100 2015",
"Thu, 4 Jan 2018 17:53:36 +0000",
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
"Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00)",
"September 17, 2012 10:09am",
"September 17, 2012 at 10:09am PST-08",
"September 17, 2012, 10:10:09",
"October 7, 1970",
"October 7th, 1970",
"Sept. 7, 1970 11:15:26pm",
"Sep 7 2009 11:15:26.123 PM PST",
"September 3rd, 2009 11:15:26.123456789pm",
"September 17 2012 10:09am",
"September 17, 2012, 10:10:09",
"Sep 17, 2012 at 10:02am (EST)",
// (PST-08 will have an offset of -0800, and a zone name of "PST")
"September 17, 2012 at 10:09am PST-08",
// (UTC-0700 has the same offset as -0700, and the returned zone name will be empty)
"September 17 2012 5:00pm UTC-0700",
"September 17 2012 5:00pm GMT-0700",
// (weekday) day mon year (time)
"7 oct 70",
"7 Oct 1970",
"7 September 1970 23:15",
"7 September 1970 11:15:26pm",
"03 February 2013",
"12 Feb 2006, 19:17",
"12 Feb 2006 19:17",
"14 May 2019 19:11:40.164",
"7 oct 70",
"7 oct 1970",
"03 February 2013",
"1 July 2013",
"2013-Feb-03",
// dd/Mon/yyy alpha Months
"06/Jan/2008:15:04:05 -0700",
"4th Sep 2012",
"1st February 2018 13:58:24",
"Mon, 02 Jan 2006 15:04:05 MST", // RFC1123
"Mon, 02 Jan 2006 15:04:05 -0700",
"Tue, 11 Jul 2017 16:28:13 +0200 (CEST)",
"Mon 30 Sep 2018 09:09:09 PM UTC",
"Sun, 07 Jun 2020 00:00:00 +0100",
"Wed, 8 Feb 2023 19:00:46 +1100 (AEDT)",
// ANSIC and UnixDate - weekday month day time year
"Mon Jan 2 15:04:05 2006",
"Mon Jan 2 15:04:05 MST 2006",
"Monday Jan 02 15:04:05 -0700 2006",
"Mon Jan 2 15:04:05.103786 2006",
// RubyDate - weekday month day time offset year
"Mon Jan 02 15:04:05 -0700 2006",
// ANSIC_GLIBC - weekday day month year time
"Mon 02 Jan 2006 03:04:05 PM UTC",
"Monday 02 Jan 2006 03:04:05 PM MST",
// weekday month day time timezone-offset year
"Mon Aug 10 15:44:11 UTC+0000 2015",
// git log default date format
"Thu Apr 7 15:13:13 2005 -0700",
// variants of git log default date format
"Thu Apr 7 15:13:13 2005 -07:00",
"Thu Apr 7 15:13:13 2005 -07:00 PST",
"Thu Apr 7 15:13:13 2005 -07:00 PST (Pacific Standard Time)",
"Thu Apr 7 15:13:13 -0700 2005",
"Thu Apr 7 15:13:13 -07:00 2005",
"Thu Apr 7 15:13:13 -0700 PST 2005",
"Thu Apr 7 15:13:13 -07:00 PST 2005",
"Thu Apr 7 15:13:13 PST 2005",
// Variants of the above with a (full time zone description)
"Fri Jul 3 2015 06:04:07 PST-0700 (Pacific Daylight Time)",
"Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time)",
"Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00)",
// year month day
"2013 May 2",
"2013 May 02 11:37:55",
// dd/Mon/year alpha Months
"06/Jan/2008 15:04:05 -0700",
// mm/dd/yy
"06/January/2008 15:04:05 -0700",
"06/Jan/2008:15:04:05 -0700", // ngnix-log
"06/January/2008:08:11:17 -0700",
// mm/dd/year (see also PreferMonthFirst and RetryAmbiguousDateWithSwap options)
"3/31/2014",
"03/31/2014",
"08/21/71",
"8/1/71",
"4/8/2014 22:05",
"04/08/2014 22:05",
"04/08/2014, 22:05",
"4/8/14 22:05",
"04/2/2014 03:00:51",
"8/8/1965 12:00:00 AM",
"8/8/1965 01:00:01 PM",
"8/8/1965 01:00 PM",
"8/8/1965 1:00 PM",
"8/8/1965 01:00 PM",
"8/8/1965 12:00 AM",
"8/8/1965 12:00:00AM",
"8/8/1965 01:00:01 PM",
"8/8/1965 01:00:01PM -0700",
"8/8/1965 13:00:01 -0700 PST",
"8/8/1965 01:00:01 PM -0700 PST",
"8/8/1965 01:00:01 PM -07:00 PST (Pacific Standard Time)",
"4/02/2014 03:00:51",
"03/19/2012 10:11:59",
"03/19/2012 10:11:59.3186369",
// mon/dd/year
"Oct/ 7/1970",
"Oct/03/1970 22:33:44",
"February/03/1970 11:33:44.555 PM PST",
// yyyy/mm/dd
"2014/3/31",
"2014/03/31",
@ -69,6 +116,78 @@ var examples = []string{
"2014/4/02 03:00:51",
"2012/03/19 10:11:59",
"2012/03/19 10:11:59.3186369",
// weekday, day-mon-yy time
"Fri, 03-Jul-15 08:08:08 CEST",
"Monday, 02-Jan-06 15:04:05 MST", // RFC850
"Monday, 02 Jan 2006 15:04:05 -0600",
"02-Jan-06 15:04:05 MST",
// RFC3339 - yyyy-mm-ddThh
"2006-01-02T15:04:05+0000",
"2009-08-12T22:15:09-07:00",
"2009-08-12T22:15:09",
"2009-08-12T22:15:09.988",
"2009-08-12T22:15:09Z",
"2009-08-12T22:15:09.52Z",
"2017-07-19T03:21:51:897+0100",
"2019-05-29T08:41-04", // no seconds, 2 digit TZ offset
// yyyy-mm-dd hh:mm:ss
"2014-04-26 17:24:37.3186369",
"2012-08-03 18:31:59.257000000",
"2014-04-26 17:24:37.123",
"2014-04-01 12:01am",
"2014-04-01 12:01:59.765 AM",
"2014-04-01 12:01:59,765",
"2014-04-01 22:43",
"2014-04-01 22:43:22",
"2014-12-16 06:20:00 UTC",
"2014-12-16 06:20:00 GMT",
"2014-04-26 05:24:37 PM",
"2014-04-26 13:13:43 +0800",
"2014-04-26 13:13:43 +0800 +08",
"2014-04-26 13:13:44 +09:00",
"2012-08-03 18:31:59.257000000 +0000 UTC",
"2015-09-30 18:48:56.35272715 +0000 UTC",
"2015-02-18 00:12:00 +0000 GMT", // golang native format
"2015-02-18 00:12:00 +0000 UTC",
"2015-02-08 03:02:00 +0300 MSK m=+0.000000001",
"2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001",
"2017-07-19 03:21:51+00:00",
"2017-04-03 22:32:14.322 CET",
"2017-04-03 22:32:14,322 CET",
"2017-04-03 22:32:14:322 CET",
"2018-09-30 08:09:13.123PM PMDT", // PMDT time zone
"2018-09-30 08:09:13.123 am AMT", // AMT time zone
"2014-04-26",
"2014-04",
"2014",
// yyyy-mm-dd(offset)
"2020-07-20+08:00",
"2020-07-20+0800",
// year-mon-dd
"2013-Feb-03",
"2013-February-03 09:07:08.123",
// dd-mon-year
"03-Feb-13",
"03-Feb-2013",
"07-Feb-2004 09:07:07 +0200",
"07-February-2004 09:07:07 +0200",
// dd-mm-year (this format (common in Europe) always puts the day first, regardless of PreferMonthFirst)
"28-02-02",
"28-02-02 15:16:17",
"28-02-2002",
"28-02-2002 15:16:17",
// mm.dd.yy (see also PreferMonthFirst and RetryAmbiguousDateWithSwap options)
"3.31.2014",
"03.31.14",
"03.31.2014",
"03.31.2014 10:11:59 MST",
"03.31.2014 10:11:59.3186369Z",
// year.mm.dd
"2014.03",
"2014.03.30",
"2014.03.30 08:33pm",
"2014.03.30T08:33:44.555 PM -0700 MST",
"2014.03.30-0600",
// yyyy:mm:dd
"2014:3:31",
"2014:03:31",
@ -78,58 +197,53 @@ var examples = []string{
"2014:4:02 03:00:51",
"2012:03:19 10:11:59",
"2012:03:19 10:11:59.3186369",
// Chinese
"2014年04月08日",
// yyyy-mm-ddThh
"2006-01-02T15:04:05+0000",
"2009-08-12T22:15:09-07:00",
"2009-08-12T22:15:09",
"2009-08-12T22:15:09.988",
"2009-08-12T22:15:09Z",
"2017-07-19T03:21:51:897+0100",
"2019-05-29T08:41-04", // no seconds, 2 digit TZ offset
// yyyy-mm-dd hh:mm:ss
"2014-04-26 17:24:37.3186369",
"2012-08-03 18:31:59.257000000",
"2014-04-26 17:24:37.123",
"2013-04-01 22:43",
"2013-04-01 22:43:22",
"2014-12-16 06:20:00 UTC",
"2014-12-16 06:20:00 GMT",
"2014-04-26 05:24:37 PM",
"2014-04-26 13:13:43 +0800",
"2014-04-26 13:13:43 +0800 +08",
"2014-04-26 13:13:44 +09:00",
"2012-08-03 18:31:59.257000000 +0000 UTC",
"2015-09-30 18:48:56.35272715 +0000 UTC",
"2015-02-18 00:12:00 +0000 GMT",
"2015-02-18 00:12:00 +0000 UTC",
"2015-02-08 03:02:00 +0300 MSK m=+0.000000001",
"2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001",
"2017-07-19 03:21:51+00:00",
"2014-04-26",
"2014-04",
"2014",
"2014-05-11 08:20:13,787",
// yyyy-mm-dd-07:00
"2020-07-20+08:00",
// mm.dd.yy
"3.31.2014",
"03.31.2014",
"08.21.71",
"2014.03",
"2014.03.30",
// yyyymmdd and similar
// mm:dd:yyyy (see also PreferMonthFirst and RetryAmbiguousDateWithSwap options)
"08:03:2012",
"08:04:2012 18:31:59+00:00",
// yyyymmdd and similar
"20140601",
"20140722105203",
// yymmdd hh:mm:yy mysql log
"20140722105203.364",
// Chinese
"2014年4月25日",
"2014年04月08日",
"2014年04月08日 19:17:22 -0700",
// RabbitMQ log format
"8-Mar-2018::14:09:27",
"08-03-2018::02:09:29 PM",
// yymmdd hh:mm:yy mysql log
// 080313 05:21:55 mysqld started
"171113 14:14:20",
"190910 11:51:49",
// unix seconds, ms, micro, nano
"1332151919",
"1384216367189",
"1384216367111222",
"1384216367111222333",
// syslog RFC3164 (and non-conformant variants)
"Apr 9 12:37:24",
"Apr 9 12:37:24-10",
"Apr 9 12:37:24-1000",
"Apr 9 12:37:24 UTC-10",
"Apr 9 12:37:24 MST",
"Apr 9 12:37:24 MST-07:00",
"Apr 9 12:37:24 TZ-10",
"Apr 9 12:37:24 TZ+02:00",
"Apr 9 12:37:24+10",
"Apr 9 12:37:24+10:00",
"Apr 9 12:37:24 CEST",
"Apr 9 12:37:24 CEST+0200",
"Apr 9 12:37:24 2025",
"Apr 9 12:37:24 2025 +02:00",
"Apr 9 2025 12:37:24",
"Apr 9 2025 12:37:24 -0700",
// syslog RFC5424 (and non-conformant variants)
"2025-04-09T12:37:24Z",
"2025-04-09T12:37:24.123Z",
"2025-04-09T12:37:24.123456Z",
"2025-04-09T12:37:24-10:00",
"2025-04-09T12:37:24.123 +0200",
"2025-04-09T12:37:24.123456 -0700 MDT",
}
var (
@ -164,115 +278,185 @@ func main() {
}
/*
+-------------------------------------------------------+-----------------------------------------+
| Input | Parsed, and Output as %v |
+-------------------------------------------------------+-----------------------------------------+
| May 8, 2009 5:57:51 PM | 2009-05-08 17:57:51 +0000 UTC |
| oct 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| oct 7, '70 | 1970-10-07 00:00:00 +0000 UTC |
| oct. 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| oct. 7, 70 | 1970-10-07 00:00:00 +0000 UTC |
| Mon Jan 2 15:04:05 2006 | 2006-01-02 15:04:05 +0000 UTC |
| Mon Jan 2 15:04:05 MST 2006 | 2006-01-02 15:04:05 +0000 MST |
| Mon Jan 02 15:04:05 -0700 2006 | 2006-01-02 15:04:05 -0700 -0700 |
| Monday, 02-Jan-06 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 +0200 |
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
| Mon 30 Sep 2018 09:09:09 PM UTC | 2018-09-30 21:09:09 +0000 UTC |
| Mon Aug 10 15:44:11 UTC+0100 2015 | 2015-08-10 15:44:11 +0000 UTC |
| Thu, 4 Jan 2018 17:53:36 +0000 | 2018-01-04 17:53:36 +0000 UTC |
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 GMT |
| Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00) | 2021-01-03 00:12:23 +0800 +0800 |
| September 17, 2012 10:09am | 2012-09-17 10:09:00 +0000 UTC |
| September 17, 2012 at 10:09am PST-08 | 2012-09-17 10:09:00 -0800 PST |
| September 17, 2012, 10:10:09 | 2012-09-17 10:10:09 +0000 UTC |
| October 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| October 7th, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| 12 Feb 2006, 19:17 | 2006-02-12 19:17:00 +0000 UTC |
| 12 Feb 2006 19:17 | 2006-02-12 19:17:00 +0000 UTC |
| 14 May 2019 19:11:40.164 | 2019-05-14 19:11:40.164 +0000 UTC |
| 7 oct 70 | 1970-10-07 00:00:00 +0000 UTC |
| 7 oct 1970 | 1970-10-07 00:00:00 +0000 UTC |
| 03 February 2013 | 2013-02-03 00:00:00 +0000 UTC |
| 1 July 2013 | 2013-07-01 00:00:00 +0000 UTC |
| 2013-Feb-03 | 2013-02-03 00:00:00 +0000 UTC |
| 06/Jan/2008:15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 06/Jan/2008 15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 3/31/2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03/31/2014 | 2014-03-31 00:00:00 +0000 UTC |
| 08/21/71 | 1971-08-21 00:00:00 +0000 UTC |
| 8/1/71 | 1971-08-01 00:00:00 +0000 UTC |
| 4/8/2014 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/08/2014 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 4/8/14 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/2/2014 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 8/8/1965 12:00:00 AM | 1965-08-08 00:00:00 +0000 UTC |
| 8/8/1965 01:00:01 PM | 1965-08-08 13:00:01 +0000 UTC |
| 8/8/1965 01:00 PM | 1965-08-08 13:00:00 +0000 UTC |
| 8/8/1965 1:00 PM | 1965-08-08 13:00:00 +0000 UTC |
| 8/8/1965 12:00 AM | 1965-08-08 00:00:00 +0000 UTC |
| 4/02/2014 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 03/19/2012 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 03/19/2012 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| 2014/3/31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014/03/31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014/4/8 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014/04/08 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014/04/2 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2014/4/02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2012/03/19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 2012/03/19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| 2014:3:31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014:03:31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014:4:8 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014:04:08 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014:04:2 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2014:4:02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2012:03:19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 2012:03:19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| 2014年04月08日 | 2014-04-08 00:00:00 +0000 UTC |
| 2006-01-02T15:04:05+0000 | 2006-01-02 15:04:05 +0000 UTC |
| 2009-08-12T22:15:09-07:00 | 2009-08-12 22:15:09 -0700 -0700 |
| 2009-08-12T22:15:09 | 2009-08-12 22:15:09 +0000 UTC |
| 2009-08-12T22:15:09.988 | 2009-08-12 22:15:09.988 +0000 UTC |
| 2009-08-12T22:15:09Z | 2009-08-12 22:15:09 +0000 UTC |
| 2017-07-19T03:21:51:897+0100 | 2017-07-19 03:21:51.897 +0100 +0100 |
| 2019-05-29T08:41-04 | 2019-05-29 08:41:00 -0400 -0400 |
| 2014-04-26 17:24:37.3186369 | 2014-04-26 17:24:37.3186369 +0000 UTC |
| 2012-08-03 18:31:59.257000000 | 2012-08-03 18:31:59.257 +0000 UTC |
| 2014-04-26 17:24:37.123 | 2014-04-26 17:24:37.123 +0000 UTC |
| 2013-04-01 22:43 | 2013-04-01 22:43:00 +0000 UTC |
| 2013-04-01 22:43:22 | 2013-04-01 22:43:22 +0000 UTC |
| 2014-12-16 06:20:00 UTC | 2014-12-16 06:20:00 +0000 UTC |
| 2014-12-16 06:20:00 GMT | 2014-12-16 06:20:00 +0000 UTC |
| 2014-04-26 05:24:37 PM | 2014-04-26 17:24:37 +0000 UTC |
| 2014-04-26 13:13:43 +0800 | 2014-04-26 13:13:43 +0800 +0800 |
| 2014-04-26 13:13:43 +0800 +08 | 2014-04-26 13:13:43 +0800 +0800 |
| 2014-04-26 13:13:44 +09:00 | 2014-04-26 13:13:44 +0900 +0900 |
| 2012-08-03 18:31:59.257000000 +0000 UTC | 2012-08-03 18:31:59.257 +0000 UTC |
| 2015-09-30 18:48:56.35272715 +0000 UTC | 2015-09-30 18:48:56.35272715 +0000 UTC |
| 2015-02-18 00:12:00 +0000 GMT | 2015-02-18 00:12:00 +0000 UTC |
| 2015-02-18 00:12:00 +0000 UTC | 2015-02-18 00:12:00 +0000 UTC |
| 2015-02-08 03:02:00 +0300 MSK m=+0.000000001 | 2015-02-08 03:02:00 +0300 +0300 |
| 2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001 | 2015-02-08 03:02:00.001 +0300 +0300 |
| 2017-07-19 03:21:51+00:00 | 2017-07-19 03:21:51 +0000 UTC |
| 2014-04-26 | 2014-04-26 00:00:00 +0000 UTC |
| 2014-04 | 2014-04-01 00:00:00 +0000 UTC |
| 2014 | 2014-01-01 00:00:00 +0000 UTC |
| 2014-05-11 08:20:13,787 | 2014-05-11 08:20:13.787 +0000 UTC |
| 2020-07-20+08:00 | 2020-07-20 00:00:00 +0800 +0800 |
| 3.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 08.21.71 | 1971-08-21 00:00:00 +0000 UTC |
| 2014.03 | 2014-03-01 00:00:00 +0000 UTC |
| 2014.03.30 | 2014-03-30 00:00:00 +0000 UTC |
| 20140601 | 2014-06-01 00:00:00 +0000 UTC |
| 20140722105203 | 2014-07-22 10:52:03 +0000 UTC |
| 171113 14:14:20 | 2017-11-13 14:14:20 +0000 UTC |
| 1332151919 | 2012-03-19 10:11:59 +0000 UTC |
| 1384216367189 | 2013-11-12 00:32:47.189 +0000 UTC |
| 1384216367111222 | 2013-11-12 00:32:47.111222 +0000 UTC |
| 1384216367111222333 | 2013-11-12 00:32:47.111222333 +0000 UTC |
+-------------------------------------------------------+-----------------------------------------+
+------------------------------------------------------------+-----------------------------------------+
| Input | Parsed, and Output as %v |
+------------------------------------------------------------+-----------------------------------------+
| May 8, 2009 5:57:51 PM | 2009-05-08 17:57:51 +0000 UTC |
| oct 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| oct 7, '70 | 1970-10-07 00:00:00 +0000 UTC |
| oct. 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| oct. 7, 70 | 1970-10-07 00:00:00 +0000 UTC |
| October 7, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| October 7th, 1970 | 1970-10-07 00:00:00 +0000 UTC |
| Sept. 7, 1970 11:15:26pm | 1970-09-07 23:15:26 +0000 UTC |
| Sep 7 2009 11:15:26.123 PM PST | 2009-09-07 23:15:26.123 +0000 PST |
| September 3rd, 2009 11:15:26.123456789pm | 2009-09-03 23:15:26.123456789 +0000 UTC |
| September 17 2012 10:09am | 2012-09-17 10:09:00 +0000 UTC |
| September 17, 2012, 10:10:09 | 2012-09-17 10:10:09 +0000 UTC |
| Sep 17, 2012 at 10:02am (EST) | 2012-09-17 10:02:00 +0000 EST |
| September 17, 2012 at 10:09am PST-08 | 2012-09-17 10:09:00 -0800 PST |
| September 17 2012 5:00pm UTC-0700 | 2012-09-17 17:00:00 -0700 -0700 |
| September 17 2012 5:00pm GMT-0700 | 2012-09-17 17:00:00 -0700 -0700 |
| 7 oct 70 | 1970-10-07 00:00:00 +0000 UTC |
| 7 Oct 1970 | 1970-10-07 00:00:00 +0000 UTC |
| 7 September 1970 23:15 | 1970-09-07 23:15:00 +0000 UTC |
| 7 September 1970 11:15:26pm | 1970-09-07 23:15:26 +0000 UTC |
| 03 February 2013 | 2013-02-03 00:00:00 +0000 UTC |
| 12 Feb 2006, 19:17 | 2006-02-12 19:17:00 +0000 UTC |
| 12 Feb 2006 19:17 | 2006-02-12 19:17:00 +0000 UTC |
| 14 May 2019 19:11:40.164 | 2019-05-14 19:11:40.164 +0000 UTC |
| 4th Sep 2012 | 2012-09-04 00:00:00 +0000 UTC |
| 1st February 2018 13:58:24 | 2018-02-01 13:58:24 +0000 UTC |
| Mon, 02 Jan 2006 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| Mon, 02 Jan 2006 15:04:05 -0700 | 2006-01-02 15:04:05 -0700 -0700 |
| Tue, 11 Jul 2017 16:28:13 +0200 (CEST) | 2017-07-11 16:28:13 +0200 +0200 |
| Mon 30 Sep 2018 09:09:09 PM UTC | 2018-09-30 21:09:09 +0000 UTC |
| Sun, 07 Jun 2020 00:00:00 +0100 | 2020-06-07 00:00:00 +0100 +0100 |
| Wed, 8 Feb 2023 19:00:46 +1100 (AEDT) | 2023-02-08 19:00:46 +1100 +1100 |
| Mon Jan 2 15:04:05 2006 | 2006-01-02 15:04:05 +0000 UTC |
| Mon Jan 2 15:04:05 MST 2006 | 2006-01-02 15:04:05 +0000 MST |
| Monday Jan 02 15:04:05 -0700 2006 | 2006-01-02 15:04:05 -0700 -0700 |
| Mon Jan 2 15:04:05.103786 2006 | 2006-01-02 15:04:05.103786 +0000 UTC |
| Mon Jan 02 15:04:05 -0700 2006 | 2006-01-02 15:04:05 -0700 -0700 |
| Mon 02 Jan 2006 03:04:05 PM UTC | 2006-01-02 15:04:05 +0000 UTC |
| Monday 02 Jan 2006 03:04:05 PM MST | 2006-01-02 15:04:05 +0000 MST |
| Mon Aug 10 15:44:11 UTC+0000 2015 | 2015-08-10 15:44:11 +0000 UTC |
| Thu Apr 7 15:13:13 2005 -0700 | 2005-04-07 15:13:13 -0700 -0700 |
| Thu Apr 7 15:13:13 2005 -07:00 | 2005-04-07 15:13:13 -0700 -0700 |
| Thu Apr 7 15:13:13 2005 -07:00 PST | 2005-04-07 15:13:13 -0700 PST |
| Thu Apr 7 15:13:13 2005 -07:00 PST (Pacific Standard Time) | 2005-04-07 15:13:13 -0700 PST |
| Thu Apr 7 15:13:13 -0700 2005 | 2005-04-07 15:13:13 -0700 -0700 |
| Thu Apr 7 15:13:13 -07:00 2005 | 2005-04-07 15:13:13 -0700 -0700 |
| Thu Apr 7 15:13:13 -0700 PST 2005 | 2005-04-07 15:13:13 -0700 PST |
| Thu Apr 7 15:13:13 -07:00 PST 2005 | 2005-04-07 15:13:13 -0700 PST |
| Thu Apr 7 15:13:13 PST 2005 | 2005-04-07 15:13:13 +0000 PST |
| Fri Jul 3 2015 06:04:07 PST-0700 (Pacific Daylight Time) | 2015-07-03 06:04:07 -0700 PST |
| Fri Jul 03 2015 18:04:07 GMT+0100 (GMT Daylight Time) | 2015-07-03 18:04:07 +0100 +0100 |
| Sun, 3 Jan 2021 00:12:23 +0800 (GMT+08:00) | 2021-01-03 00:12:23 +0800 +0800 |
| 2013 May 2 | 2013-05-02 00:00:00 +0000 UTC |
| 2013 May 02 11:37:55 | 2013-05-02 11:37:55 +0000 UTC |
| 06/Jan/2008 15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 06/January/2008 15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 06/Jan/2008:15:04:05 -0700 | 2008-01-06 15:04:05 -0700 -0700 |
| 06/January/2008:08:11:17 -0700 | 2008-01-06 08:11:17 -0700 -0700 |
| 3/31/2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03/31/2014 | 2014-03-31 00:00:00 +0000 UTC |
| 08/21/71 | 1971-08-21 00:00:00 +0000 UTC |
| 8/1/71 | 1971-08-01 00:00:00 +0000 UTC |
| 4/8/2014 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/08/2014 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/08/2014, 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 4/8/14 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 04/2/2014 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 8/8/1965 1:00 PM | 1965-08-08 13:00:00 +0000 UTC |
| 8/8/1965 01:00 PM | 1965-08-08 13:00:00 +0000 UTC |
| 8/8/1965 12:00 AM | 1965-08-08 00:00:00 +0000 UTC |
| 8/8/1965 12:00:00AM | 1965-08-08 00:00:00 +0000 UTC |
| 8/8/1965 01:00:01 PM | 1965-08-08 13:00:01 +0000 UTC |
| 8/8/1965 01:00:01PM -0700 | 1965-08-08 13:00:01 -0700 -0700 |
| 8/8/1965 13:00:01 -0700 PST | 1965-08-08 13:00:01 -0700 PST |
| 8/8/1965 01:00:01 PM -0700 PST | 1965-08-08 13:00:01 -0700 PST |
| 8/8/1965 01:00:01 PM -07:00 PST (Pacific Standard Time) | 1965-08-08 13:00:01 -0700 PST |
| 4/02/2014 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 03/19/2012 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 03/19/2012 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| Oct/ 7/1970 | 1970-10-07 00:00:00 +0000 UTC |
| Oct/03/1970 22:33:44 | 1970-10-03 22:33:44 +0000 UTC |
| February/03/1970 11:33:44.555 PM PST | 1970-02-03 23:33:44.555 +0000 PST |
| 2014/3/31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014/03/31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014/4/8 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014/04/08 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014/04/2 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2014/4/02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2012/03/19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 2012/03/19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| Fri, 03-Jul-15 08:08:08 CEST | 2015-07-03 08:08:08 +0000 CEST |
| Monday, 02-Jan-06 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| Monday, 02 Jan 2006 15:04:05 -0600 | 2006-01-02 15:04:05 -0600 -0600 |
| 02-Jan-06 15:04:05 MST | 2006-01-02 15:04:05 +0000 MST |
| 2006-01-02T15:04:05+0000 | 2006-01-02 15:04:05 +0000 UTC |
| 2009-08-12T22:15:09-07:00 | 2009-08-12 22:15:09 -0700 -0700 |
| 2009-08-12T22:15:09 | 2009-08-12 22:15:09 +0000 UTC |
| 2009-08-12T22:15:09.988 | 2009-08-12 22:15:09.988 +0000 UTC |
| 2009-08-12T22:15:09Z | 2009-08-12 22:15:09 +0000 UTC |
| 2009-08-12T22:15:09.52Z | 2009-08-12 22:15:09.52 +0000 UTC |
| 2017-07-19T03:21:51:897+0100 | 2017-07-19 03:21:51.897 +0100 +0100 |
| 2019-05-29T08:41-04 | 2019-05-29 08:41:00 -0400 -0400 |
| 2014-04-26 17:24:37.3186369 | 2014-04-26 17:24:37.3186369 +0000 UTC |
| 2012-08-03 18:31:59.257000000 | 2012-08-03 18:31:59.257 +0000 UTC |
| 2014-04-26 17:24:37.123 | 2014-04-26 17:24:37.123 +0000 UTC |
| 2014-04-01 12:01am | 2014-04-01 00:01:00 +0000 UTC |
| 2014-04-01 12:01:59.765 AM | 2014-04-01 00:01:59.765 +0000 UTC |
| 2014-04-01 12:01:59,765 | 2014-04-01 12:01:59.765 +0000 UTC |
| 2014-04-01 22:43 | 2014-04-01 22:43:00 +0000 UTC |
| 2014-04-01 22:43:22 | 2014-04-01 22:43:22 +0000 UTC |
| 2014-12-16 06:20:00 UTC | 2014-12-16 06:20:00 +0000 UTC |
| 2014-12-16 06:20:00 GMT | 2014-12-16 06:20:00 +0000 GMT |
| 2014-04-26 05:24:37 PM | 2014-04-26 17:24:37 +0000 UTC |
| 2014-04-26 13:13:43 +0800 | 2014-04-26 13:13:43 +0800 +0800 |
| 2014-04-26 13:13:43 +0800 +08 | 2014-04-26 13:13:43 +0800 +0800 |
| 2014-04-26 13:13:44 +09:00 | 2014-04-26 13:13:44 +0900 +0900 |
| 2012-08-03 18:31:59.257000000 +0000 UTC | 2012-08-03 18:31:59.257 +0000 UTC |
| 2015-09-30 18:48:56.35272715 +0000 UTC | 2015-09-30 18:48:56.35272715 +0000 UTC |
| 2015-02-18 00:12:00 +0000 GMT | 2015-02-18 00:12:00 +0000 GMT |
| 2015-02-18 00:12:00 +0000 UTC | 2015-02-18 00:12:00 +0000 UTC |
| 2015-02-08 03:02:00 +0300 MSK m=+0.000000001 | 2015-02-08 03:02:00 +0300 MSK |
| 2015-02-08 03:02:00.001 +0300 MSK m=+0.000000001 | 2015-02-08 03:02:00.001 +0300 MSK |
| 2017-07-19 03:21:51+00:00 | 2017-07-19 03:21:51 +0000 UTC |
| 2017-04-03 22:32:14.322 CET | 2017-04-03 22:32:14.322 +0000 CET |
| 2017-04-03 22:32:14,322 CET | 2017-04-03 22:32:14.322 +0000 CET |
| 2017-04-03 22:32:14:322 CET | 2017-04-03 22:32:14.322 +0000 CET |
| 2018-09-30 08:09:13.123PM PMDT | 2018-09-30 20:09:13.123 +0000 PMDT |
| 2018-09-30 08:09:13.123 am AMT | 2018-09-30 08:09:13.123 +0000 AMT |
| 2014-04-26 | 2014-04-26 00:00:00 +0000 UTC |
| 2014-04 | 2014-04-01 00:00:00 +0000 UTC |
| 2014 | 2014-01-01 00:00:00 +0000 UTC |
| 2020-07-20+08:00 | 2020-07-20 00:00:00 +0800 +0800 |
| 2020-07-20+0800 | 2020-07-20 00:00:00 +0800 +0800 |
| 2013-Feb-03 | 2013-02-03 00:00:00 +0000 UTC |
| 2013-February-03 09:07:08.123 | 2013-02-03 09:07:08.123 +0000 UTC |
| 03-Feb-13 | 2013-02-03 00:00:00 +0000 UTC |
| 03-Feb-2013 | 2013-02-03 00:00:00 +0000 UTC |
| 07-Feb-2004 09:07:07 +0200 | 2004-02-07 09:07:07 +0200 +0200 |
| 07-February-2004 09:07:07 +0200 | 2004-02-07 09:07:07 +0200 +0200 |
| 28-02-02 | 2002-02-28 00:00:00 +0000 UTC |
| 28-02-02 15:16:17 | 2002-02-28 15:16:17 +0000 UTC |
| 28-02-2002 | 2002-02-28 00:00:00 +0000 UTC |
| 28-02-2002 15:16:17 | 2002-02-28 15:16:17 +0000 UTC |
| 3.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03.31.14 | 2014-03-31 00:00:00 +0000 UTC |
| 03.31.2014 | 2014-03-31 00:00:00 +0000 UTC |
| 03.31.2014 10:11:59 MST | 2014-03-31 10:11:59 +0000 MST |
| 03.31.2014 10:11:59.3186369Z | 2014-03-31 10:11:59.3186369 +0000 UTC |
| 2014.03 | 2014-03-01 00:00:00 +0000 UTC |
| 2014.03.30 | 2014-03-30 00:00:00 +0000 UTC |
| 2014.03.30 08:33pm | 2014-03-30 20:33:00 +0000 UTC |
| 2014.03.30T08:33:44.555 PM -0700 MST | 2014-03-30 20:33:44.555 -0700 MST |
| 2014.03.30-0600 | 2014-03-30 00:00:00 -0600 -0600 |
| 2014:3:31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014:03:31 | 2014-03-31 00:00:00 +0000 UTC |
| 2014:4:8 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014:04:08 22:05 | 2014-04-08 22:05:00 +0000 UTC |
| 2014:04:2 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2014:4:02 03:00:51 | 2014-04-02 03:00:51 +0000 UTC |
| 2012:03:19 10:11:59 | 2012-03-19 10:11:59 +0000 UTC |
| 2012:03:19 10:11:59.3186369 | 2012-03-19 10:11:59.3186369 +0000 UTC |
| 08:03:2012 | 2012-08-03 00:00:00 +0000 UTC |
| 08:04:2012 18:31:59+00:00 | 2012-08-04 18:31:59 +0000 UTC |
| 20140601 | 2014-06-01 00:00:00 +0000 UTC |
| 20140722105203 | 2014-07-22 10:52:03 +0000 UTC |
| 20140722105203.364 | 2014-07-22 10:52:03.364 +0000 UTC |
| 2014年4月25日 | 2014-04-25 00:00:00 +0000 UTC |
| 2014年04月08日 | 2014-04-08 00:00:00 +0000 UTC |
| 2014年04月08日 19:17:22 -0700 | 2014-04-08 19:17:22 -0700 -0700 |
| 8-Mar-2018::14:09:27 | 2018-03-08 14:09:27 +0000 UTC |
| 08-03-2018::02:09:29 PM | 2018-03-08 14:09:29 +0000 UTC |
| 171113 14:14:20 | 2017-11-13 14:14:20 +0000 UTC |
| 190910 11:51:49 | 2019-09-10 11:51:49 +0000 UTC |
| 1332151919 | 2012-03-19 10:11:59 +0000 UTC |
| 1384216367189 | 2013-11-12 00:32:47.189 +0000 UTC |
| 1384216367111222 | 2013-11-12 00:32:47.111222 +0000 UTC |
| 1384216367111222333 | 2013-11-12 00:32:47.111222333 +0000 UTC |
+------------------------------------------------------------+-----------------------------------------+
*/

15
go.mod
View File

@ -1,9 +1,16 @@
module github.com/araddon/dateparse
module github.com/itlightning/dateparse
go 1.12
go 1.20
require (
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.10.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

23
go.sum
View File

@ -1,18 +1,17 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
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/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
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/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4 h1:8qmTC5ByIXO3GP/IzBkxcZ/99VITvnIETDhdFz/om7A=
github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff