Skip to content

Commit 8238f68

Browse files
committed
fix first day of week again
1 parent a27a507 commit 8238f68

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

core/src/main/java/com/example/util/simpletimetracker/core/extension/OtherExtensions.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ fun Record.isNotFiltered(filter: TypesFilterParams): Boolean {
2222
}
2323

2424
fun Calendar.setWeekToFirstDay() {
25-
val currentTime = timeInMillis
26-
set(Calendar.DAY_OF_WEEK, firstDayOfWeek)
25+
val another = Calendar.getInstance()
26+
another.timeInMillis = timeInMillis
27+
28+
val currentTime = another.timeInMillis
29+
// Setting DAY_OF_WEEK have a weird behaviour so as if after that another field is set -
30+
// it would reset to current day. Use another calendar to manipulate day of week and get its time.
31+
another.set(Calendar.DAY_OF_WEEK, firstDayOfWeek)
2732
// If went to future - go back a week
28-
if (timeInMillis > currentTime) {
29-
add(Calendar.DATE, -7)
33+
if (another.timeInMillis > currentTime) {
34+
another.add(Calendar.DATE, -7)
3035
}
36+
37+
timeInMillis = another.timeInMillis
3138
}

0 commit comments

Comments
 (0)