Skip to content

fix: count a new daily limit from when it's set on its first day - #135

Merged
ykisana merged 1 commit into
mainfrom
fix/daily-limit-count-from-creation
Nov 19, 2026
Merged

ykisana merged 1 commit into
mainfrom
fix/daily-limit-count-from-creation

Conversation

@ykisana

@ykisana ykisana commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Problem

A daily limit added after its apps were already used today never blocked that day.

The limit's threshold event counted the whole day (includesPastActivity: true), so when the apps were already past the limit, iOS fired the threshold 0.1 s after the limit was registered. The monitor drops thresholds that arrive within 10 s of registering, as a guard against iOS's false fires at registration. iOS fires each threshold only once a day, so the limit stayed off until the reset.

Device log (iOS 26, 5-minute limits):

  • App used for 5+ minutes, limit added at 18:49:51 → dropped, 0.1 s after the interval started. Used 5+ more minutes, never blocked.
  • App used for ~1 minute, limit added → blocked after 5 minutes of total use.
  • App not used yet, limit added → blocked after 5 minutes.

Fix

A new limit counts from when it's set on its first day, then the whole day from the next reset.

Apple's DeviceActivityEvent(…, includesPastActivity:) (iOS 17.4+): "Whether the system takes into account the person's device activity before your app starts monitoring the event."

Limit includesPastActivity Counts
Created today false Only time after it's saved
Created on an earlier day true Whole day, so re-registering can't refund time
Saved before this change true Whole day, as before
  • UsageLimit.createdAt (optional, so existing stores open without migration) is passed through UsageLimitDTO.createdAt (optional, so earlier app-group data still decodes).
  • UsagePeriod.countsPastActivity(createdAt:on:) decides it, for both registration and the editor's text.
  • Editor footer for a new limit: "…Today, only time after you save counts." Older limits keep the existing text.
  • Max Daily Limits guide: "On the day you add a limit, only time after that counts."

Known limitation

On the day a limit is created, adding or editing another limit re-registers every limit and restarts the new one's count. From the next reset it counts the whole day.

Tests

A limit added after its apps were already used counted the whole day. If they
were already past it, the threshold fired as the limit was registered, the
monitor dropped it as a likely false fire, and the limit never blocked that
day. New limits now count only usage after they're registered on the day
they're created (includesPastActivity: false). From the next reset they count
the whole day as before, so re-registering can't refund time. Limits saved
before this change keep counting the whole day.
@ykisana
ykisana merged commit 206294c into main Nov 19, 2026
4 checks passed
@ykisana
ykisana deleted the fix/daily-limit-count-from-creation branch November 19, 2026 04:24
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