Skip to content

Commit

Permalink
Correct from_datetime() and filetime() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxuser committed Nov 29, 2023
1 parent bedc400 commit a70af71
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl FileTime {
/// let ft_i64 = FileTime::now().filetime();
/// ```
pub fn filetime(&self) -> i64 {
(self.secs * Self::HUNDREDS_OF_NANOSECONDS) + self.nsecs
(self.secs * Self::HUNDREDS_OF_NANOSECONDS) + self.nsecs.checked_div(100).unwrap_or(0)
}

/// Return FILETIME epoch as DateTime<Utc>
Expand Down Expand Up @@ -115,7 +115,7 @@ impl FileTime {
pub fn from_datetime(dt: DateTime<Utc>) -> Self {
let nsecs = Self::EPOCH_AS_FILETIME
+ (dt.timestamp() * Self::HUNDREDS_OF_NANOSECONDS)
+ dt.timestamp_subsec_nanos() as i64;
+ dt.timestamp_subsec_nanos().checked_div(100).unwrap_or(0) as i64;
Self::from_i64(nsecs)
}

Expand Down Expand Up @@ -214,7 +214,7 @@ mod test {
let bytes = [0xCE_u8, 0xEB, 0x7D, 0x1A, 0x61, 0x59, 0xCE, 0x01];
let ft: [u8; 8] = FileTime {
secs: 13013971283,
nsecs: 1482830,
nsecs: 148283000,
}
.into();
assert_eq!(ft, bytes);
Expand Down

0 comments on commit a70af71

Please sign in to comment.