Fixed date comparison with string date #1537

This commit is contained in:
Mike Farah 2023-02-02 13:30:48 +11:00
parent 915ab69922
commit 88a6b20ba5
2 changed files with 8 additions and 2 deletions

View File

@ -3,7 +3,6 @@ package yqlib
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"time"
yaml "gopkg.in/yaml.v3" yaml "gopkg.in/yaml.v3"
) )
@ -80,7 +79,7 @@ func compareScalars(context Context, prefs compareTypePref, lhs *yaml.Node, rhs
isDateTime := lhs.Tag == "!!timestamp" isDateTime := lhs.Tag == "!!timestamp"
// if the lhs is a string, it might be a timestamp in a custom format. // 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) _, err := parseDateTime(context.GetDateTimeLayout(), lhs.Value)
isDateTime = err == nil isDateTime = err == nil
} }

View File

@ -21,6 +21,13 @@ var compareOperatorScenarios = []expressionScenario{
"D0, P[k], (!!bool)::true\n", "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, skipDoc: true,
document: "a: 5\nb: 4", document: "a: 5\nb: 4",