Repository navigation
Count notification retention in calendar days, not 336 hours #687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kurexw
wants to merge
4
commits into
OpenStrap:main
Choose a base branch
from
kurexw:fix/notify-retention-calendar-days
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−7
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // The fired-key / notification-slot retention cutoff is "14 calendar days | ||
| // before today". It used to be `now.subtract(Duration(days: 14))`, which is | ||
| // 336 h: across a DST change one of those days is 23 or 25 h, so in the hour | ||
| // either side of midnight the cutoff landed one day early or late. Real | ||
| // DST only bites if the PROCESS timezone has DST, so this moves it (libc | ||
| // setenv("TZ") + tzset(), as day_window_dst_test does). Windows has neither | ||
| // symbol, so the file is skipped there rather than failing in setUpAll. | ||
| @TestOn('!windows') | ||
| library; | ||
|
|
||
| import 'dart:ffi'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:ffi/ffi.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:openstrap_edge/notify/fired_keys.dart'; | ||
|
|
||
| typedef _SetenvNative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>, Int32); | ||
| typedef _SetenvDart = int Function(Pointer<Utf8>, Pointer<Utf8>, int); | ||
| typedef _UnsetenvNative = Int32 Function(Pointer<Utf8>); | ||
| typedef _UnsetenvDart = int Function(Pointer<Utf8>); | ||
| typedef _TzsetNative = Void Function(); | ||
| typedef _TzsetDart = void Function(); | ||
|
|
||
| void _setProcessTz(String? tz) { | ||
| final lib = DynamicLibrary.process(); | ||
| final key = 'TZ'.toNativeUtf8(); | ||
| try { | ||
| if (tz == null) { | ||
| lib.lookupFunction<_UnsetenvNative, _UnsetenvDart>('unsetenv')(key); | ||
| } else { | ||
| final value = tz.toNativeUtf8(); | ||
| lib.lookupFunction<_SetenvNative, _SetenvDart>('setenv')(key, value, 1); | ||
| calloc.free(value); | ||
| } | ||
| lib.lookupFunction<_TzsetNative, _TzsetDart>('tzset')(); | ||
| } finally { | ||
| calloc.free(key); | ||
| } | ||
| } | ||
|
|
||
| void main() { | ||
| final originalTz = Platform.environment['TZ']; | ||
| // America/New_York: 2026-03-08 is 23 h long, 2026-11-01 is 25 h long. | ||
| setUpAll(() => _setProcessTz('America/New_York')); | ||
| tearDownAll(() => _setProcessTz(originalTz)); | ||
|
|
||
| test('the host really is on a DST zone (or this test proves nothing)', () { | ||
| expect(DateTime(2026, 3, 9).difference(DateTime(2026, 3, 8)).inHours, 23); | ||
| }); | ||
|
|
||
| test('just after midnight, past a 23 h day: still 14 calendar days', () { | ||
| // 336 h before 00:30 lands at 23:30 on 02-22, a day too far back. | ||
| expect(FiredKeyStore.cutoffLabel(DateTime(2026, 3, 9, 0, 30)), | ||
| '2026-02-23'); | ||
| }); | ||
|
|
||
| test('just before midnight, past a 25 h day: still 14 calendar days', () { | ||
| // 336 h before 23:30 lands at 00:30 on 10-20, a day too recent. | ||
| expect(FiredKeyStore.cutoffLabel(DateTime(2026, 11, 2, 23, 30)), | ||
| '2026-10-19'); | ||
| }); | ||
|
|
||
| test('an ordinary day is unchanged', () { | ||
| expect(FiredKeyStore.cutoffLabel(DateTime(2026, 6, 20, 12)), '2026-06-06'); | ||
| }); | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.