Context
LocalizedFormatters.formatRelativeTime
(lib/core/localization/localized_formatters.dart:168-189) documents itself
as producing both past and future phrasings:
Format relative time (e.g., "2 hours ago", "in 3 days")
The implementation cannot produce a future phrasing at all. It computes
now.difference(dateTime), which is negative for any future date, so
every > 0 branch is skipped and the fall-through returns
l10n.minutesAgo(difference.inMinutes.clamp(0, 59)) - and minutesAgo(0)
renders as "just now" in every shipped locale.
Verified with a probe test (temporary file, since removed):
$ flutter test test/_audit_probe_test.dart
in 3 days -> "Just now"
in 2 hours -> "Just now"
00:00 +1: All tests passed!
(probe body: LocalizedFormatters.formatRelativeTime(DateTime.now().add(const Duration(days: 3)), locale: const Locale('en')))
An adopter formatting a deadline, a scheduled event, or a task due date -
the natural uses of relative time in exactly the kind of app this template
scaffolds - silently gets "Just now" for everything upcoming. The existing
tests (test/core/localization/localized_formatters_test.dart:194-260)
only cover past dates, so nothing guards this.
Two acceptable resolutions; the criteria below allow either, but the
decision must be explicit:
- (a) implement future phrasings ("in X days" etc.) with properly extracted
plural strings in all four ARB files, or
- (b) declare the API past-only: fix the doc comment, and give future input
a defined, tested behavior (e.g. clamp to "just now" documented as
such).
Acceptance criteria
- The doc comment on
formatRelativeTime matches what the function
actually returns for a future DateTime. Observable: the example strings
in the doc are ones a flutter test case reproduces.
flutter test test/core/localization/localized_formatters_test.dart
passes with new cases passing DateTime.now().add(...) for at least
Duration(hours: 2) and Duration(days: 3), asserting the chosen
behavior - localized future phrasing under (a), or the documented
defined output under (b).
- Under (a) only: the future strings come from the ARB files (all four
locales), not from string interpolation in Dart, and a test asserts a
non-English locale renders a non-English future phrasing.
Context
LocalizedFormatters.formatRelativeTime(
lib/core/localization/localized_formatters.dart:168-189) documents itselfas producing both past and future phrasings:
The implementation cannot produce a future phrasing at all. It computes
now.difference(dateTime), which is negative for any future date, soevery
> 0branch is skipped and the fall-through returnsl10n.minutesAgo(difference.inMinutes.clamp(0, 59))- andminutesAgo(0)renders as "just now" in every shipped locale.
Verified with a probe test (temporary file, since removed):
(probe body:
LocalizedFormatters.formatRelativeTime(DateTime.now().add(const Duration(days: 3)), locale: const Locale('en')))An adopter formatting a deadline, a scheduled event, or a task due date -
the natural uses of relative time in exactly the kind of app this template
scaffolds - silently gets "Just now" for everything upcoming. The existing
tests (
test/core/localization/localized_formatters_test.dart:194-260)only cover past dates, so nothing guards this.
Two acceptable resolutions; the criteria below allow either, but the
decision must be explicit:
plural strings in all four ARB files, or
a defined, tested behavior (e.g. clamp to "just now" documented as
such).
Acceptance criteria
formatRelativeTimematches what the functionactually returns for a future
DateTime. Observable: the example stringsin the doc are ones a
flutter testcase reproduces.flutter test test/core/localization/localized_formatters_test.dartpasses with new cases passing
DateTime.now().add(...)for at leastDuration(hours: 2)andDuration(days: 3), asserting the chosenbehavior - localized future phrasing under (a), or the documented
defined output under (b).
locales), not from string interpolation in Dart, and a test asserts a
non-English locale renders a non-English future phrasing.