4 releases

0.1.3 Feb 18, 2024
0.1.2 Feb 15, 2024
0.1.1 Feb 13, 2024
0.1.0 Jan 22, 2024

#239 in Date and time

27 downloads per month

MIT license

29KB
842 lines

Langtime - Parsing dates in rust

This library is a personal project, currently in development, that allows rust programmers to parse dates written in the english language, both absolute and relative. These are some examples of dates that you can currently parse:

  • 2024-01-01 at 20:15
  • 28/02/2024 at 10 a.m.
  • 25 minutes ago

Why creating this repo when chrono-english already exists? Well for two reasons. First of all, I didn't knew it existed. Second, there are some formats, or combination thereof, that are not parsable with chrono_english.

This library uses nom, which makes it extremely easy to add new formats to the parsable inputs.

Next goals

  • Expand allowed tokens to separate parts of sentences
  • Correct month and year calculation
  • Implement unit tests
  • Add missing time format
  • Cleanup text before parsing
  • Add configuration for english dialects (UK/US)
  • Add configuration to force matching to the full string

Parsable data

Dates

  • 2024-01-20 (ISO)
  • 20/01/2024
  • yesterday / tomorrow
  • 01/2024 (beginning of the month)
  • january 2024 (same as above)

Times

  • 17:00
  • 17:00:30
  • 5 p.m. / 5pm
  • 8 o'clock / half past 9 / a quarter to 10

Relative times and dates

  • in 5 hours
  • 8 minutes ago
  • 2 hours, 8 minutes and 10 seconds ago
  • last friday
  • next tuesday
  • saturday / this saturday
  • 2 days ago
  • in 3 months *

* months and years are currently not calculated correctly: a month is considered as 4 weeks, a year as 365 days.

Full dates and times

  • 2024-01-01T20:30:10
  • yesterday at 17:00
  • tomorrow at 8 p.m.
  • 2 days ago at 5 a.m.
  • last friday at 9:00

Dependencies

~2MB
~35K SLoC