fe24f228fe
Review r2 findings P2-4, P2-5, P3-13: a shared relative-time helper for
every list row's time, formatDuration switches to days past 24h ('9d
16h'), the stage page uses one visit numbering, drops a repeated stage
heading and fixes '1 files', and search run hits read 'Run 1'.
Implemented by pipeline run #205/#207 (Terra); its UIReview blocked on a
fixture without timestamps, verified by the manager.
41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
const _monthNames = <String>[
|
|
'Jan',
|
|
'Feb',
|
|
'Mar',
|
|
'Apr',
|
|
'May',
|
|
'Jun',
|
|
'Jul',
|
|
'Aug',
|
|
'Sep',
|
|
'Oct',
|
|
'Nov',
|
|
'Dec',
|
|
];
|
|
|
|
/// A compact local recency label for list rows.
|
|
///
|
|
/// Past instants use `just now`, `Nm`, `Nh`, or `Nd` for their first week,
|
|
/// then a short local date. Future instants use the same compact units with an
|
|
/// `in` prefix, which keeps scheduled rows truthful.
|
|
String? formatRelativeTime(DateTime? instant, {DateTime? now}) {
|
|
if (instant == null) return null;
|
|
final current = now ?? DateTime.now();
|
|
final seconds = instant.difference(current).inSeconds;
|
|
final future = seconds > 0;
|
|
final age = seconds.abs();
|
|
if (age < 60) return 'just now';
|
|
final prefix = future ? 'in ' : '';
|
|
if (age < 3600) return '$prefix${age ~/ 60}m';
|
|
if (age < 86400) return '$prefix${age ~/ 3600}h';
|
|
if (age < 7 * 86400) return '$prefix${age ~/ 86400}d';
|
|
final local = instant.toLocal();
|
|
return '${local.day} ${_monthNames[local.month - 1]}';
|
|
}
|
|
|
|
/// Parses [text] as an RFC3339 timestamp before formatting it for a list row.
|
|
String? formatRelativeTimestamp(String? text, {DateTime? now}) {
|
|
final value = text?.trim() ?? '';
|
|
return formatRelativeTime(DateTime.tryParse(value), now: now);
|
|
}
|