Skip to content

Commit a70af71

Browse files
committed
Correct from_datetime() and filetime() methods
1 parent bedc400 commit a70af71

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl FileTime {
8181
/// let ft_i64 = FileTime::now().filetime();
8282
/// ```
8383
pub fn filetime(&self) -> i64 {
84-
(self.secs * Self::HUNDREDS_OF_NANOSECONDS) + self.nsecs
84+
(self.secs * Self::HUNDREDS_OF_NANOSECONDS) + self.nsecs.checked_div(100).unwrap_or(0)
8585
}
8686

8787
/// Return FILETIME epoch as DateTime<Utc>
@@ -115,7 +115,7 @@ impl FileTime {
115115
pub fn from_datetime(dt: DateTime<Utc>) -> Self {
116116
let nsecs = Self::EPOCH_AS_FILETIME
117117
+ (dt.timestamp() * Self::HUNDREDS_OF_NANOSECONDS)
118-
+ dt.timestamp_subsec_nanos() as i64;
118+
+ dt.timestamp_subsec_nanos().checked_div(100).unwrap_or(0) as i64;
119119
Self::from_i64(nsecs)
120120
}
121121

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

0 commit comments

Comments
 (0)