aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorEllie <ellie@elliehuxtable.com>2021-12-20 05:52:07 +0000
committerGitHub <noreply@github.com>2021-12-20 05:52:07 +0000
commit7fa3e1c0f4733d9af332ada3612343cb62195117 (patch)
treea88165ddb350bf9da323b158987a22076a0b33f3 /src/command
parentuse sqlite grouping rather than subquery (#181) (diff)
downloadatuin-7fa3e1c0f4733d9af332ada3612343cb62195117.zip
Do not crash if the history timestamp is in the future (#250)
Resolve #189 We were throwing an OutOfRangeError. This occurs when you attempt to convert to a duration, and your input is <0. A value in the future would have done this. This is especially noticeable during DST...
Diffstat (limited to 'src/command')
-rw-r--r--src/command/search.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/command/search.rs b/src/command/search.rs
index 922f7468..c9942143 100644
--- a/src/command/search.rs
+++ b/src/command/search.rs
@@ -42,7 +42,16 @@ impl State {
let duration: Vec<&str> = duration.split(' ').collect();
let ago = chrono::Utc::now().sub(h.timestamp);
- let ago = humantime::format_duration(ago.to_std().unwrap()).to_string();
+
+ // Account for the chance that h.timestamp is "in the future"
+ // This would mean that "ago" is negative, and the unwrap here
+ // would fail.
+ // If the timestamp would otherwise be in the future, display
+ // the time ago as 0.
+ let ago = humantime::format_duration(
+ ago.to_std().unwrap_or_else(|_| Duration::new(0, 0)),
+ )
+ .to_string();
let ago: Vec<&str> = ago.split(' ').collect();
(