From 88a6b20ba5d8c265ae4e455444f2d76d4953834b Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Thu, 2 Feb 2023 13:30:48 +1100 Subject: [PATCH] Fixed date comparison with string date #1537 --- pkg/yqlib/{compare_operators.go => operator_compare.go} | 3 +-- ...compare_operators_test.go => operators_compare_test.go} | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) rename pkg/yqlib/{compare_operators.go => operator_compare.go} (98%) rename pkg/yqlib/{compare_operators_test.go => operators_compare_test.go} (97%) diff --git a/pkg/yqlib/compare_operators.go b/pkg/yqlib/operator_compare.go similarity index 98% rename from pkg/yqlib/compare_operators.go rename to pkg/yqlib/operator_compare.go index 904e1202..a33cfecf 100644 --- a/pkg/yqlib/compare_operators.go +++ b/pkg/yqlib/operator_compare.go @@ -3,7 +3,6 @@ package yqlib import ( "fmt" "strconv" - "time" yaml "gopkg.in/yaml.v3" ) @@ -80,7 +79,7 @@ func compareScalars(context Context, prefs compareTypePref, lhs *yaml.Node, rhs isDateTime := lhs.Tag == "!!timestamp" // if the lhs is a string, it might be a timestamp in a custom format. - if lhsTag == "!!str" && context.GetDateTimeLayout() != time.RFC3339 { + if lhsTag == "!!str" { _, err := parseDateTime(context.GetDateTimeLayout(), lhs.Value) isDateTime = err == nil } diff --git a/pkg/yqlib/compare_operators_test.go b/pkg/yqlib/operators_compare_test.go similarity index 97% rename from pkg/yqlib/compare_operators_test.go rename to pkg/yqlib/operators_compare_test.go index 0c13e241..cc7d5fb8 100644 --- a/pkg/yqlib/compare_operators_test.go +++ b/pkg/yqlib/operators_compare_test.go @@ -21,6 +21,13 @@ var compareOperatorScenarios = []expressionScenario{ "D0, P[k], (!!bool)::true\n", }, }, + { + skipDoc: true, + expression: `"2022-01-30T15:53:09Z" > "2020-01-30T15:53:09Z"`, + expected: []string{ + "D0, P[], (!!bool)::true\n", + }, + }, { skipDoc: true, document: "a: 5\nb: 4",