timeflow

Crates.iotimeflow
lib.rstimeflow
version1.0.2
created_at2025-11-26 12:54:46.522024+00
updated_at2025-11-26 16:51:04.54713+00
descriptionErgonomic time handling (and traveling!) library with builder patterns, custom formatting, and seamless serialization for Date, Time, and DateTime operations
homepagehttps://github.com/ZialeHub/timeflow
repositoryhttps://github.com/ZialeHub/timeflow
max_upload_size
id1951354
size115,313
Ziale (ZialeHub)

documentation

README

ci

โ“ What is it?

Timeflow is a rust library designed to make time management easy.
It encapsulates commonly used libs such as chrono and adds up nice features.

Timeflow allows to create, update, compare and display custom formats of Time, Date or Datetime with ease, while setting default de/serialization and timezone options.

๐Ÿ”ญ What is our vision for this project?

Replace the usage of any other time-related library.

๐Ÿšจ What problem does it solve?

Time management is hard: setting up, operations, de/serialization, timezones... Timeflow provides a simple API relying on the builder pattern, to easily perform all imaginable operations.

๐ŸŽฏ Who is it for?

Developers.

  • Whenever you want to perform time-related operations.

  • Whenever you want to use serde on time-related strings and fields.

  • As a full replacement for the chrono library.

โœจ Features

By default span can be used to manage time, date or datetime, but you're free to select features for your app.

  • (Default)["full"]
  • ["time"]
  • ["date"]
  • ["datetime"]

๐Ÿš€ Usage

Run cargo add timeflow to your crate.

Each enum represents a different unit of time:

  • TimeUnit::Hour/Minute/Second
  • DateUnit::Year/Month/Day
  • DateTimeUnit::Year/Month/Day/Hour/Minute/Second

Builder

We provide a SpanBuilder to set a custom date format. This leads to less boilerplate for each date calls, and improved consistency through the entire application. Formats are defined based on a strftime inspired date and time formatting syntax.

Here is the default format for each type:

  • Time => "%H:%M:%S"
  • Date => "%Y-%m-%d"
  • DateTime => format!("{} {}", BASE_DATE_FORMAT, BASE_TIME_FORMAT)

๐Ÿ‘€ Examples

let _span = crate::builder::SpanBuilder::builder()
    .date_format("%d %m %Y")
    .time_format("T%H:%M:%SZ.000")
    .datetime_format("%Y-%m-%d %H:%M:%S")
    .build();

let mut time = Time::build("T23:17:12Z.000")?;

time.update(TimeUnit::Hour, 1)?;
assert_eq!(time.to_string(), "T00:17:12Z.000");

let mut datetime = DateTime::build("2024-10-31 06:32:28")?;

datetime.update(DateTimeUnit::Month, 1)?;
assert_eq!(datetime.to_string(), "2024-11-30 06:32:28");

assert!(datetime.matches(DateTimeUnit::Year, 2024));
assert!(datetime.matches(DateTimeUnit::Hour, 6));
assert!(datetime.matches(DateTimeUnit::Day, 30));

let previous_datetime = DateTime::build("2022-01-22 06:32:28")?;
let elapsed = datetime.elapsed(&previous_datetime);
assert_eq!(elapsed, TimeDelta::try_days(1043).unwrap());

let year_elapsed = datetime.unit_elapsed(DateTimeUnit::Year, &previous_datetime);
assert_eq!(year_elapsed, 2);

let is_in_future = previous_datetime.is_in_future()?;
assert!(!is_in_future);

eprintln!("DateTime == '{}'", datetime);
// "DateTime == '2024-11-30 06:32:28'"

๐Ÿค Contributing

Please always perform the following checks before committing:

  1. โš™๏ธ cargo build --workspace --all --all-features --tests
  2. ๐Ÿงผ cargo fmt --all
  3. ๐Ÿฉบ cargo clippy --workspace --all --all-features --tests -- -D warnings
  4. ๐Ÿงช cargo test --all-targets --all-features --workspace

๐Ÿ“„ License

This project is licensed under the MIT License. See LICENSE for details.

Contributors

Huge thanks to gpoblon for his CI, ideas and reviews!

Commit count: 0

cargo fmt