Frontend first draft
This commit is contained in:
20
frontend/pweb/lib/utils/time_ago.dart
Normal file
20
frontend/pweb/lib/utils/time_ago.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import 'package:timeago/timeago.dart' as timeago;
|
||||
|
||||
import 'package:pshared/models/storable.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
String timeAgo(BuildContext context, Storable storable) {
|
||||
// Use updatedAt if available; otherwise, fallback to createdAt.
|
||||
final timestamp = storable.updatedAt.isAfter(storable.createdAt)
|
||||
? storable.updatedAt
|
||||
: storable.createdAt;
|
||||
final timestampPrefix = storable.updatedAt.isAfter(storable.createdAt)
|
||||
? AppLocalizations.of(context)!.edited
|
||||
: AppLocalizations.of(context)!.created;
|
||||
|
||||
return '$timestampPrefix ${timeago.format(timestamp)}';
|
||||
}
|
||||
Reference in New Issue
Block a user