| Crates.io | date_format_parser |
| lib.rs | date_format_parser |
| version | 0.1.0 |
| created_at | 2024-11-13 21:17:09.187124+00 |
| updated_at | 2024-11-13 21:17:09.187124+00 |
| description | A parser standardizing date and date-time strings into ISO 8601 format. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1447090 |
| size | 33,966 |
Date Format Parser project is designed to parse date and date-time strings into a standard ISO 8601 format. It supports multiple date formats, optional time components, and flexible separators.
cargo run -- <input>
Displays usage information.
cargo run -- --credits
Shows project credits.
cargo run -- "2000/12/20 14:30:45.123"
Parses the given input and outputs the result in ISO 8601 format:
"2000-12-20T14:30:45.123"
Dates can optionally include times, separated by space:
The parsing process is built on a robust Pest grammar defined in grammar.pest. Here’s how the tool parses the input:
The input string is validated against a custom grammar defined in the Pest library. The grammar supports:
The grammar uses rules to define valid date and time formats:
date_time = { date ~ (space ~ time)? }
date = { year_month_day | day_month_year | month_day_year }
year_month_day = { year ~ separator ~ month ~ separator ~ day }
day_month_year = { day ~ separator ~ month ~ separator ~ year }
month_day_year = { month ~ separator ~ day ~ separator ~ year }
year = { '1'..'9' ~ ASCII_DIGIT ~ ASCII_DIGIT ~ ASCII_DIGIT }
month = { ("0" ~ '1'..'9') | ("1" ~ '0'..'2') }
day = { ("0" ~ '1'..'9') | ('1'..'2' ~ ASCII_DIGIT) | ("3" ~ '0'..'1') }
time = { hour_24 ~ ":" ~ minute ~ (":" ~ second ~ ("." ~ millisecond)?)? }
hour_24 = { "0" ~ ASCII_DIGIT | "1" ~ ASCII_DIGIT | "2" ~ ('0'..'3') }
minute = { ('0'..'5' ~ ASCII_DIGIT) }
second = { ('0'..'5' ~ ASCII_DIGIT) }
millisecond = { ASCII_DIGIT ~ ASCII_DIGIT ~ ASCII_DIGIT }
separator = { "-" | "/" | "." }
space = { " " }
This project is licensed under the MIT License.