File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ class TimeOfDay {
9191 DayPeriod get period => hour < hoursPerPeriod ? DayPeriod .am : DayPeriod .pm;
9292
9393 /// Which hour of the current period (e.g., am or pm) this time is.
94- int get hourOfPeriod => hour - periodOffset;
94+ int get hourOfPeriod => hour > hoursPerPeriod ? hour - periodOffset : hour ;
9595
9696 /// The hour at which the current period starts.
9797 int get periodOffset => period == DayPeriod .am ? 0 : hoursPerPeriod;
Original file line number Diff line number Diff line change @@ -25,5 +25,24 @@ void main() {
2525 expect (await pumpTest (false ), '7:00 AM' );
2626 expect (await pumpTest (true ), '07:00' );
2727 });
28+
29+ testWidgets ('return 12 hours at noon' , (WidgetTester tester) async {
30+ Future <String > pumpTest (bool alwaysUse24HourFormat) async {
31+ late String formattedValue;
32+ await tester.pumpWidget (MaterialApp (
33+ home: MediaQuery (
34+ data: MediaQueryData (alwaysUse24HourFormat: alwaysUse24HourFormat),
35+ child: Builder (builder: (BuildContext context) {
36+ formattedValue = const TimeOfDay (hour: 12 , minute: 0 ).format (context);
37+ return Container ();
38+ }),
39+ ),
40+ ));
41+ return formattedValue;
42+ }
43+
44+ expect (await pumpTest (false ), '12:00 PM' );
45+ expect (await pumpTest (true ), '12:00' );
46+ });
2847 });
2948}
You can’t perform that action at this time.
0 commit comments