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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user