mirror of
https://github.com/immich-app/immich.git
synced 2026-07-06 20:47:00 -07:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 825b1c3ded |
@@ -65,6 +65,7 @@ class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonBirthdayEdi
|
|||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
|
borderRadius: const BorderRadius.all(Radius.circular(16.0)),
|
||||||
child: ScrollDatePicker(
|
child: ScrollDatePicker(
|
||||||
|
viewType: datePickerColumnOrder(DateFormat.yMd(context.locale.toLanguageTag()).pattern),
|
||||||
options: DatePickerOptions(
|
options: DatePickerOptions(
|
||||||
backgroundColor: context.colorScheme.surfaceContainerHigh,
|
backgroundColor: context.colorScheme.surfaceContainerHigh,
|
||||||
itemExtent: 50,
|
itemExtent: 50,
|
||||||
@@ -118,3 +119,18 @@ class _DriftPersonNameEditFormState extends ConsumerState<DriftPersonBirthdayEdi
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<DatePickerViewType>? datePickerColumnOrder(String? pattern) {
|
||||||
|
if (pattern == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final positions = {
|
||||||
|
DatePickerViewType.year: pattern.indexOf('y'),
|
||||||
|
DatePickerViewType.month: pattern.indexOf('M'),
|
||||||
|
DatePickerViewType.day: pattern.indexOf('d'),
|
||||||
|
};
|
||||||
|
if (positions.values.any((position) => position < 0)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return positions.keys.toList()..sort((a, b) => positions[a]!.compareTo(positions[b]!));
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:immich_mobile/presentation/widgets/people/person_edit_birthday_modal.widget.dart';
|
||||||
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:scroll_date_picker/scroll_date_picker.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('datePickerColumnOrder', () {
|
||||||
|
test('month first (en_US)', () {
|
||||||
|
expect(
|
||||||
|
datePickerColumnOrder('M/d/y'),
|
||||||
|
orderedEquals([DatePickerViewType.month, DatePickerViewType.day, DatePickerViewType.year]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('day first (pl)', () {
|
||||||
|
expect(
|
||||||
|
datePickerColumnOrder('dd.MM.y'),
|
||||||
|
orderedEquals([DatePickerViewType.day, DatePickerViewType.month, DatePickerViewType.year]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('year first (ko)', () {
|
||||||
|
expect(
|
||||||
|
datePickerColumnOrder('y. M. d.'),
|
||||||
|
orderedEquals([DatePickerViewType.year, DatePickerViewType.month, DatePickerViewType.day]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('null pattern falls back to package default', () {
|
||||||
|
expect(datePickerColumnOrder(null), isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('missing field falls back to package default', () {
|
||||||
|
expect(datePickerColumnOrder('M/y'), isNull);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('datePickerColumnOrder with real locale patterns', () {
|
||||||
|
setUpAll(() async {
|
||||||
|
await initializeDateFormatting();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('en uses month/day/year', () {
|
||||||
|
expect(
|
||||||
|
datePickerColumnOrder(DateFormat.yMd('en').pattern),
|
||||||
|
orderedEquals([DatePickerViewType.month, DatePickerViewType.day, DatePickerViewType.year]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('pl uses day/month/year', () {
|
||||||
|
expect(
|
||||||
|
datePickerColumnOrder(DateFormat.yMd('pl').pattern),
|
||||||
|
orderedEquals([DatePickerViewType.day, DatePickerViewType.month, DatePickerViewType.year]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('ko uses year/month/day', () {
|
||||||
|
expect(
|
||||||
|
datePickerColumnOrder(DateFormat.yMd('ko').pattern),
|
||||||
|
orderedEquals([DatePickerViewType.year, DatePickerViewType.month, DatePickerViewType.day]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user