1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-07-17 01:32:22 +02:00

Added support of parsing DateTime with a custom layout (#721)

* Added support of parsing DateTime with a custom layout
This commit is contained in:
Tim Voronov
2022-01-02 23:40:42 -05:00
committed by GitHub
parent 4e94caa55f
commit b0377c1bcc
3 changed files with 50 additions and 18 deletions

View File

@ -2,6 +2,7 @@ package datetime_test
import (
"testing"
"time"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
@ -10,29 +11,32 @@ import (
)
func TestDate(t *testing.T) {
now := time.Now()
tcs := []*testCase{
&testCase{
Name: "When more than 1 arguments",
{
Name: "When more than 2 arguments",
Expected: values.None,
Args: []core.Value{
values.NewString("string"),
values.NewInt(0),
values.NewString(time.Now().Format(time.RFC3339)),
values.NewString(time.RFC3339),
values.NewString("foo"),
},
ShouldErr: true,
},
&testCase{
{
Name: "When 0 arguments",
Expected: values.None,
Args: []core.Value{},
ShouldErr: true,
},
&testCase{
Name: "When argument isn't DateTime",
{
Name: "When first argument isn't string",
Expected: values.None,
Args: []core.Value{values.NewInt(0)},
ShouldErr: true,
},
&testCase{
{
Name: "When incorrect timeStrings",
Expected: values.None,
Args: []core.Value{
@ -40,13 +44,31 @@ func TestDate(t *testing.T) {
},
ShouldErr: true,
},
&testCase{
Name: "When correct timeString in RFC3339 format",
{
Name: "When string is in default format",
Expected: mustDefaultLayoutDt("1999-02-07T15:04:05Z"),
Args: []core.Value{
values.NewString("1999-02-07T15:04:05Z"),
},
},
{
Name: "When second argument isn't string",
Expected: values.None,
Args: []core.Value{
values.NewString("1999-02-07T15:04:05Z"),
values.NewInt(1),
},
ShouldErr: true,
},
{
Name: "When string is in custom format",
Expected: mustLayoutDt(time.RFC822, now.Format(time.RFC822)),
Args: []core.Value{
values.NewString(now.Format(time.RFC822)),
values.NewString(time.RFC822),
},
ShouldErr: false,
},
}
for _, tc := range tcs {