2 releases

0.1.1 Sep 8, 2023
0.1.0 Sep 8, 2023

#2239 in Parser implementations

Download history 306/week @ 2024-07-25 315/week @ 2024-08-01 110/week @ 2024-08-08 88/week @ 2024-08-15 309/week @ 2024-08-22 270/week @ 2024-08-29 308/week @ 2024-09-05 378/week @ 2024-09-12 349/week @ 2024-09-19 297/week @ 2024-09-26 395/week @ 2024-10-03 277/week @ 2024-10-10 519/week @ 2024-10-17 502/week @ 2024-10-24 575/week @ 2024-10-31 393/week @ 2024-11-07

2,024 downloads per month
Used in 8 crates (3 directly)

Apache-2.0

16KB
326 lines

flexible-time

crates.io docs.rs CI

Time formats can be tricky. And parsing them even more so. However, in some cases you just don't want to bother the user with that. Especially when it comes command line applications.

The Problem

I need a command line argument --since, which allows the user to provide a year, or specific minute of a day. Either one is fine.

This crate can do it.

Filling the gaps

The timestamp will be parsed, but have gaps (like month, day). As can be different expectations on how to fill those gaps. The primary motivation for this crate was a "since" timestamp, so the strategy for that would be to fill missing components with the minimal value. That's implemented using the StartTimestamp.

Currently, there is no timezone handling, it defaults to UTC.

Formats

For timestamps, the following formats can be used:

Input Start timestamp
2023 2023-01-01 00:00:00 UTC
2023-02 2023-02-01 00:00:00 UTC
2023-02-03 2023-02-03 00:00:00 UTC
2023-02-03 16 2023-02-03 16:00:00 UTC
2023-02-03 16:05 2023-02-03 16:05:00 UTC
2023-02-03 16:05:06 2023-02-03 16:05:06 UTC

Dependencies

~745KB
~13K SLoC