Date literals (#4619)

* Date literals

* update deps

* Add date+duration
This commit is contained in:
JT
2022-02-23 21:02:48 -05:00
committed by GitHub
parent 63487941fb
commit 4b18fdcc6e
19 changed files with 201 additions and 23 deletions

View File

@ -30,7 +30,7 @@ calamine = "0.18.0"
chrono = { version = "0.4.19", features = ["serde"] }
chrono-humanize = "0.2.1"
chrono-tz = "0.6.0"
crossterm = "0.22.1"
crossterm = "0.23"
csv = "1.1.3"
dialoguer = "0.9.0"
digest = "0.10.0"
@ -47,7 +47,7 @@ Inflector = "0.11"
itertools = "0.10.0"
lazy_static = "1.4.0"
log = "0.4.14"
lscolors = { version = "0.8.0", features = ["crossterm"] }
lscolors = { version = "0.9.0", features = ["crossterm"] }
md5 = { package = "md-5", version = "0.10.0" }
meval = "0.2.0"
mime = "0.3.16"

View File

@ -41,8 +41,8 @@ impl Command for UpdateCells {
Example {
description: "Update the zero value cells to empty strings.",
example: r#"[
[2021-04-16, 2021-06-10, 2021-09-18, 2021-10-15, 2021-11-16, 2021-11-17, 2021-11-18];
[ 37, 0, 0, 0, 37, 0, 0]
["2021-04-16", "2021-06-10", "2021-09-18", "2021-10-15", "2021-11-16", "2021-11-17", "2021-11-18"];
[ 37, 0, 0, 0, 37, 0, 0]
] | update cells {|value|
if $value == 0 {
""
@ -78,8 +78,8 @@ impl Command for UpdateCells {
Example {
description: "Update the zero value cells to empty strings in 2 last columns.",
example: r#"[
[2021-04-16, 2021-06-10, 2021-09-18, 2021-10-15, 2021-11-16, 2021-11-17, 2021-11-18];
[ 37, 0, 0, 0, 37, 0, 0]
["2021-04-16", "2021-06-10", "2021-09-18", "2021-10-15", "2021-11-16", "2021-11-17", "2021-11-18"];
[ 37, 0, 0, 0, 37, 0, 0]
] | update cells -c ["2021-11-18", "2021-11-17"] {|value|
if $value == 0 {
""

View File

@ -212,6 +212,7 @@ fn convert_to_value(
"subexpressions and cellpaths not supported in nuon".into(),
expr.span,
)),
Expr::DateTime(dt) => Ok(Value::Date { val: dt, span }),
Expr::ExternalCall(..) => Err(ShellError::OutsideSpannedLabeledError(
original_text.to_string(),
"Error when loading".into(),

View File

@ -57,7 +57,7 @@ fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
}
Value::CellPath { .. } => Err(ShellError::UnsupportedInput("cellpath".to_string(), span)),
Value::CustomValue { .. } => Err(ShellError::UnsupportedInput("custom".to_string(), span)),
Value::Date { .. } => Err(ShellError::UnsupportedInput("date".to_string(), span)),
Value::Date { val, .. } => Ok(val.to_rfc3339()),
Value::Duration { val, .. } => Ok(format!("{}ns", *val)),
Value::Error { .. } => Err(ShellError::UnsupportedInput("error".to_string(), span)),
Value::Filesize { val, .. } => Ok(format!("{}b", *val)),