Skip to content

Commit 57af8e8

Browse files
committed
feat: show relative time on reset dates and billing period duration
Feat: _relativeTime() helper returns human-friendly countdown like (in 6d 16h), (in 3h 17m), or (in 45m). Billing Period line now shows total days: 2026-07-26 to 2026-08-26 (31 days) 5-Hour and Weekly reset lines now show countdown: Resets at: 2026-07-26 21:06 (in 3h 17m) Resets at: 2026-08-02 10:00 (in 6d 16h)
1 parent e3cfac0 commit 57af8e8

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

lib/src/tui/app.dart

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ class AppState extends State<CmdBridgeApp> {
833833
rows.add(Padding(
834834
padding: EdgeInsets.symmetric(vertical: 0),
835835
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
836-
Text(' ${_fmtDate(periodStart)} to ${_fmtDate(periodEnd)}', style: TextStyle(color: Colors.grey)),
836+
Text(' ${_fmtDate(periodStart)} to ${_fmtDate(periodEnd)} ($totalDays days)', style: TextStyle(color: Colors.grey)),
837837
SizedBox(height: 1),
838838
_bar(periodPct, Colors.blue, label: '${elapsedDays}d / ${totalDays}d elapsed'),
839839
SizedBox(height: 1),
@@ -1002,7 +1002,7 @@ class AppState extends State<CmdBridgeApp> {
10021002
Text('EXCEEDED', style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
10031003
]),
10041004
SizedBox(height: 1),
1005-
Text(' Resets at: ${_fmtDate(c.fiveHour.resetTime)}',
1005+
Text(' Resets at: ${_fmtDate(c.fiveHour.resetTime)} ${_relativeTime(c.fiveHour.resetTime)}',
10061006
style: TextStyle(color: Colors.grey)),
10071007
]),
10081008
));
@@ -1032,7 +1032,7 @@ class AppState extends State<CmdBridgeApp> {
10321032
Text('EXCEEDED', style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
10331033
]),
10341034
SizedBox(height: 1),
1035-
Text(' Resets at: ${_fmtDate(c.weekly.resetTime)}',
1035+
Text(' Resets at: ${_fmtDate(c.weekly.resetTime)} ${_relativeTime(c.weekly.resetTime)}',
10361036
style: TextStyle(color: Colors.grey)),
10371037
]),
10381038
));
@@ -1566,6 +1566,23 @@ class AppState extends State<CmdBridgeApp> {
15661566
return '${dt.year}-${dt.month.toString().padLeft(2, '0')}-${dt.day.toString().padLeft(2, '0')} ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
15671567
}
15681568

1569+
String _relativeTime(DateTime target) {
1570+
final diff = target.difference(DateTime.now());
1571+
if (diff.isNegative) return '(overdue)';
1572+
if (diff.inDays >= 1) {
1573+
final hours = diff.inHours.remainder(24);
1574+
return '(in ${diff.inDays}d ${hours}h)';
1575+
}
1576+
if (diff.inHours >= 1) {
1577+
final mins = diff.inMinutes.remainder(60);
1578+
return '(in ${diff.inHours}h ${mins}m)';
1579+
}
1580+
if (diff.inMinutes >= 1) {
1581+
return '(in ${diff.inMinutes}m)';
1582+
}
1583+
return '(now)';
1584+
}
1585+
15691586
String _fmtNum(int n) {
15701587
if (n >= 1000000) return '${(n / 1000000).toStringAsFixed(2)}M';
15711588
if (n >= 1000) return '${(n / 1000).toStringAsFixed(1)}K';

0 commit comments

Comments
 (0)