2022-04-13 16:12:22 +02:00
|
|
|
module expression
|
2022-04-12 14:22:40 +02:00
|
|
|
|
2022-04-12 20:53:20 +02:00
|
|
|
import time { parse }
|
2022-04-12 14:22:40 +02:00
|
|
|
|
2022-04-12 21:16:09 +02:00
|
|
|
fn util_test_time(exp string, t1_str string, t2_str string) ? {
|
2022-05-14 20:06:08 +02:00
|
|
|
ce := parse_expression(exp)?
|
|
|
|
t1 := parse(t1_str)?
|
|
|
|
t2 := parse(t2_str)?
|
2022-04-12 14:22:40 +02:00
|
|
|
|
2022-05-14 20:06:08 +02:00
|
|
|
t3 := ce.next(t1)?
|
2022-04-12 14:22:40 +02:00
|
|
|
|
2022-04-12 21:16:09 +02:00
|
|
|
assert t2.year == t3.year
|
|
|
|
assert t2.month == t3.month
|
|
|
|
assert t2.day == t3.day
|
|
|
|
assert t2.hour == t3.hour
|
|
|
|
assert t2.minute == t3.minute
|
2022-04-12 14:22:40 +02:00
|
|
|
}
|
|
|
|
|
2022-04-12 21:16:09 +02:00
|
|
|
fn test_next_simple() ? {
|
|
|
|
// Very simple
|
2022-05-14 20:06:08 +02:00
|
|
|
util_test_time('0 3', '2002-01-01 00:00:00', '2002-01-01 03:00:00')?
|
2022-04-12 21:16:09 +02:00
|
|
|
|
|
|
|
// Overlap to next day
|
2022-05-14 20:06:08 +02:00
|
|
|
util_test_time('0 3', '2002-01-01 03:00:00', '2002-01-02 03:00:00')?
|
|
|
|
util_test_time('0 3', '2002-01-01 04:00:00', '2002-01-02 03:00:00')?
|
2022-04-12 14:22:40 +02:00
|
|
|
|
2022-05-14 20:06:08 +02:00
|
|
|
util_test_time('0 3/4', '2002-01-01 04:00:00', '2002-01-01 07:00:00')?
|
2022-04-12 21:23:38 +02:00
|
|
|
|
|
|
|
// Overlap to next month
|
2022-05-14 20:06:08 +02:00
|
|
|
util_test_time('0 3', '2002-11-31 04:00:00', '2002-12-01 03:00:00')?
|
2022-04-12 21:23:38 +02:00
|
|
|
|
|
|
|
// Overlap to next year
|
2022-05-14 20:06:08 +02:00
|
|
|
util_test_time('0 3', '2002-12-31 04:00:00', '2003-01-01 03:00:00')?
|
2022-04-12 14:22:40 +02:00
|
|
|
}
|