Skip to content

fix: 修复假期小组件时间显示问题#31

Merged
zhxycn merged 3 commits into
mainfrom
codex/github-mention-bug]
Jul 26, 2026
Merged

fix: 修复假期小组件时间显示问题#31
zhxycn merged 3 commits into
mainfrom
codex/github-mention-bug]

Conversation

@zhxycn

@zhxycn zhxycn commented Jul 26, 2026

Copy link
Copy Markdown
Member

fix #30

Motivation

  • Ensure week calculations can be evaluated for an arbitrary Date so tomorrow/week transitions are computed consistently across platforms.
  • Unify logic so the "tomorrow" week uses the start-of-day-aware week computation instead of ad-hoc day checks.

Description

  • Kotlin: extracted a private helper getWeek(termStart: String, now: Date) and made getCurrentWeek delegate to it, and added import java.util.Date for the new parameter type.
  • Kotlin: updated getTomorrowWeek to compute the tomorrow Date via Calendar.add(Calendar.DAY_OF_YEAR, 1) and call getWeek with that date.
  • Swift: updated tomorrowWeek(termStart: String, now: Date) to compute tomorrow using Calendar.current.date(byAdding:.day, value: 1, to: now) and call currentWeek(termStart:now:) for the result.

Testing

  • No automated tests were run for this change.

Codex Task

Copilot AI review requested due to automatic review settings July 26, 2026 09:16
@zhxycn zhxycn changed the title Widget schedule: compute week for arbitrary date and use tomorrow's date for tomorrowWeek (Kotlin & Swift) fix: 修复假期小组件时间显示问题 Jul 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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): tomorrowWeek now computes a tomorrow Date and returns currentWeek(..., now: tomorrow).
  • Android (Kotlin): extracted getWeek(termStart, now: Date) helper, made getCurrentWeek delegate to it, and updated getTomorrowWeek to compute tomorrow’s Date and pass it into getWeek.

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.

Comment on lines 93 to 96
val diffMs = now.time - startDate.time
if (diffMs < 0) return 0
val diffDays = TimeUnit.MILLISECONDS.toDays(diffMs)
return (diffDays / 7 + 1).toInt()
Comment on lines +125 to +126
let tomorrow = Calendar.current.date(byAdding: .day, value: 1, to: now) ?? now
return currentWeek(termStart: termStart, now: tomorrow)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +114 to +117
val tomorrow = Calendar.getInstance().apply {
add(Calendar.DAY_OF_YEAR, 1)
}.time
return getWeek(termStart, tomorrow)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copilot AI review requested due to automatic review settings July 26, 2026 09:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • normalizedDay currently 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. Use Calendar.getInstance(utc, Locale.US) (or an explicit GregorianCalendar) 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 }
Copilot AI review requested due to automatic review settings July 26, 2026 09:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +86 to +88
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(
@zhxycn
zhxycn merged commit e572abd into main Jul 26, 2026
9 checks passed
@zhxycn
zhxycn deleted the codex/github-mention-bug] branch July 26, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 小组件课程时间加载不正确

2 participants