pub mod calendar;
pub mod leap;
pub mod time;
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
pub use leap::{LeapSecond, LeapTable};
pub use time::{Offset, Save, TimeOfDay, TimeRef};
#[derive(Debug, Clone)]
pub struct Origin {
pub file: PathBuf,
pub line: usize,
}
impl Origin {
pub fn new(file: &Path, line: usize) -> Self {
Origin {
file: file.to_path_buf(),
line,
}
}
}
#[derive(Debug, Clone)]
pub struct RuleRecord {
pub name: String,
pub from: i32,
pub to: YearBound,
pub in_month: u8,
pub on: calendar::OnDay,
pub at: TimeOfDay,
pub save: Save,
pub letter: String,
pub origin: Origin,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum YearBound {
Year(i32),
Max,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ZoneRules {
None,
Save(Save),
Named(String),
}
#[derive(Debug, Clone)]
pub struct ZoneEra {
pub stdoff: Offset,
pub rules: ZoneRules,
pub format: String,
pub until: Option<Until>,
pub origin: Origin,
}
#[derive(Debug, Clone)]
pub struct Until {
pub year: i32,
pub month: u8,
pub day: calendar::OnDay,
pub time: TimeOfDay,
}
#[derive(Debug, Clone)]
pub struct ZoneRecord {
pub name: String,
pub eras: Vec<ZoneEra>,
pub origin: Origin,
}
#[derive(Debug, Clone)]
pub struct LinkRecord {
pub target: String,
pub link_name: String,
pub origin: Origin,
}
#[derive(Debug, Default, Clone)]
pub struct Database {
pub zones: Vec<ZoneRecord>,
pub links: Vec<LinkRecord>,
pub rules: BTreeMap<String, Vec<RuleRecord>>,
}
impl Database {
pub fn zone(&self, name: &str) -> Option<&ZoneRecord> {
self.zones.iter().find(|z| z.name == name)
}
}