immich/mobile/test/modules/extensions/datetime_extensions_test.dart
Yaros c98c20e963
fix(mobile): respect 24h system setting (#30792)
* fix(mobile): respect 24h system setting

* refactor: extract into utils

* chore: remove comment

Co-authored-by: shenlong <139912620+shenlong-tanwen@users.noreply.github.com>

* refactor: resolveAssetDateTime

Co-authored-by: shenlong <139912620+shenlong-tanwen@users.noreply.github.com>

* refactor: alwaysUse24HourFormat

* chore: impl suggestions

* refactor: less comments & resolveDateTimeLocale

---------

Co-authored-by: shenlong <139912620+shenlong-tanwen@users.noreply.github.com>
2026-08-23 17:51:03 +05:30

48 lines
1.8 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:immich_mobile/extensions/datetime_extensions.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
void main() {
setUpAll(() async {
await initializeDateFormatting();
Intl.defaultLocale = 'en_US';
});
group('DateRangeFormatting.formatDateRange', () {
final currentYear = DateTime.now().year;
test('returns single date format for this year', () {
final date = DateTime(currentYear, 8, 28); // Aug 28 this year
final result = DateRangeFormatting.formatDateRange(date, date);
expect(result, 'Aug 28');
});
test('returns single date format for other year', () {
final date = DateTime(2023, 8, 28); // Aug 28, 2023
final result = DateRangeFormatting.formatDateRange(date, date);
expect(result, 'Aug 28, 2023');
});
test('returns date range format for this year', () {
final startDate = DateTime(currentYear, 3, 23); // Mar 23
final endDate = DateTime(currentYear, 5, 31); // May 31
final result = DateRangeFormatting.formatDateRange(startDate, endDate);
expect(result, 'Mar 23 - May 31');
});
test('returns date range format for other year (same year)', () {
final startDate = DateTime(2023, 8, 28); // Aug 28
final endDate = DateTime(2023, 9, 30); // Sep 30
final result = DateRangeFormatting.formatDateRange(startDate, endDate);
expect(result, 'Aug 28 - Sep 30, 2023');
});
test('returns date range format over multiple years', () {
final startDate = DateTime(2021, 4, 17); // Apr 17, 2021
final endDate = DateTime(2022, 4, 9); // Apr 9, 2022
final result = DateRangeFormatting.formatDateRange(startDate, endDate);
expect(result, 'Apr 17, 2021 - Apr 9, 2022');
});
});
}