time: sanity check parsed date/times

This commit is contained in:
Delyan Angelov 2021-10-09 10:46:04 +03:00
parent 3c7c11e55b
commit 23e679475c
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
2 changed files with 87 additions and 26 deletions

View file

@ -136,3 +136,26 @@ fn test_parse_iso8601_date_only() {
assert t.second == 0
assert t.microsecond == 0
}
fn check_invalid_date(s string) {
if date := time.parse(s) {
eprintln('invalid date: "$s" => "$date"')
assert false
}
assert true
}
fn test_invalid_dates_should_error_during_parse() {
check_invalid_date('-99999-12-20 00:00:00')
check_invalid_date('99999-12-20 00:00:00')
//
check_invalid_date('2008-00-20 00:00:00')
check_invalid_date('2008-25-20 00:00:00')
//
check_invalid_date('2008-12-00 00:00:00')
check_invalid_date('2008-12-32 00:00:00')
//
check_invalid_date('2008-12-01 30:00:00')
check_invalid_date('2008-12-01 00:60:00')
check_invalid_date('2008-12-01 00:01:60')
}