Unify person page for local and TMDB people
- Merge local and TMDB person views into a single PersonDetailsPage - Remove unused PersonTmdbRedirectPage - Show age tooltip on birthdays (person page and people list)
This commit is contained in:
1 parent
6d4c3e185a
commit
f88dfdae44
4 files changed
+183
-517
No files matched your search
@@ -137,3 +137,24 @@ export function getYear(dateStr: string | null): string {
|
||||
if (!dateStr) return "";
|
||||
return new Date(dateStr).getFullYear().toString();
|
||||
}
|
||||
|
||||
export function calculateAge(
|
||||
birthday: string | null | undefined,
|
||||
deathday?: string | null,
|
||||
): number | null {
|
||||
if (!birthday) return null;
|
||||
|
||||
const birth = new Date(birthday);
|
||||
if (isNaN(birth.getTime())) return null;
|
||||
|
||||
let end = deathday ? new Date(deathday) : new Date();
|
||||
if (deathday && isNaN(end.getTime())) end = new Date();
|
||||
|
||||
let age = end.getFullYear() - birth.getFullYear();
|
||||
const monthDiff = end.getMonth() - birth.getMonth();
|
||||
if (monthDiff < 0 || (monthDiff === 0 && end.getDate() < birth.getDate())) {
|
||||
age--;
|
||||
}
|
||||
|
||||
return age;
|
||||
}
|
||||
Reference in new issue
Block a user