mod ast;
mod civil;
mod error;
mod eval;
mod parser;
mod tz;
mod validate;
pub use error::{ParseError, UnknownTimeZone, Warning};
pub use tz::Tz;
#[derive(Clone, Debug)]
pub struct Dtrexp {
branches: Vec<ast::Expr>,
warnings: Vec<Warning>,
}
pub fn parse(input: &str) -> Result<Dtrexp, ParseError> {
let branches = parser::parse_branches(input)?;
let mut warnings = Vec::new();
for b in &branches {
warnings.extend(validate::check(b)?);
}
Ok(Dtrexp { branches, warnings })
}
pub fn validate(input: &str) -> Result<Vec<Warning>, ParseError> {
Ok(parse(input)?.warnings)
}
impl Dtrexp {
pub fn warnings(&self) -> &[Warning] {
&self.warnings
}
pub fn covers(&self, instant_ms: i64, tz_id: &str) -> Result<bool, UnknownTimeZone> {
let tz = Tz::load(tz_id)?;
Ok(self.covers_in(instant_ms, &tz))
}
pub fn covers_in(&self, instant_ms: i64, tz: &Tz) -> bool {
self.branches
.iter()
.any(|b| eval::expr_covers(b, instant_ms, tz))
}
}