Timelib for Rust is a small Rust wrapper around the timelib library that is used to power PHP and MongoDB.
You can install with:
bash
cargo add timelib
rust
let tz = timelib::Timezone::parse("America/Chicago".into()).expect("Error parsing timezone!");
timelib::strtotime("tomorrow".into(), None, &tz);
timelib::strtotime("next tuesday".into(), Some(1654318823), &tz);
View the tests for more examples.
The genereated re2c
outputs are bundled and automatically used. If you wish to generate these files yourself, do the following:
re2c
. You can install it easily on all major platforms:
apt-get install re2c
brew install re2c
choco install re2c
re2c
feature:
timelib = { version = "0.2.0", features = ["re2c"] }
Make sure to check out all submodules.
Initial clone:
bash
git clone --recurse-submodules https://github.com/westy92/timelib-rust
Post-clone:
bash
git submodule init && git submodule update
You should now be able to run cargo build
and cargo test
.
If using the re2c
feature, make sure to install re2c
as described above. i.e. cargo test --features re2c
.
bash
git submodule update --remote
Make sure to regenerate the re2c outputs:
bash
cd ext/timelib/
make parse_date.c parse_iso_intervals.c
Copy them to pregenerated/
.
Remove --dry-run
to publish for real.
bash
cargo publish --dry-run