#[derive(Debug, Clone)]
pub struct ValidPeriod {
pub start_date: String,
pub end_date: String,
}
impl ValidPeriod {
#[must_use]
pub fn new(start_date: impl Into<String>, end_date: impl Into<String>) -> Self {
Self {
start_date: start_date.into(),
end_date: end_date.into(),
}
}
#[must_use]
pub fn to_xml_string(&self) -> String {
format!(
"<ValidPeriod StartDate=\"{}\" EndDate=\"{}\"/>",
self.start_date, self.end_date
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_valid_period_new() {
let vp = ValidPeriod::new("2024-01-01", "2024-12-31");
assert_eq!(vp.start_date, "2024-01-01");
assert_eq!(vp.end_date, "2024-12-31");
}
#[test]
fn test_valid_period_xml() {
let vp = ValidPeriod::new("2024-01-01", "2024-12-31");
let xml = vp.to_xml_string();
assert!(xml.contains("StartDate=\"2024-01-01\""));
assert!(xml.contains("EndDate=\"2024-12-31\""));
assert!(xml.contains("/>"));
}
}