Repository: sorairolake/nt-time (language: rust)

Issue:
Return `Result` instead of calling `.expect()` in conversions with `chono::DateTime`
### Checklist

- [X] I have searched the existing issues

### Summary

The calls to `.expect()` in `impl From<FileTime> for chrono::DateTime<chrono::Utc>` makes me nervous, why not use `TryFrom`?

https://github.com/sorairolake/nt-time/blob/398fb74e7472f9f3f7f8d98532a8bdfca2746e18/src/file_time.rs#L1462-L1500

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct


Discussion / hints:
@rjzak Because this conversion is always expected to be successful. Panics should not occur unless there is a bug in the implementation. However, `TimeDelta::try_seconds` may be replaced by `TimeDelta::seconds`.

| Constant                   | Date and time                        |
| -------------------------- | ------------------------------------ |
| `DateTime::<Utc>::MIN_UTC` | -262143-01-01 00:00:00 UTC           |
| `FileTime::NT_TIME_EPOCH`  | 1601-01-01 00:00:00 UTC              |
| `FileTime::MAX`            | +60056-05-28 05:36:10.955161500 UTC  |
| `DateTime::<Utc>::MAX_UTC` | +262142-12-31 23:59:59.999999999 UTC |
Ok, I feel better then. I'm trying to build a system for storing and analyzing malware, so I expect to encounter dates which may be nonsense.
Thank you!

Fix patch:
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 78f13c5..f77c673 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -14,6 +14,13 @@ All notable changes to this project will be documented in this file.
 The format is based on https://keepachangelog.com/[Keep a Changelog], and this
 project adheres to https://semver.org/[Semantic Versioning].
 
+== {compare-url}/v0.6.10\...HEAD[Unreleased]
+
+=== Changed
+
+* Use `TimeDelta::seconds` instead of `TimeDelta::try_seconds`
+  ({pull-request-url}/151[#151])
+
 == {compare-url}/v0.6.9\...v0.6.10[0.6.10] - 2024-04-08
 
 === Changed
diff --git a/src/file_time.rs b/src/file_time.rs
index 698a787..949ddf2 100644
--- a/src/file_time.rs
+++ b/src/file_time.rs
@@ -1483,15 +1483,13 @@ impl From<FileTime> for chrono::DateTime<chrono::Utc> {
     fn from(ft: FileTime) -> Self {
         use chrono::TimeDelta;
 
-        let duration = TimeDelta::try_seconds(
+        let duration = TimeDelta::seconds(
             i64::try_from(ft.to_raw() / FILE_TIMES_PER_SEC)
                 .expect("the number of seconds should be in the range of `i64`"),
-        )
-        .expect("the number of seconds should be in the range of `TimeDelta`")
-            + TimeDelta::nanoseconds(
-                i64::try_from((ft.to_raw() % FILE_TIMES_PER_SEC) * 100)
-                    .expect("the number of nanoseconds should be in the range of `i64`"),
-            );
+        ) + TimeDelta::nanoseconds(
+            i64::try_from((ft.to_raw() % FILE_TIMES_PER_SEC) * 100)
+                .expect("the number of nanoseconds should be in the range of `i64`"),
+        );
         "1601-01-01 00:00:00 UTC"
             .parse::<Self>()
             .expect("date and time should be valid as RFC 3339")


Test patch: