From 34d2fce57e2836f758387b6cb54ee1f11bebd473 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 25 Nov 2024 07:41:46 +0100 Subject: [PATCH] fix: add support for 'any' unit, when parsing ` ago`. Similar to Git, any unit is allowed and will default to seconds, like `60 flurps ago` will mean a minute in the past. --- gix-date/src/parse.rs | 2 +- gix-date/tests/time/parse.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gix-date/src/parse.rs b/gix-date/src/parse.rs index cf00b13b383..f33081eaf30 100644 --- a/gix-date/src/parse.rs +++ b/gix-date/src/parse.rs @@ -156,7 +156,7 @@ mod relative { "month" => Span::new().try_months(units), "year" => Span::new().try_years(units), // Ignore values you don't know, assume seconds then (so does git) - _ => return None, + _anything => Span::new().try_seconds(units), }; Some(result.map_err(|_| Error::RelativeTimeConversion)) } diff --git a/gix-date/tests/time/parse.rs b/gix-date/tests/time/parse.rs index 6a741e3e3e5..44222752e8c 100644 --- a/gix-date/tests/time/parse.rs +++ b/gix-date/tests/time/parse.rs @@ -184,6 +184,7 @@ mod relative { // For comparison, a few are the same as in: https://github.com/git/git/blob/master/t/t0006-date.sh let cases = [ ("5 seconds ago", 5.seconds()), + ("12345 florx ago", 12_345.seconds()), // Anything parses as seconds ("5 minutes ago", 5.minutes()), ("5 hours ago", 5.hours()), ("5 days ago", 5.days()),