diff --git a/src/read.rs b/src/read.rs index 98ffd2b66..5a247339a 100644 --- a/src/read.rs +++ b/src/read.rs @@ -979,6 +979,10 @@ impl ZipArchive { files_by_unix_mode.push((outpath.clone(), mode)); } } + // Set original timestamp. + if let Some(t) = datetime_to_systemtime(&file.last_modified()) { + outfile.set_modified(t)?; + } } #[cfg(unix)] { @@ -1714,6 +1718,33 @@ pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult Option { + if let Some(t) = generate_chrono_datetime(datetime) { + let time = chrono::DateTime::::from_naive_utc_and_offset(t, chrono::Utc); + return Some(time.into()); + } + None +} + +/// Generate a `NaiveDateTime` from a `DateTime`. +fn generate_chrono_datetime(datetime: &DateTime) -> Option { + if let Some(d) = chrono::NaiveDate::from_ymd_opt( + datetime.year().into(), + datetime.month().into(), + datetime.day().into(), + ) { + if let Some(d) = d.and_hms_opt( + datetime.hour().into(), + datetime.minute().into(), + datetime.second().into(), + ) { + return Some(d); + } + } + None +} + #[cfg(test)] mod test { use crate::result::ZipResult;