diff --git a/crates/nu-command/src/date/format.rs b/crates/nu-command/src/date/format.rs index c657e8f074..ca9f89cb1f 100644 --- a/crates/nu-command/src/date/format.rs +++ b/crates/nu-command/src/date/format.rs @@ -77,18 +77,26 @@ fn format_helper(value: Value, formatter: &Spanned, span: Span) -> Value match value { Value::Date { val, span: _ } => Value::String { val: val.format(formatter.item.as_str()).to_string(), - span: span, + span, }, Value::String { val, span: _ } => { let dt = parse_date_from_string(val); - if dt.is_ok() { - Value::String { - val: dt.unwrap().format(formatter.item.as_str()).to_string(), - span: span, - } - } else { - dt.unwrap_err() + match dt { + Ok(x) => Value::String { + val: x.format(formatter.item.as_str()).to_string(), + span, + }, + Err(e) => e, } + // if dt.is_ok() { + + // Value::String { + // val: dt.unwrap().format(formatter.item.as_str()).to_string(), + // span, + // } + // } else { + // dt.unwrap_err() + // } } Value::Nothing { span: _ } => { let dt = Local::now(); @@ -97,7 +105,7 @@ fn format_helper(value: Value, formatter: &Spanned, span: Span) -> Value .with_timezone(dt.offset()) .format(formatter.item.as_str()) .to_string(), - span: span, + span, } } _ => unsupported_input_error(), diff --git a/crates/nu-command/src/date/list_timezone.rs b/crates/nu-command/src/date/list_timezone.rs index 9442ebd560..7e4ba8ee77 100644 --- a/crates/nu-command/src/date/list_timezone.rs +++ b/crates/nu-command/src/date/list_timezone.rs @@ -28,19 +28,16 @@ impl Command for SubCommand { ) -> Result { let span = call.head; - let tzs: Vec = TZ_VARIANTS + Ok(TZ_VARIANTS .iter() .map(move |x| { let cols = vec!["timezone".into()]; let vals = vec![Value::String { val: x.name().to_string(), - span: span, + span, }]; Value::Record { cols, vals, span } }) - .collect(); - - Ok(tzs .into_iter() .into_pipeline_data(engine_state.ctrlc.clone())) } diff --git a/crates/nu-command/src/date/now.rs b/crates/nu-command/src/date/now.rs index 19ba492441..dbd0f081f3 100644 --- a/crates/nu-command/src/date/now.rs +++ b/crates/nu-command/src/date/now.rs @@ -1,7 +1,7 @@ use chrono::Local; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Example, IntoPipelineData, PipelineData, Signature, Value}; +use nu_protocol::{IntoPipelineData, PipelineData, Signature, Value}; #[derive(Clone)] pub struct SubCommand; diff --git a/crates/nu-command/src/date/to_table.rs b/crates/nu-command/src/date/to_table.rs index f73146099d..1350be122e 100644 --- a/crates/nu-command/src/date/to_table.rs +++ b/crates/nu-command/src/date/to_table.rs @@ -58,40 +58,18 @@ impl Command for SubCommand { "timezone".into(), ]; let vals = vec![ - Value::Int { - val: 2020, - span: span, - }, - Value::Int { - val: 04, - span: span, - }, - Value::Int { - val: 12, - span: span, - }, - Value::Int { - val: 22, - span: span, - }, - Value::Int { - val: 10, - span: span, - }, - Value::Int { - val: 57, - span: span, - }, + Value::Int { val: 2020, span }, + Value::Int { val: 4, span }, + Value::Int { val: 12, span }, + Value::Int { val: 22, span }, + Value::Int { val: 10, span }, + Value::Int { val: 57, span }, Value::String { val: "+02:00".to_string(), - span: span, + span, }, ]; - Some(Value::Record { - cols: cols, - vals: vals, - span: span, - }) + Some(Value::Record { cols, vals, span }) }, }, ] diff --git a/crates/nu-command/src/date/to_timezone.rs b/crates/nu-command/src/date/to_timezone.rs index 7abcdd6e63..9bb256503f 100644 --- a/crates/nu-command/src/date/to_timezone.rs +++ b/crates/nu-command/src/date/to_timezone.rs @@ -93,12 +93,9 @@ fn helper(value: Value, head: Span, timezone: &Spanned) -> Value { Value::Date { val, span: _ } => _to_timezone(val, timezone, head), Value::String { val, span: _ } => { let time = parse_date_from_string(val); - - if time.is_ok() { - let dt = time.unwrap(); - _to_timezone(dt, timezone, head) - } else { - time.unwrap_err() + match time { + Ok(dt) => _to_timezone(dt, timezone, head), + Err(e) => e, } } @@ -112,11 +109,8 @@ fn helper(value: Value, head: Span, timezone: &Spanned) -> Value { } fn _to_timezone(dt: DateTime, timezone: &Spanned, span: Span) -> Value { - match datetime_in_timezone(&dt, &timezone.item.as_str()) { - Ok(dt) => Value::Date { - val: dt, - span: span, - }, + match datetime_in_timezone(&dt, timezone.item.as_str()) { + Ok(dt) => Value::Date { val: dt, span }, Err(_) => Value::Error { error: ShellError::UnsupportedInput(String::from("invalid time zone"), Span::unknown()), },