Skip to content

Commit

Permalink
TW-1503 Write unit test localizedTimeShort and isInCurrentWeek
Browse files Browse the repository at this point in the history
  • Loading branch information
hieutbui authored and hoangdat committed Mar 1, 2024
1 parent 711f2a3 commit 1c1fe4e
Show file tree
Hide file tree
Showing 2 changed files with 660 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/utils/date_time_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ extension DateTimeExtension on DateTime {
/// Returns [localizedTimeOfDay()] if the ChatTime is today, the name of the week
/// day if the ChatTime is this week and a date string else.
String localizedTimeShort(BuildContext context, {DateTime? currentTime}) {
final now = currentTime ?? DateTime.now();
currentTime ??= DateTime.now();

final sameYear = now.year == year;
final sameYear = currentTime.year == year;

final sameDay = sameYear && now.month == month && now.day == day;
final sameDay =
sameYear && currentTime.month == month && currentTime.day == day;

final sameWeek = isInCurrentWeek(currentTime: currentTime);

Expand Down Expand Up @@ -81,9 +82,10 @@ extension DateTimeExtension on DateTime {
}

bool isInCurrentWeek({DateTime? currentTime}) {
final now = currentTime ?? DateTime.now();
currentTime ??= DateTime.now();

final currentWeekStart = now.subtract(Duration(days: now.weekday - 1));
final currentWeekStart =
currentTime.subtract(Duration(days: currentTime.weekday - 1));

final weekStart = subtract(Duration(days: weekday - 1));

Expand Down
Loading

0 comments on commit 1c1fe4e

Please sign in to comment.