timefilter 0.1.0

Human-readable time string parsing and filtering with comparison operators (e.g., ">=7d", "<2h", "2024-05-01")
Documentation
  • Coverage
  • 90.48%
    19 out of 21 items documented2 out of 2 items with examples
  • Size
  • Source code size: 39.06 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 764.17 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • lenitain

timefilter

Crates.io Docs.rs

Human-readable time string parsing and filtering with comparison operators">=7d", "<2h", "2024-05-01".

Installation

cargo add timefilter

Features

  • Parse relative time: "7d", "2h", "30m", "30s"DateTime<Utc> (now — duration)
  • Parse absolute time: "2024-05-01", "2024-05-01 10:00", "2024-05-01 10:00:00"
  • Filter: TimeFilter::ge(threshold) or ">=7d".parse::<TimeFilter>()
  • Format: format_datetime(&dt) → local timezone string
  • Serde (optional): serialize/deserialize [TimeFilter] as strings

Testing

cargo test

30 tests (25 unit + 5 doc-tests) covering parsing, filtering, edge cases, and formatting.

Quick example

use timefilter::prelude::*;

// Parse absolute time
let dt = parse_time("2024-05-01 10:00").unwrap();

// Parse a filter expression
let f: TimeFilter = ">=2024-05-01 09:00".parse().unwrap();
assert!(f.matches(dt));

// Relative time (hours ago)
let dt = parse_time("2h").unwrap();
let age = chrono::Utc::now() - dt;
assert!(age.num_hours() >= 1);

License

MIT License