1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 20:07:04 +00:00

add x/jsonx.DayTime type

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-02-27 22:38:09 +02:00
parent b4b1f73df6
commit 5844eaef24
5 changed files with 156 additions and 2 deletions

52
x/jsonx/day_time_test.go Normal file
View File

@@ -0,0 +1,52 @@
package jsonx
import (
"encoding/json"
"testing"
"time"
)
func TestDayTime(t *testing.T) {
tests := []struct {
rawData string
}{
{
rawData: `{"start": "8:33:00", "end": "15:00:42", "nothing": null, "empty": ""}`,
},
{
rawData: `{"start": "8:33:00", "end": "15:00:42", "nothing": null, "empty": ""}`,
},
}
for _, tt := range tests {
v := struct {
Start DayTime `json:"start"`
End DayTime `json:"end"`
Nothing DayTime `json:"nothing"`
Empty DayTime `json:"empty"`
}{}
err := json.Unmarshal([]byte(tt.rawData), &v)
if err != nil {
t.Fatal(err)
}
if !v.Nothing.IsZero() {
t.Fatalf("expected 'nothing' to be zero but got: %v", v.Nothing)
}
if !v.Empty.IsZero() {
t.Fatalf("expected 'empty' to be zero but got: %v", v.Empty)
}
loc := time.UTC
if expected, got := time.Date(0, time.January, 1, 8, 33, 0, 0, loc), v.Start.ToTime(); expected != got {
t.Fatalf("expected 'start' to be: %v but got: %v", expected, got)
}
if expected, got := time.Date(0, time.January, 1, 15, 0, 42, 0, loc), v.End.ToTime(); expected != got {
t.Fatalf("expected 'start' to be: %v but got: %v", expected, got)
}
}
}