From 86055bb564dd6e02dfa89c878e2e12d5a7ebab0f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 7 Jan 2020 09:28:09 +1000 Subject: [PATCH] add failing test for days_elapsed calculation the current code was causing the day to move backwards: at day 7 hour 23:59, elap is 1 at day 8 hour 0:59, elap is 0 at day 8 hour 1:59, elap is 0 at day 8 hour 2:59, elap is 1 at day 8 hour 3:59, elap is 1 at day 8 hour 4:59, elap is 2 as mentioned in https://github.com/ankitects/anki/pull/416 --- rslib/src/sched.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rslib/src/sched.rs b/rslib/src/sched.rs index 41d41ecc7..530b2eb6e 100644 --- a/rslib/src/sched.rs +++ b/rslib/src/sched.rs @@ -154,5 +154,16 @@ mod test { // to DST, but the number shouldn't change let offset = mdt.utc_minus_local() / 60; assert_eq!(elap(crt, now, offset, 4), 507); + + // collection created at 3am on the 6th, so day 1 starts at 4am on the 7th, and day 3 on the 9th. + let crt = mdt.ymd(2018, 8, 6).and_hms(3, 0, 0).timestamp(); + + let mst_offset = mst.utc_minus_local() / 60; + let now = mst.ymd(2018, 8, 9).and_hms(1, 59, 59).timestamp(); + assert_eq!(elap(crt, now, mst_offset, 4), 2); + let now = mst.ymd(2018, 8, 9).and_hms(3, 59, 59).timestamp(); + assert_eq!(elap(crt, now, mst_offset, 4), 2); + let now = mst.ymd(2018, 8, 9).and_hms(4, 0, 0).timestamp(); + assert_eq!(elap(crt, now, mst_offset, 4), 3); } }