parsedate
This utility tries to brute force match a time/date against a hierarchy of possible formats in order to be able to broadly accept, and parse a wide range of date specifications.
It iterates through a list for formats, attempting to match against each date specification in turn, until either a match is found or the list is exhausted. The current set of formats is:
- Time::Format::YAML_DATE
- Time::Format::ISO_8601_DATE_TIME
- Time::Format::ISO_8601_DATE
- Time::Format::ISO_8601_TIME
- Time::Format::RFC_2822
- Time::Format::RFC_3339
- Time::Format::HTTP_DATE
- ParseDate::Format::UsMil
Installation
-
Add the dependency to your
shard.yml
:dependencies: parsedate: github: wyhaines/ParseDate.cr
-
Run
shards install
Usage
require "parse_date"
dt = ParseDate.parse("2020-07-20") dt = ParseDate.parse("2008-04-17 08:55:11.842682 -06:00")
See the spec file for many examples of parseable dates.
Development
This library is simple and inefficient in its operation. It would be nice to have an actual date parser that would intelligently attempt to figure out a date in order to produce a Time without utilizing a brute force approach. Someday...
Contributing
- Fork it (https://github.com/wyhaines/parsedate/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Kirk Haines - creator and maintainer