Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct from_i64(). #1

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
tuxuser marked this conversation as resolved.
Show resolved Hide resolved
}

/// 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