diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt index 0f675a185..96a06617c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt @@ -899,7 +899,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { private fun getDateCodeFormatForView(view: Int, date: DateTime): String { return when (view) { - WEEKLY_VIEW -> getDatesWeekDateTime(date) + WEEKLY_VIEW -> getFirstDayOfWeek(date) YEARLY_VIEW -> date.toString() else -> Formatter.getDayCodeFromDateTime(date) } @@ -922,7 +922,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { when (config.storedView) { DAILY_VIEW -> bundle.putString(DAY_CODE, fixedDayCode ?: Formatter.getTodayCode()) - WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, fixedDayCode ?: getDatesWeekDateTime(DateTime())) + WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, fixedDayCode ?: getFirstDayOfWeek(DateTime())) MONTHLY_VIEW, MONTHLY_DAILY_VIEW -> bundle.putString(DAY_CODE, fixedDayCode ?: Formatter.getTodayCode()) YEARLY_VIEW -> bundle.putString(YEAR_TO_OPEN, fixedDayCode) } @@ -933,7 +933,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { } private fun fixDayCode(dayCode: String? = null): String? = when { - config.storedView == WEEKLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> getDatesWeekDateTime(Formatter.getDateTimeFromCode(dayCode)) + config.storedView == WEEKLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> getFirstDayOfWeek(Formatter.getDateTimeFromCode(dayCode)) config.storedView == YEARLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> Formatter.getYearFromDayCode(dayCode) else -> dayCode } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt index f25efbde4..d8aedb7d9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/extensions/Context.kt @@ -47,6 +47,7 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import kotlinx.android.synthetic.main.day_monthly_event_view.view.* import org.joda.time.DateTime +import org.joda.time.DateTimeConstants import org.joda.time.DateTimeZone import org.joda.time.LocalDate import java.io.File @@ -765,18 +766,18 @@ fun Context.editEvent(event: ListEvent) { } } -fun Context.getDatesWeekDateTime(date: DateTime): String { +fun Context.getFirstDayOfWeek(date: DateTime): String { var startOfWeek = date.withZoneRetainFields(DateTimeZone.UTC).withTimeAtStartOfDay() if (!config.startWeekWithCurrentDay) { startOfWeek = if (config.isSundayFirst) { // a workaround for Joda-time's Monday-as-first-day-of-the-week - if (startOfWeek.dayOfWeek == 7) { + if (startOfWeek.dayOfWeek == DateTimeConstants.SUNDAY) { startOfWeek } else { - startOfWeek.minusWeeks(1).withDayOfWeek(7) + startOfWeek.minusWeeks(1).withDayOfWeek(DateTimeConstants.SUNDAY) } } else { - startOfWeek.withDayOfWeek(1) + startOfWeek.withDayOfWeek(DateTimeConstants.MONDAY) } } return startOfWeek.toString() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt index b05906570..e8e5a60a3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/WeekFragmentsHolder.kt @@ -44,7 +44,7 @@ class WeekFragmentsHolder : MyFragmentHolder(), WeekFragmentListener { super.onCreate(savedInstanceState) val dateTimeString = arguments?.getString(WEEK_START_DATE_TIME) ?: return currentWeekTS = (DateTime.parse(dateTimeString) ?: DateTime()).seconds() - thisWeekTS = DateTime.parse(requireContext().getDatesWeekDateTime(DateTime())).seconds() + thisWeekTS = DateTime.parse(requireContext().getFirstDayOfWeek(DateTime())).seconds() } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {