diff --git a/crates/nu-command/src/conversions/into/record.rs b/crates/nu-command/src/conversions/into/record.rs index 445d81cb86..fea5fe1e4e 100644 --- a/crates/nu-command/src/conversions/into/record.rs +++ b/crates/nu-command/src/conversions/into/record.rs @@ -99,6 +99,11 @@ impl Command for SubCommand { "timezone" => Value::test_string("+02:00"), })), }, + Example { + description: "convert date components to table columns", + example: "2020-04-12T22:10:57+02:00 | into record | transpose | transpose -r", + result: None, + }, ] } } diff --git a/crates/nu-command/src/date/to_record.rs b/crates/nu-command/src/date/to_record.rs index f683ca1eec..fc28ba46f5 100644 --- a/crates/nu-command/src/date/to_record.rs +++ b/crates/nu-command/src/date/to_record.rs @@ -1,6 +1,7 @@ use crate::date::utils::parse_date_from_string; use chrono::{DateTime, Datelike, FixedOffset, Local, Timelike}; use nu_engine::command_prelude::*; +use nu_protocol::{report_parse_warning, ParseWarning}; #[derive(Clone)] pub struct SubCommand; @@ -17,7 +18,7 @@ impl Command for SubCommand { (Type::String, Type::record()), ]) .allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032 - .category(Category::Date) + .category(Category::Deprecated) } fn description(&self) -> &str { @@ -35,6 +36,17 @@ impl Command for SubCommand { call: &Call, input: PipelineData, ) -> Result { + let head = call.head; + report_parse_warning( + &StateWorkingSet::new(engine_state), + &ParseWarning::DeprecatedWarning { + old_command: "date to-record".into(), + new_suggestion: "see `into record` command examples".into(), + span: head, + url: "`help into record`".into(), + }, + ); + let head = call.head; // This doesn't match explicit nulls if matches!(input, PipelineData::Empty) { diff --git a/crates/nu-command/src/date/to_table.rs b/crates/nu-command/src/date/to_table.rs index 1588d40063..cb635b039f 100644 --- a/crates/nu-command/src/date/to_table.rs +++ b/crates/nu-command/src/date/to_table.rs @@ -1,6 +1,7 @@ use crate::date::utils::parse_date_from_string; use chrono::{DateTime, Datelike, FixedOffset, Local, Timelike}; use nu_engine::command_prelude::*; +use nu_protocol::{report_parse_warning, ParseWarning}; #[derive(Clone)] pub struct SubCommand; @@ -17,7 +18,7 @@ impl Command for SubCommand { (Type::String, Type::table()), ]) .allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032 - .category(Category::Date) + .category(Category::Deprecated) } fn description(&self) -> &str { @@ -36,6 +37,16 @@ impl Command for SubCommand { input: PipelineData, ) -> Result { let head = call.head; + report_parse_warning( + &StateWorkingSet::new(engine_state), + &ParseWarning::DeprecatedWarning { + old_command: "date to-table".into(), + new_suggestion: "see `into record` command examples".into(), + span: head, + url: "`help into record`".into(), + }, + ); + // This doesn't match explicit nulls if matches!(input, PipelineData::Empty) { return Err(ShellError::PipelineEmpty { dst_span: head }); diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index 30f8b280d1..549e23743f 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -44,6 +44,7 @@ pub enum Category { Date, Debug, Default, + Deprecated, Removed, Env, Experimental, @@ -79,6 +80,7 @@ impl std::fmt::Display for Category { Category::Date => "date", Category::Debug => "debug", Category::Default => "default", + Category::Deprecated => "deprecated", Category::Removed => "removed", Category::Env => "env", Category::Experimental => "experimental", diff --git a/crates/nu-std/std/dt/mod.nu b/crates/nu-std/std/dt/mod.nu index 7090449994..682fa9587c 100644 --- a/crates/nu-std/std/dt/mod.nu +++ b/crates/nu-std/std/dt/mod.nu @@ -120,8 +120,8 @@ export def datetime-diff [ } } } - let from_expanded = ($later | date to-timezone utc | date to-record) - let to_expanded = ($earlier | date to-timezone utc | date to-record) + let from_expanded = ($later | date to-timezone utc | into record) + let to_expanded = ($earlier | date to-timezone utc | into record) mut result = { year: ($from_expanded.year - $to_expanded.year), month: ($from_expanded.month - $to_expanded.month), day:0, hour:0, minute:0, second:0, millisecond:0, microsecond:0, nanosecond:0}