https://github.com/ctron/flexible-time
A library to parse timestamps in a flexible format
https://github.com/ctron/flexible-time
Last synced: 3 months ago
JSON representation
A library to parse timestamps in a flexible format
- Host: GitHub
- URL: https://github.com/ctron/flexible-time
- Owner: ctron
- License: apache-2.0
- Created: 2023-09-08T09:04:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-08T11:35:02.000Z (over 2 years ago)
- Last Synced: 2025-09-30T08:56:17.175Z (8 months ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flexible-time
[](https://crates.io/crates/flexible-time)
[](https://docs.rs/flexible-time)
[](https://github.com/ctron/flexible-time/actions?query=workflow%3A%22CI%22)
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` |