@@ -1641,55 +1641,76 @@ void main() {
16411641 group ('MessageTimestampStyle' , () {
16421642 void doTests (
16431643 MessageTimestampStyle style,
1644- List <(String timestampStr, String ? expected)> cases, {
1644+ List <(
1645+ String timestampStr,
1646+ String ? expectedTwelveHour,
1647+ String ? expectedTwentyFourHour,
1648+ )> cases, {
16451649 DateTime ? now,
16461650 }) {
16471651 now ?? = DateTime .parse ("2023-01-10 12:00" );
1648- for (final (timestampStr, expected) in cases) {
1649- test ('${style .name }: $timestampStr returns $expected ' , () {
1650- addTearDown (testBinding.reset);
1651- final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
1652-
1653- withClock (Clock .fixed (now! ), () {
1654- final timestamp = DateTime .parse (timestampStr)
1655- .millisecondsSinceEpoch ~ / 1000 ;
1656- final result = style.format (
1657- timestamp,
1658- now: testBinding.utcNow ().toLocal (),
1659- twentyFourHourTimeMode: TwentyFourHourTimeMode .localeDefault,
1660- zulipLocalizations: zulipLocalizations);
1661- check (result).equals (expected);
1652+ for (final (timestampStr, expectedTwelveHour, expectedTwentyFourHour) in cases) {
1653+ for (final mode in TwentyFourHourTimeMode .values) {
1654+ final expected = switch (mode) {
1655+ TwentyFourHourTimeMode .twelveHour => expectedTwelveHour,
1656+ TwentyFourHourTimeMode .twentyFourHour => expectedTwentyFourHour,
1657+ // This expectation will hold as long as we're always using the
1658+ // default locale, en_US, which uses the twelve-hour format.
1659+ // TODO(#1727) test with other locales
1660+ TwentyFourHourTimeMode .localeDefault => expectedTwelveHour,
1661+ };
1662+
1663+ test ('${style .name } in ${mode .name }: $timestampStr returns $expected ' , () {
1664+ addTearDown (testBinding.reset);
1665+ final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
1666+
1667+ withClock (Clock .fixed (now! ), () {
1668+ final timestamp = DateTime .parse (timestampStr)
1669+ .millisecondsSinceEpoch ~ / 1000 ;
1670+ final result = style.format (
1671+ timestamp,
1672+ now: testBinding.utcNow ().toLocal (),
1673+ twentyFourHourTimeMode: mode,
1674+ zulipLocalizations: zulipLocalizations);
1675+ check (result).equals (expected);
1676+ });
16621677 });
1663- });
1678+ }
16641679 }
16651680 }
16661681
16671682 for (final style in MessageTimestampStyle .values) {
16681683 switch (style) {
16691684 case MessageTimestampStyle .none:
1670- doTests (style, [('2023-01-10 12:00' , null )]);
1685+ doTests (style, [('2023-01-10 12:00' , null , null )]);
16711686 case MessageTimestampStyle .dateOnlyRelative:
16721687 final zulipLocalizations = GlobalLocalizations .zulipLocalizations;
16731688 doTests (style,
16741689 now: DateTime .parse ("2023-01-10 12:00" ),
16751690 [
1676- ("2023-01-10 12:00" , zulipLocalizations.today),
1677- ("2023-01-10 00:00" , zulipLocalizations.today),
1678- ("2023-01-10 23:59" , zulipLocalizations.today),
1679- ("2023-01-09 23:59" , zulipLocalizations.yesterday),
1680- ("2023-01-09 00:00" , zulipLocalizations.yesterday),
1681- ("2023-01-08 00:00" , "Jan 8" ),
1682- ("2022-12-31 00:00" , "Dec 31, 2022" ),
1691+ ("2023-01-10 12:00" , zulipLocalizations.today, zulipLocalizations.today ),
1692+ ("2023-01-10 00:00" , zulipLocalizations.today, zulipLocalizations.today ),
1693+ ("2023-01-10 23:59" , zulipLocalizations.today, zulipLocalizations.today ),
1694+ ("2023-01-09 23:59" , zulipLocalizations.yesterday, zulipLocalizations.yesterday ),
1695+ ("2023-01-09 00:00" , zulipLocalizations.yesterday, zulipLocalizations.yesterday ),
1696+ ("2023-01-08 00:00" , "Jan 8" , "Jan 8" ),
1697+ ("2022-12-31 00:00" , "Dec 31, 2022" , "Dec 31, 2022" ),
16831698 // Future times
1684- ("2023-01-10 19:00" , zulipLocalizations.today),
1685- ("2023-01-11 00:00" , "Jan 11, 2023" ),
1699+ ("2023-01-10 19:00" , zulipLocalizations.today, zulipLocalizations.today ),
1700+ ("2023-01-11 00:00" , "Jan 11, 2023" , "Jan 11, 2023" ),
16861701 ]);
16871702 case MessageTimestampStyle .timeOnly:
1688- doTests (style, [('2023-01-10 12:00' , '12:00 PM' )]);
1703+ doTests (style, [('2023-01-10 12:00' , '12:00 PM' , '12:00' )]);
16891704 case MessageTimestampStyle .lightbox:
1690- doTests (style, [('2023-01-10 12:00' , 'Jan 10, 2023 12:00:00' )]);
1705+ doTests (style,
1706+ [('2023-01-10 12:00' ,
1707+ 'Jan 10, 2023 12:00:00 PM' ,
1708+ 'Jan 10, 2023 12:00:00' )]);
16911709 case MessageTimestampStyle .full:
1692- doTests (style, [('2023-01-10 12:00' , 'Jan 10, 2023 12:00 PM' )]);
1710+ doTests (style,
1711+ [('2023-01-10 12:00' ,
1712+ 'Jan 10, 2023 12:00 PM' ,
1713+ 'Jan 10, 2023 12:00' )]);
16931714 }
16941715 }
16951716 });
0 commit comments