From db261e3ed95a0aa1e1af7171557ee37617b9d068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Riegel?= <96702577+LoicRiegel@users.noreply.github.com> Date: Thu, 24 Apr 2025 15:32:29 +0200 Subject: [PATCH] bugfix: `str join` outputs dates consistently (RFC2822 when possible) (#15629) Closes #11265 # Description ``str join`` outputs dates just other commands: RFC2822 by default otherwise RFC3339 for negative dates # User-Facing Changes ```nushell ~> 2024-01-01 # => Mon, 1 Jan 2024 00:00:00 +0000 (a year ago) ~> '3000 years ago' | date from-human # => -0975-04-23T20:57:07.217711700+02:00 (3000 years ago) ~> [ 2024-01-01 ] | str join # => Mon, 1 Jan 2024 00:00:00 +0000 ~> [ ('3000 years ago' | date from-human) ] | str join # => -0975-04-23T20:57:56.221269600+02:00 ``` # Tests + Formatting OK # After Submitting Nothing --- crates/nu-command/src/strings/str_/join.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/strings/str_/join.rs b/crates/nu-command/src/strings/str_/join.rs index e500da8343..12b2858e1e 100644 --- a/crates/nu-command/src/strings/str_/join.rs +++ b/crates/nu-command/src/strings/str_/join.rs @@ -1,3 +1,4 @@ +use chrono::Datelike; use nu_engine::command_prelude::*; use nu_protocol::{shell_error::io::IoError, Signals}; @@ -109,9 +110,14 @@ fn run( Value::Error { error, .. } => { return Err(*error); } - // Hmm, not sure what we actually want. - // `to_expanded_string` formats dates as human readable which feels funny. - Value::Date { val, .. } => write!(buffer, "{val:?}").map_err(&from_io_error)?, + Value::Date { val, .. } => { + let date_str = if val.year() >= 0 { + val.to_rfc2822() + } else { + val.to_rfc3339() + }; + write!(buffer, "{date_str}").map_err(&from_io_error)? + } value => write!(buffer, "{}", value.to_expanded_string("\n", &config)) .map_err(&from_io_error)?, }