From a062e1bc2968cf02be26642dec516b900cbeba0f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 3 Jan 2018 12:00:41 +0900 Subject: [PATCH] store day rollover relative to local time --- anki/sched.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/anki/sched.py b/anki/sched.py index 1095731c7..330afe148 100644 --- a/anki/sched.py +++ b/anki/sched.py @@ -7,8 +7,8 @@ import random import itertools from operator import itemgetter from heapq import * +import datetime -#from anki.cards import Card from anki.utils import ids2str, intTime, fmtTimeSpan from anki.lang import _ from anki.consts import * @@ -1192,7 +1192,7 @@ did = ?, due = ?, usn = ? where id = ? # days since col created self.today = int((time.time() - self.col.crt) // 86400) # end of day cutoff - self.dayCutoff = self.col.crt + (self.today+1)*86400 + self.dayCutoff = self._dayCutoff() if oldToday != self.today: self.col.log(self.today, self.dayCutoff) # update all daily counts, but don't save decks to prevent needless @@ -1215,6 +1215,18 @@ did = ?, due = ?, usn = ? where id = ? if time.time() > self.dayCutoff: self.reset() + def _dayCutoff(self): + rolloverTime = self.col.conf.get("rollover", 4) + if rolloverTime < 0: + rolloverTime = 24+rolloverTime + date = datetime.datetime.today() + date = date.replace(hour=rolloverTime, minute=0, second=0, microsecond=0) + if date < datetime.datetime.today(): + date = date + datetime.timedelta(days=1) + + stamp = time.mktime(date.timetuple()) + return stamp + # Deck finished state ##########################################################################