simplify how the local offset is passed around

- no need to store it in conf
- move local_minutes_west() call to collection
This commit is contained in:
Damien Elmes 2020-03-23 13:31:53 +10:00
parent dc8cf9d554
commit cd9ceebd59
2 changed files with 10 additions and 11 deletions

View file

@ -138,10 +138,6 @@ class _Collection:
self.sched = V1Scheduler(self)
elif ver == 2:
self.sched = V2Scheduler(self)
if not self.server:
self.conf["localOffset"] = self.sched._current_timezone_offset()
elif self.server.minutes_west is not None:
self.conf["localOffset"] = self.server.minutes_west
def changeSchedulerVer(self, ver: int) -> None:
if ver == self.schedVer():
@ -164,12 +160,13 @@ class _Collection:
self._loadScheduler()
# the sync code uses this to send the local timezone to AnkiWeb
def localOffset(self) -> Optional[int]:
"Minutes west of UTC. Only applies to V2 scheduler."
if isinstance(self.sched, V1Scheduler):
return None
else:
return self.sched._current_timezone_offset()
return self.backend.local_minutes_west(intTime())
# DB-related
##########################################################################

View file

@ -1392,14 +1392,16 @@ where id = ?
self._rolloverHour(),
)
def _current_timezone_offset(self) -> int:
def _current_timezone_offset(self) -> Optional[int]:
if self.col.server:
return self.col.conf.get("localOffset", None)
mins = self.col.server.minutes_west
if mins is not None:
return mins
# older Anki versions stored the local offset in
# the config
return self.col.conf.get("localOffset", 0)
else:
# note: while we could return None to sched_timing_today to have
# the backend calculate it, this function is also used to set
# localOffset, so it must not return None
return self.col.backend.local_minutes_west(intTime())
return None
def _creation_timezone_offset(self) -> Optional[int]:
return self.col.conf.get("creationOffset", None)