mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 13:05:56 +00:00
minor: jsonx: time: iso8601
This commit is contained in:
@@ -68,7 +68,7 @@ func TestISO8601WithZoneUTCOffset(t *testing.T) {
|
||||
}
|
||||
|
||||
if expected, got := time.Date(2022, time.August, 10, 9, 49, 0, 0, loc).String(), v.End.ToTime().String(); expected != got {
|
||||
t.Fatalf("expected 'start' string to be: %v but got: %v", expected, got)
|
||||
t.Fatalf("expected 'end' string to be: %v but got: %v", expected, got)
|
||||
}
|
||||
|
||||
if expected, got := time.Date(2022, time.August, 10, 3, 21, 0, 0, loc), v.Start.ToTime().In(loc); expected != got {
|
||||
@@ -76,6 +76,48 @@ func TestISO8601WithZoneUTCOffset(t *testing.T) {
|
||||
}
|
||||
|
||||
if expected, got := time.Date(2022, time.August, 10, 9, 49, 0, 0, loc), v.End.ToTime().In(loc); expected != got {
|
||||
t.Fatalf("expected 'start' to be: %v but got: %v", expected, got)
|
||||
t.Fatalf("expected 'end' to be: %v but got: %v", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestISO8601WithZoneUTCOffsetWithoutMilliseconds(t *testing.T) {
|
||||
data := `{"start": "2023-02-04T09:48:14+00:00", "end": "2023-02-05T00:03:16+00:00", "nothing": null, "empty": ""}`
|
||||
v := struct {
|
||||
Start ISO8601 `json:"start"`
|
||||
End ISO8601 `json:"end"`
|
||||
Nothing ISO8601 `json:"nothing"`
|
||||
Empty ISO8601 `json:"empty"`
|
||||
}{}
|
||||
err := json.Unmarshal([]byte(data), &v)
|
||||
if err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
// t.Logf("Start: %s, location: %s\n", v.Start.String(), v.Start.ToTime().Location().String())
|
||||
|
||||
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.FixedZone("UTC", 0)
|
||||
|
||||
if expected, got := time.Date(2023, time.February, 04, 9, 48, 14, 0, loc).String(), v.Start.ToTime().String(); expected != got {
|
||||
t.Fatalf("expected 'start' string to be: %v but got: %v", expected, got)
|
||||
}
|
||||
|
||||
if expected, got := time.Date(2023, time.February, 05, 0, 3, 16, 0, loc).String(), v.End.ToTime().String(); expected != got {
|
||||
t.Fatalf("expected 'end' string to be: %v but got: %v", expected, got)
|
||||
}
|
||||
|
||||
if expected, got := time.Date(2023, time.February, 04, 9, 48, 14, 0, loc), v.Start.ToTime().In(loc); expected != got {
|
||||
t.Fatalf("expected 'start' to be: %v but got: %v", expected, got)
|
||||
}
|
||||
|
||||
if expected, got := time.Date(2023, time.February, 05, 0, 3, 16, 0, loc), v.End.ToTime().In(loc); expected != got {
|
||||
t.Fatalf("expected 'end' to be: %v but got: %v", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user