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
This commit is contained in:
Abdo 2022-01-06 12:52:54 +03:00 committed by GitHub
parent 349d5d0862
commit aaaea03c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<pb::CardStatsResponse> {
@ -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,
),