pub trait TimeParser {
type DateTime;
// Required methods
fn now(&self) -> Self::DateTime;
fn parse_expression(&self, expr: TimeExpression) -> Result<Self::DateTime>;
}Expand description
Trait for implementing time parsing with a specific datetime backend.
This trait should be implemented by datetime libraries (chrono, jiff, etc.) to provide the actual time calculation logic.
§Examples
use temps_core::{TimeParser, TimeExpression, Result};
struct MyTimeParser;
impl TimeParser for MyTimeParser {
type DateTime = String; // Your datetime type
fn now(&self) -> Self::DateTime {
"2024-01-15T14:30:00Z".to_string()
}
fn parse_expression(&self, expr: TimeExpression) -> Result<Self::DateTime> {
// Implementation here
Ok(self.now())
}
}Required Associated Types§
Required Methods§
Sourcefn parse_expression(&self, expr: TimeExpression) -> Result<Self::DateTime>
fn parse_expression(&self, expr: TimeExpression) -> Result<Self::DateTime>
Parse a time expression into a concrete datetime
§Errors
Returns TempsError if:
- Date calculation results in an invalid date
- Arithmetic overflow occurs
- The backend library returns an error