Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions w_common/lib/time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ library w_common.timestamp;

import 'package:intl/intl.dart';

final locale = Intl.getCurrentLocale();

/// The format of a timestamp with no date.
DateFormat timeFormat = DateFormat('h:mma');
DateFormat timeFormat = DateFormat('h:mma', locale);

/// The format of a weekday with no time of day.
DateFormat weekdayFormat = DateFormat.EEEE();
DateFormat weekdayFormat = DateFormat.EEEE(locale);

/// The format of a month and day with no time of day.
DateFormat monthDayFormat = DateFormat.MMMMd();
DateFormat monthDayFormat = DateFormat.MMMMd(locale);

/// The format of the full date with no time of day.
DateFormat yearMonthDayFormat = DateFormat.yMMMd();
DateFormat yearMonthDayFormat = DateFormat.yMMMd(locale);

/// Formats a DateTime into the 'X ago' string format.
String formatTimeDifference(DateTime time, {DateTime? now}) {
Expand All @@ -22,12 +24,12 @@ String formatTimeDifference(DateTime time, {DateTime? now}) {

if (deltaDays < 1 && now.day == time.day) {
// "Today, XX:XXam"
return 'Today, $timeOfDay';
return '${Intl.message('Today')}, $timeOfDay';
}

if (deltaDays < 2 && now.weekday == (time.weekday + 1) % 7) {
// "Yesterday, XX:XXam"
return 'Yesterday, $timeOfDay';
return '${Intl.message('Yesterday')}, $timeOfDay';
}

// Weekday check prevents ambiguity between dates that are
Expand Down
2 changes: 1 addition & 1 deletion w_common/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ dev_dependencies:
dependency_validator: ^3.0.0
mocktail: ^1.0.4
test: ^1.21.1
workiva_analysis_options: ^1.4.2
workiva_analysis_options: ^1.4.3
2 changes: 1 addition & 1 deletion w_common_tools/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ dev_dependencies:
build_web_compilers: '>=2.16.5 <5.0.0'
dependency_validator: ^3.0.0
test: ^1.21.1
workiva_analysis_options: ^1.0.0
workiva_analysis_options: ^1.4.3
Loading