Address clippy's warnings when porting date to engine-q

This commit is contained in:
Stefan Stanciulescu 2021-10-31 21:06:44 +01:00
parent 3437dacf0b
commit 032356bfb7
5 changed files with 33 additions and 56 deletions

View file

@ -77,18 +77,26 @@ fn format_helper(value: Value, formatter: &Spanned<String>, 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<String>, span: Span) -> Value
.with_timezone(dt.offset())
.format(formatter.item.as_str())
.to_string(),
span: span,
span,
}
}
_ => unsupported_input_error(),

View file

@ -28,19 +28,16 @@ impl Command for SubCommand {
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let span = call.head;
let tzs: Vec<Value> = 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()))
}

View file

@ -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;

View file

@ -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 })
},
},
]

View file

@ -93,12 +93,9 @@ fn helper(value: Value, head: Span, timezone: &Spanned<String>) -> 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<String>) -> Value {
}
fn _to_timezone(dt: DateTime<FixedOffset>, timezone: &Spanned<String>, 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()),
},