fix: 修复假期小组件时间显示问题#31
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors widget schedule week computations so both platforms can compute the week for an arbitrary reference date, and updates “tomorrow week” to be derived by computing the week for an actual “tomorrow” date rather than using ad-hoc day checks.
Changes:
- iOS (Swift):
tomorrowWeeknow computes atomorrowDateand returnscurrentWeek(..., now: tomorrow). - Android (Kotlin): extracted
getWeek(termStart, now: Date)helper, madegetCurrentWeekdelegate to it, and updatedgetTomorrowWeekto compute tomorrow’sDateand pass it intogetWeek.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| targets/widget/Models/WidgetData.swift | Updates tomorrow-week logic to compute week based on an actual “tomorrow” date. |
| modules/widget/android/src/main/java/dev/tokenteam/iwut/widget/ScheduleData.kt | Extracts a shared week-calculation helper and uses it for both current and tomorrow week calculations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val diffMs = now.time - startDate.time | ||
| if (diffMs < 0) return 0 | ||
| val diffDays = TimeUnit.MILLISECONDS.toDays(diffMs) | ||
| return (diffDays / 7 + 1).toInt() |
| let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: now) ?? now | ||
| return currentWeek(termStart: termStart, now: tomorrow) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0b26b8274a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| val tomorrow = Calendar.getInstance().apply { | ||
| add(Calendar.DAY_OF_YEAR, 1) | ||
| }.time | ||
| return getWeek(termStart, tomorrow) |
There was a problem hiding this comment.
Normalize dates before deriving the Android tomorrow week
On Android devices in a daylight-saving timezone, this can select the wrong Monday courses during the hour after midnight on the spring-forward Sunday. For example, with a term starting 2026-03-02 in America/New_York, Sunday 2026-03-08 00:30 plus one calendar day is only 167.5 elapsed hours after the term start; TimeUnit.MILLISECONDS.toDays therefore yields 6 and keeps tomorrowWeek at week 1 instead of week 2. The previous Sunday-specific increment returned week 2, so compute the difference using normalized local dates/calendar days as the Swift implementation does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
modules/widget/android/src/main/java/dev/tokenteam/iwut/widget/ScheduleData.kt:107
normalizedDaycurrently builds the UTC Calendar using the device default locale/calendar. On devices using a non-Gregorian calendar,set(year, month, day)will interpret these fields in that calendar system and produce incorrect millis. UseCalendar.getInstance(utc, Locale.US)(or an explicitGregorianCalendar) so ISO date components are interpreted consistently.
Calendar.getInstance(TimeZone.getTimeZone("UTC")).apply {
clear()
set(year, month, day)
}.timeInMillis
| match.groupValues[2].toInt() - 1, | ||
| match.groupValues[3].toInt(), | ||
| ) | ||
| val nowCalendar = Calendar.getInstance().apply { time = now } |
| private fun getWeek(termStart: String, now: Date): Int { | ||
| val match = Regex("^(\\d{4})-(\\d{1,2})-(\\d{1,2})").find(termStart) ?: return 1 | ||
| val startDay = normalizedDay( |
fix #30
Motivation
Dateso tomorrow/week transitions are computed consistently across platforms.Description
getWeek(termStart: String, now: Date)and madegetCurrentWeekdelegate to it, and addedimport java.util.Datefor the new parameter type.getTomorrowWeekto compute the tomorrowDateviaCalendar.add(Calendar.DAY_OF_YEAR, 1)and callgetWeekwith that date.tomorrowWeek(termStart: String, now: Date)to computetomorrowusingCalendar.current.date(byAdding:.day, value: 1, to: now)and callcurrentWeek(termStart:now:)for the result.Testing
Codex Task