tiffany352 / rink-rs

Unit conversion tool and library written in rust
https://rinkcalc.app/about
GNU General Public License v3.0
406 stars 28 forks source link

Date range checking #160

Closed tiffany352 closed 3 months ago

tiffany352 commented 3 months ago

Dates have no range checking which makes parsing them slightly unreliable and causes weird error messages like this:

> #25:00#
Most likely pattern `hour12:min[:sec] meridiem[ offset]` failed: Expected ` `, got eof

Additionally, large numbers cause a panic:

> #9999999999#
Panic: The application panicked (crashed).
Message:  called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
Location: core/src/parsing/datetime.rs:117

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

This PR adds range checks. I also cleaned up the code a little.