10 releases

0.3.4 Apr 6, 2024
0.3.3 Feb 13, 2024
0.3.2 Aug 3, 2023
0.2.1 Jun 4, 2023
0.1.1 May 7, 2023

#144 in Date and time

Download history 20/week @ 2024-02-08 19/week @ 2024-02-15 12/week @ 2024-02-22 7/week @ 2024-02-29 5/week @ 2024-03-07 4/week @ 2024-03-14 8/week @ 2024-03-28 168/week @ 2024-04-04 138/week @ 2024-04-11

314 downloads per month

MIT license

1.5MB
46K SLoC

C 30K SLoC // 0.0% comments C++ 14K SLoC // 0.0% comments PHP 1K SLoC // 0.0% comments OCaml 411 SLoC // 0.9% comments Rust 271 SLoC // 0.0% comments Bitbake 249 SLoC // 0.1% comments

Timelib for Rust

Crates.io Build Status docs.rs Code Coverage Funding Status

Timelib for Rust is a small Rust wrapper around the timelib library that is used to power PHP and MongoDB.

Installation

You can install with:

cargo add timelib

Usage

let tz = timelib::Timezone::parse("America/Chicago").expect("Error parsing timezone!");
timelib::strtotime("tomorrow", None, &tz);
timelib::strtotime("next tuesday", Some(1654318823), &tz);

View the tests for more examples.

Optional Features

The genereated re2c outputs are bundled and automatically used. If you wish to generate these files yourself, do the following:

  1. Install re2c. You can install it easily on all major platforms:
    • Linux: apt-get install re2c
    • Mac: brew install re2c
    • Windows: choco install re2c
    • From source: re2c.org
  2. Enable the re2c feature:
    • timelib = { version = "0.2.0", features = ["re2c"] }

Building

Make sure to check out all submodules.

Initial clone:

git clone --recurse-submodules https://github.com/westy92/timelib-rust

Post-clone:

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.

Updating the submodule version

git submodule update --remote

Make sure to regenerate the re2c outputs and copy them to pregenerated/.

cd ext/timelib/
make parse_date.c parse_iso_intervals.c
cp parse_date.c ../../pregenerated/
cp parse_iso_intervals.c ../../pregenerated/

Publishing

Remove --dry-run to publish for real.

cargo publish --dry-run

No runtime deps