fix(mobile): person birthday viewing/editing (#20731)

* fix: edit birthday dialog

* chore: convert age to "x years old" format

* fix: lint

---------

Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
Brandon Wees 2025-08-06 17:13:56 -05:00 committed by GitHub
parent 746252fe39
commit 325d5f7ba9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 16 additions and 40 deletions

View file

@ -7,6 +7,7 @@ import 'package:immich_mobile/extensions/build_context_extensions.dart';
import 'package:immich_mobile/models/search/search_curated_content.model.dart';
import 'package:immich_mobile/providers/asset_viewer/asset_people.provider.dart';
import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/utils/people.utils.dart';
import 'package:immich_mobile/widgets/search/curated_people_row.dart';
import 'package:immich_mobile/widgets/search/person_name_edit_form.dart';
@ -41,7 +42,7 @@ class PeopleInfo extends ConsumerWidget {
id: p.id,
label: p.name,
subtitle: p.birthDate != null && p.birthDate!.isBefore(asset.fileCreatedAt)
? _formatAge(p.birthDate!, asset.fileCreatedAt)
? formatAge(p.birthDate!, asset.fileCreatedAt)
: null,
),
)
@ -87,33 +88,4 @@ class PeopleInfo extends ConsumerWidget {
),
);
}
String _formatAge(DateTime birthDate, DateTime referenceDate) {
int ageInYears = _calculateAge(birthDate, referenceDate);
int ageInMonths = _calculateAgeInMonths(birthDate, referenceDate);
if (ageInMonths <= 11) {
return "exif_bottom_sheet_person_age_months".tr(namedArgs: {'months': ageInMonths.toString()});
} else if (ageInMonths > 12 && ageInMonths <= 23) {
return "exif_bottom_sheet_person_age_year_months".tr(namedArgs: {'months': (ageInMonths - 12).toString()});
} else {
return "exif_bottom_sheet_person_age_years".tr(namedArgs: {'years': ageInYears.toString()});
}
}
int _calculateAge(DateTime birthDate, DateTime referenceDate) {
int age = referenceDate.year - birthDate.year;
if (referenceDate.month < birthDate.month ||
(referenceDate.month == birthDate.month && referenceDate.day < birthDate.day)) {
age--;
}
return age;
}
int _calculateAgeInMonths(DateTime birthDate, DateTime referenceDate) {
return (referenceDate.year - birthDate.year) * 12 +
referenceDate.month -
birthDate.month -
(referenceDate.day < birthDate.day ? 1 : 0);
}
}