vieter/src/cron/expression_test.v

36 lines
922 B
Coq
Raw Normal View History

module cron
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-11-01 22:30:48 +01:00
fn util_test_time(exp string, t1_str string, t2_str string) ! {
ce := parse_expression(exp)!
t1 := parse(t1_str)!
t2 := parse(t2_str)!
2022-04-12 14:22:40 +02:00
t3 := ce.next(t1)
2022-04-12 14:22:40 +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-11-01 22:30:48 +01:00
fn test_next_simple() ! {
// Very simple
// util_test_time('0 3', '2002-01-01 00:00:00', '2002-01-01 03:00:00')!
// Overlap to next day
mut exp := '0 3 '
util_test_time(exp, '2002-01-01 03:00:00', '2002-01-02 03:00:00')!
util_test_time(exp, '2002-01-01 04:00:00', '2002-01-02 03:00:00')!
2022-04-12 14:22:40 +02:00
util_test_time('0 3-7/4,7-19', '2002-01-01 04:00:00', '2002-01-01 07:00:00')!
//// Overlap to next month
2022-11-01 22:30:48 +01:00
util_test_time('0 3', '2002-11-31 04:00:00', '2002-12-01 03:00:00')!
//// Overlap to next year
2022-11-01 22:30:48 +01: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
}