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

minor improvement of the x/jsonx.SimpleDate time parser

more features designed for the past 2-3 months to come, this is just a hotfix
This commit is contained in:
Gerasimos (Makis) Maropoulos
2024-04-08 21:39:45 +03:00
parent 384ca4db70
commit c2238c71b8
2 changed files with 66 additions and 8 deletions

View File

@@ -57,3 +57,37 @@ func TestSimpleDateAterBefore(t *testing.T) {
t.Fatalf("[after] expected d2 to be after d1")
}
}
func TestCountPastDays(t *testing.T) {
tests := []struct {
AfterDate SimpleDate
BeforeDate SimpleDate
ExpectedPastDays int
}{
{
AfterDate: mustParseSimpleDate("2023-01-01"),
BeforeDate: mustParseSimpleDate("2022-12-31"),
ExpectedPastDays: 1,
},
{
AfterDate: mustParseSimpleDate("2023-01-01"),
BeforeDate: mustParseSimpleDate("2022-01-01"),
ExpectedPastDays: 365,
},
}
for i, tt := range tests {
if expected, got := tt.ExpectedPastDays, tt.AfterDate.CountPastDays(tt.BeforeDate); expected != got {
t.Fatalf("[%d] expected past days count: %d but got: %d", i, expected, got)
}
}
}
func mustParseSimpleDate(s string) SimpleDate {
d, err := ParseSimpleDate(s)
if err != nil {
panic(err)
}
return d
}