Open klondikedragon opened 8 months ago
Great work @klondikedragon
this is great work @klondikedragon! Now, this repo hasn't seen much movement in years, do you think we should start using a fork? should we use yours?
I would vote that we use his, we should see if it qualifies for https://github.com/avelino/awesome-go
In some further testing, I found that weekday prefixes only worked for some date formats, but not for others. So that is fixed now. As a side effect (benefit?), leading whitespace is now allowed/ignored.
Let's see if @araddon has feedback and/or is interested in merging this PR (it's a pretty big change and changes the philosophy a bit to have validation, and also makes the code a little more complex in favor of performance). The changes are large enough now it could break backwards compatibility, so in the very least it should deserve a new major version IMO.
Although I don't want to fork something lightly, since we haven't heard any feedback from @araddon for a few years, it could definitely make sense to go ahead. If there is no comment after the holidays, I think it would make sense to go ahead and fork. This package is a key part of freeform date parsing in the "automatic structured field extraction" logic being built for IT Lightning (this new cloud-based log management platform I'm building). Given that's the case, the IT Lightning org would be willing to maintain the forked repo and work with community issues/contributions, since we're motivated to have best-in-class date recognition & parsing in the log ingestion pipeline. The license would remain the same of course.
The community contributions would help us improve our date parsing, we'd be motivated to put energy into it to keep our date parsing bug-free and comprehensive, and community use of the package might help us get a little exposure to devs/SREs who might become interested in our log management solution. So it should benefit everyone.
All feedback is welcome. What do ya'll think of this proposed plan?
great work @klondikedragon . How can i start using this?
I'll go ahead and fork this package. I'm renaming the main branch as part of that.
The fork is complete and published as v0.1.0
-- again, a huge thanks to @araddon for authoring and maintaining this package for so many years!
The fork is available using go get github.com/itlightning/dateparse
-- issues and PRs are welcome.
@elliot40404 @arran4 @jmdacruz -- see what you think and how this updated package works! If this looks good and after incorporating feedback, I think I'll publish a v1.0.0 at some point soon. I'm also curious to get feedback on my log management project too, check out the site/discord if you're interested. Thanks!
This package is amazing and hugely popular, and has been the best package for automatic date parsing in go for years! β
Thanks @araddon for crafting this package with love over the years!!
I've been using this while developing a new cloud-based log aggregation/search/visualization product, and I've found that there are three major opportunities for improvement for my particular use case:
This PR addresses all 3 opportunities:
SimpleErrorMessages
option was added (off by default) that greatly speeds up the case where a string does not match a known format -- with the option on, this case is now 4x faster and produces almost no allocations.In the process of going through the state machine comprehensively for validation, redundant code/states were merged, and support was added for certain edge cases (for example, some date formats did not support being followed by times).
The example and README.md were updated to incorporate all of the newly supported formats and edge cases. More details on how to properly interpret returned location information with respect to abbreviated timezones was added.
BREAKING -- the package now requires go >= 1.20 to support memory optimizations converting from
[]byte
tostring
in key places.A huge thanks to all who posted issues and contributed PRs -- while the PRs were unable to be merged directly because the validation changes were so major, the ideas of all these contributions and the associated test cases were incorporated. Here's credit for all of the issues fixes and contributions in this PR as well as a summary of additional fixes added:
"1.jpg"
incorrectly parsed as valid - fixed by comprehensive validationThu Jan 28 2021 15:28:21 GMT+0000
formatyyyy mon dd
format - adapt https://github.com/araddon/dateparse/pull/142 by @dferstayyyyymmddhhmmss.SSS
format - adapt https://github.com/araddon/dateparse/pull/144 by @dferstay2017-04-03 22:32:14.322 CET
)Sun, 07 Jun 2020 00:00:00 +0100
format1 April 2022 23:59
format (time after certain date formats)mm.dd.yyyy (time)
- adapted https://github.com/araddon/dateparse/pull/133 by @mehanizm (also fixes https://github.com/araddon/dateparse/issues/91 and https://github.com/araddon/dateparse/issues/28)PMDT
andAMT
time zones and validate that AM/PM indicators only appear at most oncedd[th,nd,st,rd] Month yyyy
format - adapt https://github.com/araddon/dateparse/pull/128 by @krhubert(time) UTC[+-]NNNN
mm/dd/yyyy, hh:mm:ss
format - adapt https://github.com/araddon/dateparse/pull/156 by @BrianLeishmanyyyy.mm.dd (time)
format - adapt https://github.com/araddon/dateparse/pull/134 by @jmdacruz, and add cases expected to fail toTestParseErrors
unit testThu Apr 7 15:13:13 2005 -0700
) - adapt commit https://github.com/araddon/dateparse/pull/92/commits/99d9682a1cbe7a14975b5b71704af8847c2684f9 from https://github.com/araddon/dateparse/pull/92 by @jiangxin (merge timeWsYearOffset case and add validation)dd-mon-yyyy::hh:mm:ss
) - adapt https://github.com/araddon/dateparse/pull/122 by @bizy01mon/dd/yyyy
format, e.g.,Oct/31/1970
dd-month-year
formatyyyy-mon-dd
to allow times to follow it. Also allow full month name instead of just abbreviated.mm:dd:yyyy
formatMonday January 4th, 2017
)mm.dd.yyyy (time)
formatmm/dd
formats that start with a weekdayAlso adds tests to verify that the following stay fixed:
190910 11:51:49