ParseDate.cr v0.1.2

This is a small library that attempts to parse a wide variety of date formats with a single call.

parsedate

ParseDate.cr CI GitHub release GitHub commits since latest release (by SemVer)

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:

  1. Time::Format::YAML_DATE
  2. Time::Format::ISO_8601_DATE_TIME
  3. Time::Format::ISO_8601_DATE
  4. Time::Format::ISO_8601_TIME
  5. Time::Format::RFC_2822
  6. Time::Format::RFC_3339
  7. Time::Format::HTTP_DATE
  8. ParseDate::Format::UsMil

Installation

  1. Add the dependency to your shard.yml:
    dependencies:
      parsedate:
        github: wyhaines/ParseDate.cr
    
  2. 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

  1. Fork it (https://github.com/wyhaines/parsedate/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

GitHub code size in bytes GitHub issues

Repository

ParseDate.cr

Owner
Statistic
  • 4
  • 0
  • 1
  • 2
  • 1
  • 7 months ago
  • March 19, 2021
License

Apache License 2.0

Links
Synced at

Fri, 26 Apr 2024 00:50:37 GMT

Languages