From a3aae2d26c592a1066a50c1be3aa345e7a3d8843 Mon Sep 17 00:00:00 2001 From: Anish Bhobe Date: Sun, 27 Apr 2025 02:06:08 +0200 Subject: [PATCH] Fix examples about RFC3339 format in `date now` and `format date`. (#15563) Replace example on `date now | debug` with `date now | format date "%+"`. Add RFC3339 "%+" format string example on `format date`. Users can now find how to format date-time to RFC3339. FIXES: #15168 # Description Documentation will now provide users examples on how to print RFC3339 strings. # User-Facing Changes Corrects documentation. # Tests + Formatting # After Submitting --- crates/nu-command/src/date/now.rs | 11 +++++++++-- crates/nu-command/src/strings/format/date.rs | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/date/now.rs b/crates/nu-command/src/date/now.rs index b3fca4ade2..833ef0c310 100644 --- a/crates/nu-command/src/date/now.rs +++ b/crates/nu-command/src/date/now.rs @@ -38,10 +38,16 @@ impl Command for DateNow { fn examples(&self) -> Vec { vec![ Example { - description: "Get the current date and display it in a given format string.", + description: "Get the current date and format it in a given format string.", example: r#"date now | format date "%Y-%m-%d %H:%M:%S""#, result: None, }, + Example { + description: + "Get the current date and format it according to the RFC 3339 standard.", + example: r#"date now | format date "%+""#, + result: None, + }, Example { description: "Get the time duration since 2019-04-30.", example: r#"(date now) - 2019-05-01"#, @@ -53,7 +59,8 @@ impl Command for DateNow { result: None, }, Example { - description: "Get current time in full RFC 3339 format with time zone.", + description: + "Get current time and format it in the debug format (RFC 2822 with timezone)", example: r#"date now | debug"#, result: None, }, diff --git a/crates/nu-command/src/strings/format/date.rs b/crates/nu-command/src/strings/format/date.rs index ad668ca510..5c6fb61d83 100644 --- a/crates/nu-command/src/strings/format/date.rs +++ b/crates/nu-command/src/strings/format/date.rs @@ -61,6 +61,14 @@ impl Command for FormatDate { Span::test_data(), )), }, + Example { + description: "Format a given date-time according to the RFC 3339 standard.", + example: r#"'2021-10-22 20:00:12 +01:00' | into datetime | format date "%+""#, + result: Some(Value::string( + "2021-10-22T20:00:12+01:00".to_string(), + Span::test_data(), + )), + }, Example { description: "Format the current date-time using a given format string.", example: r#"date now | format date "%Y-%m-%d %H:%M:%S""#,