From 40636246df7d4d2605b1169f03f60e31b766b590 Mon Sep 17 00:00:00 2001 From: krawieck Date: Fri, 12 Feb 2021 17:53:51 +0100 Subject: [PATCH 1/5] Add extension for relative time and fix a bug the bug was that time from server is in UTC format, and our time is in local format, so it needed to be shifted back to UTC. oddly enough .toUtc() method didn't work --- lib/util/extensions/datetime.dart | 12 ++++++++++++ lib/widgets/comment.dart | 4 ++-- lib/widgets/post.dart | 4 ++-- lib/widgets/user_profile.dart | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 lib/util/extensions/datetime.dart diff --git a/lib/util/extensions/datetime.dart b/lib/util/extensions/datetime.dart new file mode 100644 index 0000000..3628e5a --- /dev/null +++ b/lib/util/extensions/datetime.dart @@ -0,0 +1,12 @@ +import 'package:timeago/timeago.dart' as timeago; + +extension FancyTime on DateTime { + /// returns [this] time as a relative, human-readable string. In short format + String get fancyShort => timeago.format(this, + locale: 'en_short', + clock: DateTime.now().subtract(DateTime.now().timeZoneOffset)); + + /// returns [this] time as a relative, human-readable string + String get fancy => timeago.format(this, + clock: DateTime.now().subtract(DateTime.now().timeZoneOffset)); +} diff --git a/lib/widgets/comment.dart b/lib/widgets/comment.dart index 12910c0..3b7df7d 100644 --- a/lib/widgets/comment.dart +++ b/lib/widgets/comment.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:lemmy_api_client/v2.dart'; -import 'package:timeago/timeago.dart' as timeago; import 'package:url_launcher/url_launcher.dart' as ul; import '../comment_tree.dart'; @@ -13,6 +12,7 @@ import '../hooks/delayed_loading.dart'; import '../hooks/logged_in_action.dart'; import '../hooks/stores.dart'; import '../util/extensions/api.dart'; +import '../util/extensions/datetime.dart'; import '../util/goto.dart'; import '../util/intl.dart'; import '../util/text_color.dart'; @@ -385,7 +385,7 @@ class CommentWidget extends HookWidget { Text(compactNumber(comment.counts.score + (wasVoted ? 0 : myVote.value.value))), const Text(' · '), - Text(timeago.format(comment.comment.published)), + Text(comment.comment.published.fancy), ], ), ) diff --git a/lib/widgets/post.dart b/lib/widgets/post.dart index 8293973..9f417c9 100644 --- a/lib/widgets/post.dart +++ b/lib/widgets/post.dart @@ -6,7 +6,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:intl/intl.dart'; import 'package:lemmy_api_client/v2.dart'; -import 'package:timeago/timeago.dart' as timeago; import 'package:url_launcher/url_launcher.dart' as ul; import '../hooks/delayed_loading.dart'; @@ -15,6 +14,7 @@ import '../pages/full_post.dart'; import '../url_launcher.dart'; import '../util/cleanup_url.dart'; import '../util/extensions/api.dart'; +import '../util/extensions/datetime.dart'; import '../util/goto.dart'; import '../util/more_icon.dart'; import 'bottom_modal.dart'; @@ -216,7 +216,7 @@ class PostWidget extends HookWidget { ), TextSpan( text: - ' · ${timeago.format(post.post.published, locale: 'en_short')}'), + ' · ${post.post.published.fancyShort}'), if (post.post.locked) const TextSpan(text: ' · 🔒'), if (post.post.stickied) diff --git a/lib/widgets/user_profile.dart b/lib/widgets/user_profile.dart index 3ffdbf6..dd80b52 100644 --- a/lib/widgets/user_profile.dart +++ b/lib/widgets/user_profile.dart @@ -3,12 +3,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:intl/intl.dart'; import 'package:lemmy_api_client/v2.dart'; -import 'package:timeago/timeago.dart' as timeago; import '../hooks/memo_future.dart'; import '../hooks/stores.dart'; import '../pages/manage_account.dart'; import '../util/extensions/api.dart'; +import '../util/extensions/datetime.dart'; import '../util/goto.dart'; import '../util/intl.dart'; import '../util/text_color.dart'; @@ -282,7 +282,7 @@ class _UserOverview extends HookWidget { ), const SizedBox(height: 15), Text( - 'Joined ${timeago.format(userView.user.published)}', + 'Joined ${userView.user.published.fancy}', style: theme.textTheme.bodyText1, ), Row( From ba5ffdfc416bc42c96f0da68f462db05c8a53bff Mon Sep 17 00:00:00 2001 From: krawieck Date: Fri, 12 Feb 2021 17:57:32 +0100 Subject: [PATCH 2/5] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 507996e..4a2a7ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - Added page with saved posts/comments. It can be accessed from the profile tab under the bookmark icon +### Fixed + +- Time of posts is now displayed properly. Unless you live in UTC zone, then you won't notice a difference. + ## v0.2.3 - 2021-02-09 Lemmur is now available on the [play store](https://play.google.com/store/apps/details?id=com.krawieck.lemmur) and [f-droid](https://f-droid.org/packages/com.krawieck.lemmur) From 39b12fe3bc384a8237e69280a137f399f8e72acf Mon Sep 17 00:00:00 2001 From: krawieck Date: Fri, 12 Feb 2021 23:44:15 +0100 Subject: [PATCH 3/5] change "this" formatting --- lib/util/extensions/datetime.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util/extensions/datetime.dart b/lib/util/extensions/datetime.dart index 3628e5a..de4bf2c 100644 --- a/lib/util/extensions/datetime.dart +++ b/lib/util/extensions/datetime.dart @@ -1,12 +1,12 @@ import 'package:timeago/timeago.dart' as timeago; extension FancyTime on DateTime { - /// returns [this] time as a relative, human-readable string. In short format + /// returns `this` time as a relative, human-readable string. In short format String get fancyShort => timeago.format(this, locale: 'en_short', clock: DateTime.now().subtract(DateTime.now().timeZoneOffset)); - /// returns [this] time as a relative, human-readable string + /// returns `this` time as a relative, human-readable string String get fancy => timeago.format(this, clock: DateTime.now().subtract(DateTime.now().timeZoneOffset)); } From 3afb5c9d116f1cf13f60dac8a130e95b41d3fd12 Mon Sep 17 00:00:00 2001 From: krawieck Date: Sat, 13 Feb 2021 17:03:40 +0100 Subject: [PATCH 4/5] remove offset cuz it got fixed in lac --- lib/util/extensions/datetime.dart | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/util/extensions/datetime.dart b/lib/util/extensions/datetime.dart index de4bf2c..eaf19ad 100644 --- a/lib/util/extensions/datetime.dart +++ b/lib/util/extensions/datetime.dart @@ -2,11 +2,8 @@ import 'package:timeago/timeago.dart' as timeago; extension FancyTime on DateTime { /// returns `this` time as a relative, human-readable string. In short format - String get fancyShort => timeago.format(this, - locale: 'en_short', - clock: DateTime.now().subtract(DateTime.now().timeZoneOffset)); + String get fancyShort => timeago.format(this, locale: 'en_short'); /// returns `this` time as a relative, human-readable string - String get fancy => timeago.format(this, - clock: DateTime.now().subtract(DateTime.now().timeZoneOffset)); + String get fancy => timeago.format(this); } From 40e9c45b27dfd5bf6a38bc94199347aac400d617 Mon Sep 17 00:00:00 2001 From: krawieck Date: Sat, 13 Feb 2021 17:10:53 +0100 Subject: [PATCH 5/5] update LAC --- pubspec.lock | 2 +- pubspec.yaml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 761ed48..bbbc3be 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -267,7 +267,7 @@ packages: name: lemmy_api_client url: "https://pub.dartlang.org" source: hosted - version: "0.10.2" + version: "0.11.0" markdown: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index cfea5e2..4f55e47 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,7 +44,8 @@ dependencies: # utils timeago: ^2.0.27 fuzzy: <1.0.0 - lemmy_api_client: ^0.10.2 + lemmy_api_client: ^0.11.0 + matrix4_transform: ^1.1.7 flutter: