Merge pull request 'fixed time ago in notifications' (#174) from fixed_timeago_function into main

Reviewed-on: https://repo.ravanertebat.com/TM/tm_app/pulls/174
This commit is contained in:
a.ghabeli
2025-09-27 13:58:23 +03:30
2 changed files with 6 additions and 5 deletions
+5 -4
View File
@@ -315,17 +315,18 @@ class NotificationViewModel with ChangeNotifier {
notifyListeners();
}
String timeAgo(String dateTimeString) {
final createdAt = DateTime.parse(dateTimeString);
String timeAgo(timestamp) {
final int ts = int.tryParse(timestamp.toString()) ?? 0;
final createdAt = DateTime.fromMillisecondsSinceEpoch(ts * 1000).toLocal();
final now = DateTime.now();
final difference = now.difference(createdAt);
if (difference.inMinutes < 1) {
return NotificationStrings.now;
} else if (difference.inMinutes < 60) {
return '${difference.inMinutes} ${NotificationStrings.min} ';
return '${difference.inMinutes} ${NotificationStrings.min}';
} else if (difference.inHours < 24) {
return '${difference.inHours} ${NotificationStrings.hour} ';
return '${difference.inHours} ${NotificationStrings.hour}';
} else if (difference.inDays == 1) {
return NotificationStrings.yesterday;
} else {
@@ -112,7 +112,7 @@ class NotificationCard extends StatelessWidget {
SvgPicture.asset(AssetsManager.calendar),
SizedBox(width: 4.0.w()),
Text(
viewModel.timeAgo(notification.createdAt!),
viewModel.timeAgo(notification.createdAt!.toString()),
style: TextStyle(
fontSize: 12.0.sp(),
fontWeight: FontWeight.w400,