From aaaea03c722cbfbf2d94e3c590c5f1b95a283ce9 Mon Sep 17 00:00:00 2001 From: Abdo Date: Thu, 6 Jan 2022 12:52:54 +0300 Subject: [PATCH] Fix new preview card's position being interpreted as a date (#1577) * Fix new preview card's position being interpreted as a date Can be reproduced by opening the Card Info screen of a new preview card not answered yet. * Update rslib/src/stats/card.rs --- rslib/src/stats/card.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/rslib/src/stats/card.rs b/rslib/src/stats/card.rs index aebb4c548..60bfb8a20 100644 --- a/rslib/src/stats/card.rs +++ b/rslib/src/stats/card.rs @@ -1,7 +1,12 @@ // Copyright: Ankitects Pty Ltd and contributors // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -use crate::{backend_proto as pb, card::CardQueue, prelude::*, revlog::RevlogEntry}; +use crate::{ + backend_proto as pb, + card::{CardQueue, CardType}, + prelude::*, + revlog::RevlogEntry, +}; impl Collection { pub fn card_stats(&mut self, cid: CardId) -> Result { @@ -66,10 +71,15 @@ impl Collection { ), CardQueue::Review | CardQueue::DayLearn => ( { - let days_remaining = due - (self.timing_today()?.days_elapsed as i32); - let mut due = TimestampSecs::now(); - due.0 += (days_remaining as i64) * 86_400; - Some(pb::generic::Int64 { val: due.0 }) + if card.ctype == CardType::New { + // new preview card not answered yet + None + } else { + let days_remaining = due - (self.timing_today()?.days_elapsed as i32); + let mut due = TimestampSecs::now(); + due.0 += (days_remaining as i64) * 86_400; + Some(pb::generic::Int64 { val: due.0 }) + } }, None, ),