20 lines
668 B
Dart
20 lines
668 B
Dart
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)}';
|
|
} |