Skip to content

Commit

Permalink
Decomplexify match some more
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Feb 10, 2024
1 parent 91efcfe commit 25b0610
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rc-zip/src/parse/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ impl MsdosTimestamp {
/// Attempts to convert to a chrono UTC date time
pub fn to_datetime(&self) -> Option<DateTime<Utc>> {
// see https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-dosdatetimetofiletime
let date = match {
let res = {
// bits 0-4: day of the month (1-31)
let d = (self.date & 0b1_1111) as u32;
// bits 5-8: month (1 = january, 2 = february and so on)
let m = ((self.date >> 5) & 0b1111) as u32;
// bits 9-15: year offset from 1980
let y = ((self.date >> 9) + 1980) as i32;
Utc.with_ymd_and_hms(y, m, d, 0, 0, 0)
} {
};

let date = match res {
LocalResult::Single(date) => date,
_ => return None,
};
Expand Down

0 comments on commit 25b0610

Please sign in to comment.