Skip to content

Reset countdown at midnight after overtime - #37

Merged
KTSCode merged 4 commits into
mainfrom
todo/midnight_reset
Jun 8, 2026
Merged

Reset countdown at midnight after overtime#37
KTSCode merged 4 commits into
mainfrom
todo/midnight_reset

Conversation

@KTSCode

@KTSCode KTSCode commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Overtime is a single-day opt-out, but leaving the machine on past midnight parked the Countdown daemon in :done — the next day's shutdown was never enforced.
  • Arm a one-shot midnight timer at init. On fire it resets the GenServer to a fresh state (mode: :severance, phase: :waiting), reschedules the countdown start, and re-arms itself for the following midnight.
  • Add ms_until_midnight/1 for the timer math (with doctest) and document the reset in the README Overtime Protocol section.

Test plan

  • mix test test/severance/countdown_test.exs — new tests cover reset-to-waiting, reschedule-into-countdown, and ms_until_midnight/1
  • mix quality — format, compile, credo, dialyzer, doctor, tests + coverage all pass

Leaving the machine on past midnight after overtime parked the daemon
in :done, so the next day's shutdown was never enforced. Arm a midnight
timer that resets to severance mode and waiting, reschedules the
countdown, and re-arms itself.

@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: 0680e68086

ℹ️ 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 thread lib/severance/countdown.ex
KTSCode added 3 commits June 8, 2026 09:41
The reset timer waits monotonic milliseconds, but the interval to the
next midnight is wall-clock, so a DST transition fires it up to an hour
off. Track the session's local date and only roll over once the date has
actually advanced; an early fire just re-arms, which re-reads the clock
and self-corrects.
The day-rollover decision lived inside the GenServer callback and read
the clock through the now_fn injection, forcing tests to override it.
Move it into a pure reset_state/2 that takes the current day as an
argument, so the rollover and DST early-fire cases test directly without
dependency injection.
…me is a single-day opt-out and the next day's shutdown is enforced again
@KTSCode
KTSCode merged commit 182f211 into main Jun 8, 2026
@KTSCode
KTSCode deleted the todo/midnight_reset branch June 8, 2026 18:28
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.

1 participant