From e8b8836977d94d9dc606a491df5c6ace977584e9 Mon Sep 17 00:00:00 2001 From: Stefan Stanciulescu <71919805+onthebridgetonowhere@users.noreply.github.com> Date: Wed, 26 Jan 2022 22:54:31 +0100 Subject: [PATCH] Add suport for Filesize and Date for sort-by command (#855) --- crates/nu-command/src/filters/sort_by.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/nu-command/src/filters/sort_by.rs b/crates/nu-command/src/filters/sort_by.rs index 76dab26c89..b475d6a804 100644 --- a/crates/nu-command/src/filters/sort_by.rs +++ b/crates/nu-command/src/filters/sort_by.rs @@ -1,3 +1,4 @@ +use chrono::{DateTime, FixedOffset}; use nu_engine::column::column_does_not_exist; use nu_engine::CallExt; use nu_protocol::ast::Call; @@ -157,6 +158,8 @@ pub enum CompareValues { // Floats(f64, f64), String(String, String), Booleans(bool, bool), + Filesize(i64, i64), + Date(DateTime, DateTime), } impl CompareValues { @@ -167,6 +170,8 @@ impl CompareValues { // CompareValues::Floats(left, right) => left.cmp(right), CompareValues::String(left, right) => left.cmp(right), CompareValues::Booleans(left, right) => left.cmp(right), + CompareValues::Filesize(left, right) => left.cmp(right), + CompareValues::Date(left, right) => left.cmp(right), } } } @@ -176,11 +181,17 @@ pub fn coerce_compare( right: &Value, ) -> Result { match (left, right) { - /* - (Value::Float { val: left, .. }, Value::Float { val: right, .. }) => { - Ok(CompareValues::Floats(*left, *right)) + // (Value::Float { val: left, .. }, Value::Float { val: right, .. }) => { + // Ok(CompareValues::Floats(*left, *right)) + // } + (Value::Filesize { val: left, .. }, Value::Filesize { val: right, .. }) => { + Ok(CompareValues::Filesize(*left, *right)) } - */ + + (Value::Date { val: left, .. }, Value::Date { val: right, .. }) => { + Ok(CompareValues::Date(*left, *right)) + } + (Value::Int { val: left, .. }, Value::Int { val: right, .. }) => { Ok(CompareValues::Ints(*left, *right)) }