Deprecate date to-record and date to-table

This commit is contained in:
NotTheDr01ds
2024-11-12 14:45:01 -05:00
parent a541382776
commit 192e6dc3a7
4 changed files with 42 additions and 2 deletions

View File

@@ -99,6 +99,22 @@ impl Command for SubCommand {
"timezone" => Value::test_string("+02:00"), "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: Some(Value::test_list(vec![Value::test_record(record! {
"year" => Value::test_int(2020),
"month" => Value::test_int(4),
"day" => Value::test_int(12),
"hour" => Value::test_int(22),
"minute" => Value::test_int(10),
"second" => Value::test_int(57),
"millisecond" => Value::test_int(0),
"microsecond" => Value::test_int(0),
"nanosecond" => Value::test_int(0),
"timezone" => Value::test_string("+02:00"),
})])),
},
] ]
} }
} }

View File

@@ -1,6 +1,7 @@
use crate::date::utils::parse_date_from_string; use crate::date::utils::parse_date_from_string;
use chrono::{DateTime, Datelike, FixedOffset, Local, Timelike}; use chrono::{DateTime, Datelike, FixedOffset, Local, Timelike};
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use nu_protocol::{report_parse_warning, ParseWarning};
#[derive(Clone)] #[derive(Clone)]
pub struct SubCommand; pub struct SubCommand;
@@ -35,6 +36,18 @@ impl Command for SubCommand {
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
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; let head = call.head;
// This doesn't match explicit nulls // This doesn't match explicit nulls
if matches!(input, PipelineData::Empty) { if matches!(input, PipelineData::Empty) {

View File

@@ -1,6 +1,7 @@
use crate::date::utils::parse_date_from_string; use crate::date::utils::parse_date_from_string;
use chrono::{DateTime, Datelike, FixedOffset, Local, Timelike}; use chrono::{DateTime, Datelike, FixedOffset, Local, Timelike};
use nu_engine::command_prelude::*; use nu_engine::command_prelude::*;
use nu_protocol::{report_parse_warning, ParseWarning};
#[derive(Clone)] #[derive(Clone)]
pub struct SubCommand; pub struct SubCommand;
@@ -36,6 +37,16 @@ impl Command for SubCommand {
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let head = call.head; 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 // This doesn't match explicit nulls
if matches!(input, PipelineData::Empty) { if matches!(input, PipelineData::Empty) {
return Err(ShellError::PipelineEmpty { dst_span: head }); return Err(ShellError::PipelineEmpty { dst_span: head });

View File

@@ -120,8 +120,8 @@ export def datetime-diff [
} }
} }
} }
let from_expanded = ($later | 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 | date to-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} 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}