Expand description
§temps-core
Core functionality for parsing human-readable time expressions.
This crate provides the fundamental types and traits for parsing natural language time expressions like “in 5 minutes”, “yesterday at 3pm”, or “next Monday”. It is designed to be backend-agnostic, allowing different datetime libraries (chrono, jiff, etc.) to implement the parsing logic.
§Overview
The crate consists of several key components:
- Types: Core data structures representing different time expressions
- Traits: Interfaces for implementing time parsing with different backends
- Parsers: Language-specific parsers (English and German)
- Utilities: Helper functions for time calculations and conversions
§Example
use temps_core::{parse, Language, TimeExpression};
// Parse a relative time expression
let expr = parse("in 5 minutes", Language::English).unwrap();
match expr {
TimeExpression::Relative(rel) => {
println!("Amount: {}, Unit: {:?}", rel.amount, rel.unit);
}
_ => {}
}
// Parse with German language
let expr = parse("in 5 Minuten", Language::German).unwrap();§Supported Languages
- English
- German
§Error Handling
All parsing operations return a Result<T, TempsError> where TempsError
provides detailed information about what went wrong during parsing or
date calculations.
Re-exports§
pub use error::Result;pub use error::TempsError;
Modules§
- common
- Common parsing utilities shared across language implementations.
- constants
- Common constants used across the temps library
- error
- Error types for the temps library.
- errors
- Common error messages and error handling utilities
- language
- Language-specific parser implementations.
- time_
utils - Time conversion and calculation utilities
Structs§
- Absolute
Time - Represents an absolute date and time.
- DayTime
- Represents a combination of a day reference and a specific time.
- Relative
Time - Represents a time relative to the current moment.
- Standard
Date - Represents a calendar date.
- Time
- Represents a time of day.
Enums§
- DayReference
- Represents a reference to a specific day.
- Direction
- Direction of time relative to now.
- Language
- Supported languages for parsing time expressions.
- Meridiem
- AM/PM indicator for 12-hour time format.
- Time
Expression - Represents a parsed time expression.
- Time
Unit - Units of time used in relative expressions.
- Timezone
- Represents a timezone specification.
- Weekday
- Days of the week.
- Weekday
Modifier - Modifiers for weekday references.
Traits§
- Language
Parser - Trait for implementing language-specific parsers.
- Time
Parser - Trait for implementing time parsing with a specific datetime backend.
Functions§
- parse
- Parse a natural language time expression.