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
TimeParsertrait - 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 parsedDateCalculationError: Date arithmetic that results in invalid datesInvalidDate/InvalidTime: Components that are out of valid rangesBackendError: Errors from the jiff library
Structs§
- Jiff
Provider - Jiff-based implementation of the TimeParser trait.
Functions§
- parse_
to_ zoned - Parse a natural language time expression into a jiff
Zoneddatetime.