Skip to content

Commit

Permalink
Use backend to calculate legacy timezone
Browse files Browse the repository at this point in the history
I expect this fixes ankidroid#9368

Bumps the backend version, since the API changed.

Closes ankidroid#11881
  • Loading branch information
dae committed Jul 22, 2022
1 parent 87956b3 commit 092df5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 45 deletions.
19 changes: 12 additions & 7 deletions AnkiDroid/src/main/java/com/ichi2/libanki/sched/BaseSched.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.graphics.Typeface
import android.text.SpannableStringBuilder
import android.text.style.StyleSpan
import androidx.annotation.VisibleForTesting
import anki.ankidroid.schedTimingTodayLegacyRequest
import anki.decks.DeckTreeNode
import anki.scheduler.*
import com.ichi2.anki.R
Expand Down Expand Up @@ -478,13 +479,17 @@ abstract class BaseSched(val col: Collection) {
fun _timingToday(): SchedTimingTodayResponse {
return if (true) { // (BackendFactory.defaultLegacySchema) {
@Suppress("useless_cast")
return col.backend.schedTimingTodayLegacy(
col.crt,
col.get_config("creationOffset", 0 as Int)!!,
time.intTime(),
_current_timezone_offset(),
_rolloverHour()
)
val request = schedTimingTodayLegacyRequest {
createdSecs = col.crt
val minsWest = col.get_config("creationOffset", null as Int?)
if (minsWest != null) {
createdMinsWest = minsWest
}
nowSecs = time.intTime()
nowMinsWest = _current_timezone_offset()
rolloverHour = _rolloverHour()
}
return col.backend.schedTimingTodayLegacy(request)
} else {
// this currently breaks a bunch of unit tests that assume a mocked time,
// as it uses the real time to calculate daysElapsed
Expand Down
39 changes: 2 additions & 37 deletions AnkiDroid/src/main/java/com/ichi2/libanki/sched/SchedV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -2127,13 +2127,8 @@ public void _updateCutoff() {

SchedTimingTodayResponse timing = _timingToday();

if (_new_timezone_enabled()) {
mToday = timing.getDaysElapsed();
mDayCutoff = timing.getNextDayAt();
} else {
mToday = _daysSinceCreation();
mDayCutoff = _dayCutoff();
}
mToday = timing.getDaysElapsed();
mDayCutoff = timing.getNextDayAt();

if (oldToday != mToday) {
getCol().log(mToday, mDayCutoff);
Expand All @@ -2151,36 +2146,6 @@ public void _updateCutoff() {
}
}


private long _dayCutoff() {
int rolloverTime = getCol().get_config("rollover", 4);
if (rolloverTime < 0) {
rolloverTime = 24 + rolloverTime;
}
Calendar date = getTime().calendar();
date.set(Calendar.HOUR_OF_DAY, rolloverTime);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
Calendar today = getTime().calendar();
if (date.before(today)) {
date.add(Calendar.DAY_OF_MONTH, 1);
}

return date.getTimeInMillis() / 1000;
}


private int _daysSinceCreation() {
Calendar c = getCol().crtCalendar();
c.set(Calendar.HOUR, _rolloverHour());
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);

return (int) (((getTime().intTimeMS() - c.getTimeInMillis()) / 1000) / SECONDS_PER_DAY);
}

protected void update(@NonNull Deck g) {
for (String t : new String[] { "new", "rev", "lrn", "time" }) {
String key = t + "Today";
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
ext.kotlin_version = '1.7.0'
ext.lint_version = '30.2.1'
ext.acra_version = '5.7.0'
ext.ankidroid_backend_version = '0.1.14-anki2.1.54'
ext.ankidroid_backend_version = '0.1.15-anki2.1.54'
ext.hamcrest_version = '2.2'
ext.junit_version = '5.8.2'
ext.coroutines_version = '1.6.2'
Expand Down

0 comments on commit 092df5c

Please sign in to comment.