Use the local day of the last Habitica cron for the calendars by frenck · Pull Request #184613 · home-assistant/core · GitHub
Skip to content

Use the local day of the last Habitica cron for the calendars - #184613

Merged
MartinHjelmare merged 2 commits into
devfrom
frenck/fix-habitica-calendar-local-day
Oct 7, 2026
Merged

MartinHjelmare merged 2 commits into
devfrom
frenck/fix-habitica-calendar-local-day

Conversation

@frenck

@frenck frenck commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Breaking change

Proposed change

The Habitica calendars derive "today" from the user's last cron, but passed the UTC lastCron timestamp straight to start_of_local_day, which takes the date part as is. When the cron ran shortly after local midnight in a timezone ahead of UTC (for example 00:03 in Europe/Berlin, which is still the previous day in UTC), the calendars treated yesterday as today: yesterday's open dailies showed up as current and today's completed dailies were still listed.

The last cron is now converted to local time before taking the start of the day, like the to-do platform already does. The existing test fixture happens to have exactly this case, so the calendar snapshots are updated to the correct day.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI balanced review requested due to automatic review settings October 7, 2026 05:30
@home-assistant

home-assistant Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused correction and regression expectations are consistent, with no blocking issues identified; tests were not run.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes Habitica calendars using the UTC date instead of the local date of the last cron.

Changes:

  • Converts the last cron to local time before deriving the day, preserving the fallback when absent.
  • Adds a timezone regression test and updates calendar snapshots.
File Description
tests/​components/​habitica/​test_calendar.py Tests the local-day boundary case.
tests/​components/​habitica/​snapshots/​test_calendar.ambr Updates expected daily and reminder events.
homeassistant/​components/​habitica/​calendar.py Corrects the shared local-day calculation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@frenck frenck added this to the 2026.10.0 milestone Oct 7, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generated by quality-scale-reviewer · copilot · auto · 125.9 AIC · ⌖ 4.79 AIC · ⊞ 8.1K

Comment thread homeassistant/components/habitica/calendar.py

@epenet epenet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Coverage could be improved, but it's not blocking.

It could be covered by parametrizing the new test, e.g. setting habitica.get_user.return_value.data.lastCron = None and asserting the dailies start today.

@frenck

frenck commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

Copilot AI balanced review requested due to automatic review settings October 7, 2026 06:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused fix preserves fallback behavior and has regression coverage with consistent snapshot updates.

Review effort: Balanced
Findings: None

@MartinHjelmare
MartinHjelmare merged commit 21cea4d into dev Oct 7, 2026
37 checks passed
@MartinHjelmare
MartinHjelmare deleted the frenck/fix-habitica-calendar-local-day branch October 7, 2026 09:44
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timezone issue with Habitica integration resulting in wrong counting of open Dailies

4 participants