From 209d522a81fcb361a504299035d34e331191e4ee Mon Sep 17 00:00:00 2001 From: redDwarf03 Date: Thu, 8 Aug 2024 23:40:35 +0200 Subject: [PATCH] fix: :bug: Error calculating time remaining in farm lock --- ...farm_lock_block_list_single_line_lock.dart | 93 +++++++++++-------- pubspec.lock | 16 ++-- pubspec.yaml | 6 +- 3 files changed, 63 insertions(+), 52 deletions(-) diff --git a/lib/ui/views/farm_lock/layouts/components/farm_lock_block_list_single_line_lock.dart b/lib/ui/views/farm_lock/layouts/components/farm_lock_block_list_single_line_lock.dart index 759785a3..44c3e134 100644 --- a/lib/ui/views/farm_lock/layouts/components/farm_lock_block_list_single_line_lock.dart +++ b/lib/ui/views/farm_lock/layouts/components/farm_lock_block_list_single_line_lock.dart @@ -15,7 +15,7 @@ import 'package:flutter_gen/gen_l10n/localizations.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:gradient_borders/box_borders/gradient_box_border.dart'; import 'package:intl/intl.dart'; -import 'package:moment_dart/moment_dart.dart'; +import 'package:humanize_duration/humanize_duration.dart'; class FarmLockBlockListSingleLineLock extends ConsumerWidget { const FarmLockBlockListSingleLineLock({ @@ -186,19 +186,23 @@ class FarmLockBlockListSingleLineLock extends ConsumerWidget { child: Column( children: [ SelectableText( - DateTime.fromMillisecondsSinceEpoch( - farmLockUserInfos.end! * - 1000, - ) - .difference( - DateTime.now() - .toUtc(), - ) - .toDurationString( - includeWeeks: true, - round: false, - delimiter: ', ', - ), + humanizeDuration( + DateTime.fromMillisecondsSinceEpoch( + farmLockUserInfos.end! * + 1000, + ).toUtc().difference( + DateTime.now() + .toUtc(), + ), + options: + const HumanizeOptions( + units: [ + Units.year, + Units.day, + Units.hour, + ], + ), + ), style: style, ), SelectableText( @@ -206,13 +210,14 @@ class FarmLockBlockListSingleLineLock extends ConsumerWidget { Localizations.localeOf( context, ).languageCode, - ).format( - DateTime - .fromMillisecondsSinceEpoch( - farmLockUserInfos.end! * - 1000, - ), - ), + ).add_Hm().format( + DateTime + .fromMillisecondsSinceEpoch( + farmLockUserInfos + .end! * + 1000, + ).toUtc(), + ), style: AppTextStyles.bodySmall( context, @@ -447,19 +452,24 @@ class FarmLockBlockListSingleLineLock extends ConsumerWidget { style: styleHeader, ), SelectableText( - DateTime.fromMillisecondsSinceEpoch( - farmLockUserInfos.end! * - 1000, - ) - .difference( - DateTime.now() - .toUtc(), - ) - .toDurationString( - includeWeeks: true, - round: false, - delimiter: ', ', - ), + humanizeDuration( + DateTime.fromMillisecondsSinceEpoch( + farmLockUserInfos + .end! * + 1000, + ).toUtc().difference( + DateTime.now() + .toUtc(), + ), + options: + const HumanizeOptions( + units: [ + Units.year, + Units.day, + Units.hour, + ], + ), + ), style: style, ), ], @@ -469,13 +479,14 @@ class FarmLockBlockListSingleLineLock extends ConsumerWidget { Localizations.localeOf( context, ).languageCode, - ).format( - DateTime - .fromMillisecondsSinceEpoch( - farmLockUserInfos.end! * - 1000, - ), - ), + ).add_Hm().format( + DateTime + .fromMillisecondsSinceEpoch( + farmLockUserInfos + .end! * + 1000, + ).toUtc(), + ), style: Theme.of(context) .textTheme .bodySmall, diff --git a/pubspec.lock b/pubspec.lock index 0dd1d4e9..1b30cf08 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -600,6 +600,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + humanize_duration: + dependency: "direct main" + description: + name: humanize_duration + sha256: a9fb33b18d028aa2ffd1731af25f59cfcb3c1c2af673cf73fffc7f9a42b2f57e + url: "https://pub.dev" + source: hosted + version: "0.0.2" image: dependency: transitive description: @@ -720,14 +728,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.5" - moment_dart: - dependency: "direct main" - description: - name: moment_dart - sha256: "721f008251341578a818140afe402be827bc29951846575598426f4039a0799b" - url: "https://pub.dev" - source: hosted - version: "2.2.1+beta.0" ninja_asn1: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ec7df53b..463bcbde 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,6 +65,9 @@ dependencies: hive: ^2.2.3 hive_flutter: ^1.1.0 + # Utilities to make working with 'Duration's easier. + humanize_duration: ^0.0.2 + # Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization issues. intl: ^0.19.0 @@ -74,9 +77,6 @@ dependencies: # A Flutter plugin for rendering an animated and customizable starfield on a dark background. lit_starfield: ^0.1.1 - # Utilities to make working with 'Duration's easier. - moment_dart: ^2.1.0 - # Flutter plugin for getting commonly used locations on host platform file systems, such as the temp and app data directories. path_provider: ^2.1.2