Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Replace timeago with local formatter

Neeraj Gupta520d15e21218
diff --git a/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart b/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
index 12fffd00e3..80bc87de03 100644
--- a/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
+++ b/mobile/apps/photos/lib/ui/settings/cast/cast_settings_page.dart
@@ -12,7 +12,7 @@ import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
-import 'package:timeago/timeago.dart' as timeago;
+import "package:photos/utils/relative_time_formatter.dart";
class CastSettingsPage extends StatelessWidget {
const CastSettingsPage({super.key});
@@ -179,7 +179,7 @@ class _CastSessionItem extends StatelessWidget {
final title = collection?.displayName ?? session.collectionID.toString();
return SettingsItem(
title: "$title on ${session.deviceName ?? session.deviceIP}",
- subtitle: timeago.format(session.lastUsedAt),
+ subtitle: formatTimeAgo(session.lastUsedAt),
icon: HugeIcons.strokeRoundedTvSmart,
showChevron: false,
showOnlyLoadingState: true,
diff --git a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
index c405ab8244..b365498529 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/comment_bubble_widget.dart
@@ -21,7 +21,7 @@ import "package:photos/ui/social/widgets/comment_actions_popup.dart";
import "package:photos/ui/social/widgets/comment_like_count_capsule.dart";
import "package:photos/ui/social/widgets/delete_comment_confirmation_dialog.dart";
import "package:photos/ui/social/widgets/resolved_social_user_name.dart";
-import "package:photos/utils/social/relative_time_formatter.dart";
+import "package:photos/utils/relative_time_formatter.dart";
final _logger = Logger("CommentBubbleWidget");
@@ -828,7 +828,9 @@ class _Header extends StatelessWidget {
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
- final timestamp = formatRelativeTime(createdAt);
+ final timestamp = formatCompactRelativeTime(
+ DateTime.fromMicrosecondsSinceEpoch(createdAt),
+ );
if (isOwnComment) {
return Align(
diff --git a/mobile/apps/photos/lib/utils/relative_time_formatter.dart b/mobile/apps/photos/lib/utils/relative_time_formatter.dart
new file mode 100644
index 0000000000..5d0ee653b0
--- /dev/null
+++ b/mobile/apps/photos/lib/utils/relative_time_formatter.dart
@@ -0,0 +1,57 @@
+import "package:intl/intl.dart";
+
+String formatCompactRelativeTime(DateTime dateTime) {
+ final now = DateTime.now();
+ final difference = now.difference(dateTime);
+
+ if (difference.inMinutes < 1) {
+ return "just now";
+ } else if (difference.inMinutes < 60) {
+ return "${difference.inMinutes}m ago";
+ } else if (difference.inHours < 24) {
+ return "${difference.inHours}hr ago";
+ } else if (difference.inDays < 7) {
+ return "${difference.inDays}d ago";
+ } else {
+ final sameYear = dateTime.year == now.year;
+ return DateFormat(sameYear ? "MMM d" : "MMM d, yyyy").format(dateTime);
+ }
+}
+
+String formatTimeAgo(DateTime dateTime) {
+ final elapsedMilliseconds =
+ DateTime.now().millisecondsSinceEpoch - dateTime.millisecondsSinceEpoch;
+ final seconds = elapsedMilliseconds / Duration.millisecondsPerSecond;
+ final minutes = seconds / Duration.secondsPerMinute;
+ final hours = minutes / Duration.minutesPerHour;
+ final days = hours / Duration.hoursPerDay;
+ final months = days / 30;
+ final years = days / 365;
+
+ final String value;
+ if (seconds < 45) {
+ value = "a moment";
+ } else if (seconds < 90) {
+ value = "a minute";
+ } else if (minutes < 45) {
+ value = "${minutes.round()} minutes";
+ } else if (minutes < 90) {
+ value = "about an hour";
+ } else if (hours < 24) {
+ value = "${hours.round()} hours";
+ } else if (hours < 48) {
+ value = "a day";
+ } else if (days < 30) {
+ value = "${days.round()} days";
+ } else if (days < 60) {
+ value = "about a month";
+ } else if (days < 365) {
+ value = "${months.round()} months";
+ } else if (years < 2) {
+ value = "about a year";
+ } else {
+ value = "${years.round()} years";
+ }
+
+ return "$value ago";
+}
diff --git a/mobile/apps/photos/lib/utils/social/relative_time_formatter.dart b/mobile/apps/photos/lib/utils/social/relative_time_formatter.dart
deleted file mode 100644
index cbf3d28452..0000000000
--- a/mobile/apps/photos/lib/utils/social/relative_time_formatter.dart
+++ /dev/null
@@ -1,23 +0,0 @@
-import "package:intl/intl.dart";
-
-/// Formats a timestamp (in microseconds) to a relative time string.
-///
-/// Server timestamps are in microseconds since epoch.
-String formatRelativeTime(int timestampMicros) {
- final now = DateTime.now();
- final dateTime = DateTime.fromMicrosecondsSinceEpoch(timestampMicros);
- final difference = now.difference(dateTime);
-
- if (difference.inMinutes < 1) {
- return "just now";
- } else if (difference.inMinutes < 60) {
- return "${difference.inMinutes}m ago";
- } else if (difference.inHours < 24) {
- return "${difference.inHours}hr ago";
- } else if (difference.inDays < 7) {
- return "${difference.inDays}d ago";
- } else {
- final sameYear = dateTime.year == now.year;
- return DateFormat(sameYear ? "MMM d" : "MMM d, yyyy").format(dateTime);
- }
-}
diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yaml
index 0335d5e821..9f381f61c2 100644
--- a/mobile/apps/photos/pubspec.yaml
+++ b/mobile/apps/photos/pubspec.yaml
@@ -218,7 +218,6 @@ dependencies:
synchronized: 3.4.0
system_info_plus: 0.0.6
thermal: 1.1.11
- timeago: 3.7.1
timezone: 0.10.1
tuple: 2.0.2
ua_client_hints: 1.4.1
diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock
index b31eb22b1e..106dc4e99d 100644
--- a/mobile/pubspec.lock
+++ b/mobile/pubspec.lock
@@ -2854,14 +2854,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.11"
- timeago:
- dependency: transitive
- description:
- name: timeago
- sha256: b05159406a97e1cbb2b9ee4faa9fb096fe0e2dfcd8b08fcd2a00553450d3422e
- url: "https://pub.dev"
- source: hosted
- version: "3.7.1"
timezone:
dependency: transitive
description: