async_zip/date/
builder.rs1use crate::ZipDateTime;
5
6pub struct ZipDateTimeBuilder(pub(crate) ZipDateTime);
8
9impl From<ZipDateTime> for ZipDateTimeBuilder {
10 fn from(date: ZipDateTime) -> Self {
11 Self(date)
12 }
13}
14
15impl Default for ZipDateTimeBuilder {
16 fn default() -> Self {
17 Self::new()
18 }
19}
20
21impl ZipDateTimeBuilder {
22 pub fn new() -> Self {
24 Self(ZipDateTime { date: 0, time: 0 })
25 }
26
27 pub fn year(mut self, year: i32) -> Self {
29 let year: u16 = (((year - 1980) << 9) & 0xFE00).try_into().unwrap();
30 self.0.date |= year;
31 self
32 }
33
34 pub fn month(mut self, month: u32) -> Self {
36 let month: u16 = ((month << 5) & 0x1E0).try_into().unwrap();
37 self.0.date |= month;
38 self
39 }
40
41 pub fn day(mut self, day: u32) -> Self {
43 let day: u16 = (day & 0x1F).try_into().unwrap();
44 self.0.date |= day;
45 self
46 }
47
48 pub fn hour(mut self, hour: u32) -> Self {
50 let hour: u16 = ((hour << 11) & 0xF800).try_into().unwrap();
51 self.0.time |= hour;
52 self
53 }
54
55 pub fn minute(mut self, minute: u32) -> Self {
57 let minute: u16 = ((minute << 5) & 0x7E0).try_into().unwrap();
58 self.0.time |= minute;
59 self
60 }
61
62 pub fn second(mut self, second: u32) -> Self {
66 let second: u16 = ((second >> 1) & 0x1F).try_into().unwrap();
67 self.0.time |= second;
68 self
69 }
70
71 pub fn build(self) -> ZipDateTime {
81 self.into()
82 }
83}