Merge branch 'main' into worktree-agent-aab11f4f1fe3dff6b
# Conflicts: # app/test/features/runs/ui/run_list_row_test.dart
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user