| 1 | // Copyright (c) 2021-2024 Harry [Majored] [[email protected]] |
| 2 | // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE) |
| 3 | |
| 4 | pub mod builderrust-analyzer cargo async_zip 0.0.18 date/builder/; |
| 5 | |
| 6 | #[cfg(feature = "chrono")] |
| 7 | use chronorust-analyzer cargo chrono 0.4.37 crate/::{DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#, Datelikerust-analyzer cargo chrono 0.4.37 traits/Datelike#, LocalResultrust-analyzer cargo chrono 0.4.37 offset/LocalResult#, TimeZonerust-analyzer cargo chrono 0.4.37 offset/TimeZone#, Timelikerust-analyzer cargo chrono 0.4.37 traits/Timelike#, Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#}; |
| 8 | |
| 9 | use selfrust-analyzer cargo async_zip 0.0.18 date/::builderrust-analyzer cargo async_zip 0.0.18 date/builder/::ZipDateTimeBuilderrust-analyzer cargo async_zip 0.0.18 date/builder/ZipDateTimeBuilder#; |
| 10 | |
| 11 | // https://github.com/Majored/rs-async-zip/blob/main/SPECIFICATION.md#446 |
| 12 | // https://learn.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-dosdatetimetovarianttime |
| 13 | |
| 14 | /// A date and time stored as per the MS-DOS representation used by ZIP files. |
| 15 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 16 | pub struct ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime# { |
| 17 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) daterust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#date.: u16, |
| 18 | pub(craterust-analyzer cargo async_zip 0.0.18 crate/) timerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#time.: u16, |
| 19 | } |
| 20 | |
| 21 | impl ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime# { |
| 22 | /// Returns the year of this date & time. |
| 23 | pub fn yearrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]year().(&self) -> i32 { |
| 24 | (((self.daterust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#date. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0xFE00) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().9) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u16][`Add<Self>`]add().1980).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 25 | } |
| 26 | |
| 27 | /// Returns the month of this date & time. |
| 28 | pub fn monthrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]month().(&self) -> u32 { |
| 29 | ((self.daterust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#date. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0x1E0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().5).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 30 | } |
| 31 | |
| 32 | /// Returns the day of this date & time. |
| 33 | pub fn dayrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]day().(&self) -> u32 { |
| 34 | (self.daterust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#date. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0x1F).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 35 | } |
| 36 | |
| 37 | /// Returns the hour of this date & time. |
| 38 | pub fn hourrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]hour().(&self) -> u32 { |
| 39 | ((self.timerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#time. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0xF800) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().11).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 40 | } |
| 41 | |
| 42 | /// Returns the minute of this date & time. |
| 43 | pub fn minuterust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]minute().(&self) -> u32 { |
| 44 | ((self.timerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#time. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0x7E0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shr<i32>`]shr().5).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 45 | } |
| 46 | |
| 47 | /// Returns the second of this date & time. |
| 48 | /// |
| 49 | /// Note that MS-DOS has a maximum granularity of two seconds. |
| 50 | pub fn secondrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]second().(&self) -> u32 { |
| 51 | ((self.timerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#time. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`BitAnd<Self>`]bitand().0x1F) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u16][`Shl<i32>`]shl().1).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 52 | } |
| 53 | |
| 54 | /// Constructs chrono's [`DateTime`] representation of this date & time. |
| 55 | /// |
| 56 | /// Note that this requires the `chrono` feature. |
| 57 | #[cfg(feature = "chrono")] |
| 58 | pub fn as_chronorust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]as_chrono().(&self) -> LocalResultrust-analyzer cargo chrono 0.4.37 offset/LocalResult#<DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#>> { |
| 59 | self.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 60 | } |
| 61 | |
| 62 | /// Constructs this date & time from chrono's [`DateTime`] representation. |
| 63 | /// |
| 64 | /// Note that this requires the `chrono` feature. |
| 65 | #[cfg(feature = "chrono")] |
| 66 | pub fn from_chronorust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]from_chrono().(dt: &DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#>) -> Selfrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime] { |
| 67 | dt.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ZipDateTimeBuilderrust-analyzer cargo async_zip 0.0.18 date/builder/ZipDateTimeBuilder#> for ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime# { |
| 72 | fn fromrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime][`From<ZipDateTimeBuilder>`]from().(builder: ZipDateTimeBuilderrust-analyzer cargo async_zip 0.0.18 date/builder/ZipDateTimeBuilder#) -> Selfrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime][`From<ZipDateTimeBuilder>`] { |
| 73 | builder.0rust-analyzer cargo async_zip 0.0.18 date/builder/ZipDateTimeBuilder#0. |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | #[cfg(feature = "chrono")] |
| 78 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#>> for ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime# { |
| 79 | fn fromrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime][`From<&DateTime<Utc>>`]from().(value: &DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#>) -> Selfrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime][`From<&DateTime<Utc>>`] { |
| 80 | let mut builder = ZipDateTimeBuilderrust-analyzer cargo async_zip 0.0.18 date/builder/ZipDateTimeBuilder#::newrust-analyzer cargo async_zip 0.0.18 date/builder/impl#[ZipDateTimeBuilder]new().(); |
| 81 | |
| 82 | builder = builder.yearrust-analyzer cargo async_zip 0.0.18 date/builder/impl#[ZipDateTimeBuilder]year().(value.date_naiverust-analyzer cargo chrono 0.4.37 datetime/impl#[`DateTime<Tz>`]date_naive().().yearrust-analyzer cargo chrono 0.4.37 naive/date/impl#[NaiveDate][Datelike]year().()); |
| 83 | builder = builder.monthrust-analyzer cargo async_zip 0.0.18 date/builder/impl#[ZipDateTimeBuilder]month().(value.date_naiverust-analyzer cargo chrono 0.4.37 datetime/impl#[`DateTime<Tz>`]date_naive().().monthrust-analyzer cargo chrono 0.4.37 naive/date/impl#[NaiveDate][Datelike]month().()); |
| 84 | builder = builder.dayrust-analyzer cargo async_zip 0.0.18 date/builder/impl#[ZipDateTimeBuilder]day().(value.date_naiverust-analyzer cargo chrono 0.4.37 datetime/impl#[`DateTime<Tz>`]date_naive().().dayrust-analyzer cargo chrono 0.4.37 naive/date/impl#[NaiveDate][Datelike]day().()); |
| 85 | builder = builder.hourrust-analyzer cargo async_zip 0.0.18 date/builder/impl#[ZipDateTimeBuilder]hour().(value.timerust-analyzer cargo chrono 0.4.37 datetime/impl#[`DateTime<Tz>`]time().().hourrust-analyzer cargo chrono 0.4.37 naive/time/impl#[NaiveTime][Timelike]hour().()); |
| 86 | builder = builder.minuterust-analyzer cargo async_zip 0.0.18 date/builder/impl#[ZipDateTimeBuilder]minute().(value.timerust-analyzer cargo chrono 0.4.37 datetime/impl#[`DateTime<Tz>`]time().().minuterust-analyzer cargo chrono 0.4.37 naive/time/impl#[NaiveTime][Timelike]minute().()); |
| 87 | builder = builder.secondrust-analyzer cargo async_zip 0.0.18 date/builder/impl#[ZipDateTimeBuilder]second().(value.timerust-analyzer cargo chrono 0.4.37 datetime/impl#[`DateTime<Tz>`]time().().secondrust-analyzer cargo chrono 0.4.37 naive/time/impl#[NaiveTime][Timelike]second().()); |
| 88 | |
| 89 | builder.buildrust-analyzer cargo async_zip 0.0.18 date/builder/impl#[ZipDateTimeBuilder]build().() |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | #[cfg(feature = "chrono")] |
| 94 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#> for LocalResultrust-analyzer cargo chrono 0.4.37 offset/LocalResult#<DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#>> { |
| 95 | fn fromrust-analyzer cargo async_zip 0.0.18 date/impl#[`LocalResult<DateTime<Utc>>`][`From<&ZipDateTime>`]from().(value: &ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#) -> Selfrust-analyzer cargo async_zip 0.0.18 date/impl#[`LocalResult<DateTime<Utc>>`][`From<&ZipDateTime>`] { |
| 96 | Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#.with_ymd_and_hmsrust-analyzer cargo chrono 0.4.37 offset/TimeZone#with_ymd_and_hms().(value.yearrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]year().(), value.monthrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]month().(), value.dayrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]day().(), value.hourrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]hour().(), value.minuterust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]minute().(), value.secondrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime]second().()) |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | #[cfg(feature = "chrono")] |
| 101 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#>> for ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime# { |
| 102 | fn fromrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime][`From<DateTime<Utc>>`]from().(value: DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#>) -> Selfrust-analyzer cargo async_zip 0.0.18 date/impl#[ZipDateTime][`From<DateTime<Utc>>`] { |
| 103 | (&value).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | #[cfg(feature = "chrono")] |
| 108 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#> for LocalResultrust-analyzer cargo chrono 0.4.37 offset/LocalResult#<DateTimerust-analyzer cargo chrono 0.4.37 datetime/DateTime#<Utcrust-analyzer cargo chrono 0.4.37 offset/utc/Utc#>> { |
| 109 | fn fromrust-analyzer cargo async_zip 0.0.18 date/impl#[`LocalResult<DateTime<Utc>>`][`From<ZipDateTime>`]from().(value: ZipDateTimerust-analyzer cargo async_zip 0.0.18 date/ZipDateTime#) -> Selfrust-analyzer cargo async_zip 0.0.18 date/impl#[`LocalResult<DateTime<Utc>>`][`From<ZipDateTime>`] { |
| 110 | (&value).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 111 | } |
| 112 | } |