Skip to content

Fix Christmas countdown: replace silent fallback with connection state feedback#5

Draft
atarukun with Copilot wants to merge 4 commits into
christmasfrom
copilot/fix-christmas-countdown-bug
Draft

Fix Christmas countdown: replace silent fallback with connection state feedback#5
atarukun with Copilot wants to merge 4 commits into
christmasfrom
copilot/fix-christmas-countdown-bug

Conversation

Copilot AI commented Oct 30, 2025

Copy link
Copy Markdown

App displays 358 days until Christmas (should be ~56) because internet time fetch fails silently and falls back to uninitialized device time (Jan 1, 2025).

Changes

State machine for connection feedback

  • Added 4 states: IDLE, FETCHING, SUCCESS, FAILED
  • UI renders based on state: "Fetching date...", countdown, or "Unable to sync time from internet"
  • 10s timeout before transitioning FETCHING → FAILED

Removed unsafe fallback

  • get_days_until_christmas() no longer falls back to time.localtime()
  • Returns (days, has_valid_date) tuple; countdown only shown when has_valid_date=True
  • Prevents displaying incorrect values from uninitialized device clock

Timer fix for high frame rates

  • _fetch_start_time only resets when transitioning INTO FETCHING state
  • Prevents timeout from being defeated by repeated update() calls (60fps)
# Before: silent failure shows wrong value
def get_days_until_christmas():
    fetched = fetch_current_date()
    if fetched:
        year, month, day = fetched
    else:
        # Falls back to wrong device time
        now = time.localtime()
        year, month, day = now[0], now[1], now[2]
    # ... calculate using potentially wrong date

# After: explicit validity check
def get_days_until_christmas():
    fetched = fetch_current_date()
    if fetched:
        year, month, day = fetched
        has_valid_date = True
    else:
        return (0, False)  # Never show countdown with invalid date
    # ... calculate and return (days, has_valid_date)
Original prompt

There's still a bug in that this shows 358 days until Christmas. Please review the logic and determine what might be happening. It is supposed to use an internet connection to get the correct date. If that's failing, it shouldn't just display an incorrect number. Instead, it should show that it's either trying to connect to the internet, or unable to after a while if not successful. Please ask me if you have any questions.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits October 30, 2025 12:20
Co-authored-by: atarukun <6511495+atarukun@users.noreply.github.com>
Co-authored-by: atarukun <6511495+atarukun@users.noreply.github.com>
Co-authored-by: atarukun <6511495+atarukun@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect countdown calculation for Christmas Fix Christmas countdown: replace silent fallback with connection state feedback Oct 30, 2025
Copilot AI requested a review from atarukun October 30, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants