Skip to main content

Crate temps_jiff

Crate temps_jiff 

Source
Expand description

§temps-jiff

Jiff integration for the temps time expression parser.

This crate provides a JiffProvider that implements the TimeParser trait using the jiff datetime library. It enables parsing natural language time expressions into jiff’s Zoned type.

§Features

  • Full implementation of the temps TimeParser trait
  • Support for all time expression types
  • Proper handling of month/year arithmetic using jiff’s Span
  • Timezone support (UTC and fixed offsets)
  • Precise time calculations with nanosecond precision

§Example

use temps_jiff::{JiffProvider, parse_to_zoned};
use temps_core::{Language, TimeParser};

// Parse using the convenience function
let datetime = parse_to_zoned("in 5 minutes", Language::English).unwrap();
println!("In 5 minutes: {}", datetime);

// Or use the provider directly
let provider = JiffProvider;
let expr = temps_core::parse("tomorrow at 3:30 pm", Language::English).unwrap();
let datetime = provider.parse_expression(expr).unwrap();

§Month and Year Arithmetic

This implementation uses jiff’s Span type for date arithmetic, which provides correct handling of edge cases:

  • January 31 + 1 month = February 29 (leap year) or February 28 (non-leap year)
  • February 29, 2024 + 1 year = February 28, 2025

§Error Handling

All parsing operations return Result<Zoned, TempsError>. Common errors include:

  • ParseError: Invalid input that cannot be parsed
  • DateCalculationError: Date arithmetic that results in invalid dates
  • InvalidDate/InvalidTime: Components that are out of valid ranges
  • BackendError: Errors from the jiff library

Structs§

JiffProvider
Jiff-based implementation of the TimeParser trait.

Functions§

parse_to_zoned
Parse a natural language time expression into a jiff Zoned datetime.