Repository navigation
fix: count a new daily limit from when it's set on its first day - #135
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
dropped, 0.1 s after the interval started. Used 5+ more minutes, never blocked.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."includesPastActivityfalsetruetrueUsageLimit.createdAt(optional, so existing stores open without migration) is passed throughUsageLimitDTO.createdAt(optional, so earlier app-group data still decodes).UsagePeriod.countsPastActivity(createdAt:on:)decides it, for both registration and the editor's text.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
createdAt == nil.includesPastActivity: falsesometimes never fires on iOS 17 and 18 (FB15220094).