use crate::ZipDateTime;
pub struct ZipDateTimeBuilder(pub(crate) ZipDateTime);
impl From<ZipDateTime> for ZipDateTimeBuilder {
fn from(date: ZipDateTime) -> Self {
Self(date)
}
}
impl Default for ZipDateTimeBuilder {
fn default() -> Self {
Self::new()
}
}
impl ZipDateTimeBuilder {
pub fn new() -> Self {
Self(ZipDateTime { date: 0, time: 0 })
}
pub fn year(mut self, year: i32) -> Self {
let year: u16 = (((year - 1980) << 9) & 0xFE00).try_into().unwrap();
self.0.date |= year;
self
}
pub fn month(mut self, month: u32) -> Self {
let month: u16 = ((month << 5) & 0x1E0).try_into().unwrap();
self.0.date |= month;
self
}
pub fn day(mut self, day: u32) -> Self {
let day: u16 = (day & 0x1F).try_into().unwrap();
self.0.date |= day;
self
}
pub fn hour(mut self, hour: u32) -> Self {
let hour: u16 = ((hour << 11) & 0xF800).try_into().unwrap();
self.0.time |= hour;
self
}
pub fn minute(mut self, minute: u32) -> Self {
let minute: u16 = ((minute << 5) & 0x7E0).try_into().unwrap();
self.0.time |= minute;
self
}
pub fn second(mut self, second: u32) -> Self {
let second: u16 = ((second >> 1) & 0x1F).try_into().unwrap();
self.0.time |= second;
self
}
pub fn build(self) -> ZipDateTime {
self.into()
}
}