From 5da7dcdbdb2c5a7db39a9a622540785e76821ed6 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sun, 8 Jun 2025 16:09:57 -0500 Subject: [PATCH] make `date humanize` use `human_time_from_now()` (#15918) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR fixes a `date humanize` bug and makes it use @LoicRiegel's newer function `human_time_from_now()`. ### Before ```nushell ❯ (date now) + 3day Wed, 11 Jun 2025 07:15:48 -0500 (in 3 days) ❯ (date now) + 3day | date humanize in 2 days ``` ### After ```nushell ❯ (date now) + 3day Wed, 11 Jun 2025 07:23:10 -0500 (in 3 days) ❯ (date now) + 3day | date humanize in 3 days ``` Closes #15916 # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-command/src/date/humanize.rs | 3 +-- crates/nu-protocol/src/value/mod.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/date/humanize.rs b/crates/nu-command/src/date/humanize.rs index 5670d1faed..1d4420bc04 100644 --- a/crates/nu-command/src/date/humanize.rs +++ b/crates/nu-command/src/date/humanize.rs @@ -1,6 +1,5 @@ use crate::date::utils::parse_date_from_string; use chrono::{DateTime, FixedOffset, Local}; -use chrono_humanize::HumanTime; use nu_engine::command_prelude::*; #[derive(Clone)] @@ -90,7 +89,7 @@ fn helper(value: Value, head: Span) -> Value { } fn humanize_date(dt: DateTime) -> String { - HumanTime::from(dt).to_string() + nu_protocol::human_time_from_now(&dt).to_string() } #[cfg(test)] diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 85b54d9e20..567c36263e 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -4078,7 +4078,7 @@ fn operator_type_error( } } -fn human_time_from_now(val: &DateTime) -> HumanTime { +pub fn human_time_from_now(val: &DateTime) -> HumanTime { let now = Local::now().with_timezone(val.offset()); let delta = *val - now; match delta.num_nanoseconds() {