@@ -12,43 +12,43 @@ void main() {
1212 test ('age function should return correct string for years' , () {
1313 final now = DateTime .now ();
1414 final dt = now.subtract (const Duration (days: 2 * 365 ));
15- expect (age (dt), '2y ' );
15+ expect (age (dt), startsWith ( '2y ago (' ) );
1616 });
1717
1818 test ('age function should return correct string for months' , () {
1919 final now = DateTime .now ();
2020 final dt = now.subtract (const Duration (days: 2 * 30 ));
21- expect (age (dt), '2mo ' );
21+ expect (age (dt), startsWith ( '2mo ago (' ) );
2222 });
2323
2424 test ('age function should return correct string for weeks' , () {
2525 final now = DateTime .now ();
2626 final dt = now.subtract (const Duration (days: 2 * 7 ));
27- expect (age (dt), '2w ' );
27+ expect (age (dt), startsWith ( '2w ago (' ) );
2828 });
2929
3030 test ('age function should return correct string for days' , () {
3131 final now = DateTime .now ();
3232 final dt = now.subtract (const Duration (days: 2 )); // 2 days
33- expect (age (dt), '2d ' );
33+ expect (age (dt), startsWith ( '2d ago (' ) );
3434 });
3535
3636 test ('age function should return correct string for hours' , () {
3737 final now = DateTime .now ();
3838 final dt = now.subtract (const Duration (hours: 2 )); // 2 hours
39- expect (age (dt), '2h ' );
39+ expect (age (dt), startsWith ( '2h ago (' ) );
4040 });
4141
4242 test ('age function should return correct string for minutes' , () {
4343 final now = DateTime .now ();
4444 final dt = now.subtract (const Duration (minutes: 2 )); // 2 minutes
45- expect (age (dt), '2min ' );
45+ expect (age (dt), startsWith ( '2min ago (' ) );
4646 });
4747
4848 test ('age function should return correct string for seconds' , () {
4949 final now = DateTime .now ();
5050 final dt = now.subtract (const Duration (seconds: 2 )); // 2 seconds
51- expect (age (dt), '2s ' );
51+ expect (age (dt), startsWith ( '2s ago (' ) );
5252 });
5353
5454 test ('age function should respect use24HourFormat app setting' , () {
@@ -58,50 +58,35 @@ void main() {
5858 // Test with 12-hour format
5959 AppSettings .use24HourFormatRx.value = false ;
6060 expect (age (dt), contains ('2d' ));
61- expect (age (dt), contains ( '(hh:mm a )' ));
61+ expect (age (dt), matches ( r'.*\d{1,2}:\d{2} [AP]M\ )' ));
6262
6363 // Test with 24-hour format
6464 AppSettings .use24HourFormatRx.value = true ;
6565 expect (age (dt), contains ('2d' ));
66- expect (age (dt), contains ( '(HH:mm )' ));
66+ expect (age (dt), matches ( r'.*\d{1,2}:\d{2}\ )' ));
6767 });
6868
6969 test ('when function should return correct string for future dates' , () {
7070 final now = DateTime .now ();
71- final dt = now.add (const Duration (days: 2 )); // 2 days from now
72- expect (when (dt), '1d ' );
71+ final dt =
72+ now.add (const Duration (days: 1 , hours: 12 )); // 1+ days from now
73+ expect (when (dt), startsWith ('1d (' ));
7374 });
7475
7576 test ('when function should respect use24HourFormat app setting' , () {
7677 final now = DateTime .now ();
77- final dt = now.add (const Duration (days: 2 )); // 2 days from now
78+ final dt =
79+ now.add (const Duration (days: 1 , hours: 12 )); // 1+ days from now
7880
7981 // Test with 12-hour format
8082 AppSettings .use24HourFormatRx.value = false ;
8183 expect (when (dt), contains ('1d' ));
82- expect (when (dt), contains ( '(hh:mm a )' ));
84+ expect (when (dt), matches ( r'.*\d{1,2}:\d{2} [AP]M\ )' ));
8385
8486 // Test with 24-hour format
8587 AppSettings .use24HourFormatRx.value = true ;
8688 expect (when (dt), contains ('1d' ));
87- expect (when (dt), contains ('(HH:mm)' ));
88- });
89-
90- test (
91- 'difference function should return correct string for various durations' ,
92- () {
93- expect (difference (const Duration (days: 2 * 365 )), '2y ' );
94- expect (difference (const Duration (days: 2 * 30 )), '2mo ' );
95- expect (difference (const Duration (days: 2 * 7 )), '2w ' );
96- expect (difference (const Duration (days: 2 )), '2d ' );
97- expect (difference (const Duration (hours: 2 )), '2h ' );
98- expect (difference (const Duration (minutes: 2 )), '2min ' );
99- expect (difference (const Duration (seconds: 2 )), '2s ' );
100-
101- expect (difference (const Duration (days: - 2 )), '2d ago ' );
102- expect (difference (const Duration (hours: - 2 )), '2h ago ' );
103- expect (difference (const Duration (minutes: - 2 )), '2min ago ' );
104- expect (difference (const Duration (seconds: - 2 )), '2s ago ' );
89+ expect (when (dt), matches (r'.*\d{1,2}:\d{2}\)' ));
10590 });
10691 });
10792}
0 commit comments