Skip to content
Open
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
8 changes: 8 additions & 0 deletions w_common/lib/src/intl/time_intl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'package:intl/intl.dart';

class TimeIntl {
static String get today => Intl.message('Today', name: 'TimeIntl_today');

static String get yesterday =>
Intl.message('Yesterday', name: 'TimeIntl_yesterday');
}
13 changes: 7 additions & 6 deletions w_common/lib/time.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
library w_common.timestamp;

import 'package:intl/intl.dart';
import 'package:w_common/src/intl/time_intl.dart';

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change going to add a space before the AM/PM?

Image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will add a space, but we're preferring to adapt to locale now.
Screenshot 2026-01-06 at 14 56 12

Screenshot 2026-01-06 at 14 57 02


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

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

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

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

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

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

// Weekday check prevents ambiguity between dates that are
Expand Down