Skip to content

Commit 865b6bf

Browse files
committed
Fix displaying birthday for leap+non-leap year combination
1 parent 11fed59 commit 865b6bf

File tree

1 file changed

+10
-4
lines changed
  • app/src/main/java/org/thunderdog/challegram/core

1 file changed

+10
-4
lines changed

app/src/main/java/org/thunderdog/challegram/core/Lang.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,26 +2414,32 @@ public static String getDownloadStatus (TdApi.File file, int downloadedRes, bool
24142414

24152415
public static CharSequence getBirthdate (@NonNull TdApi.Birthdate birthdate, boolean includeAge, boolean isSelf) {
24162416
Calendar c = Calendar.getInstance();
2417+
c.setTimeInMillis(0);
24172418
c.set(Calendar.DAY_OF_MONTH, birthdate.day);
24182419
c.set(Calendar.MONTH, birthdate.month - 1);
2420+
int birthDayOfThisYear = -1;
24192421
String date;
24202422
if (birthdate.year != 0) {
24212423
c.set(Calendar.YEAR, birthdate.year);
24222424
date = dateYearShort(c);
2425+
2426+
Calendar now = DateUtils.getNowCalendar();
2427+
now.set(Calendar.DAY_OF_MONTH, birthdate.day);
2428+
now.set(Calendar.MONTH, birthdate.month - 1);
2429+
birthDayOfThisYear = now.get(Calendar.DAY_OF_YEAR);
24232430
} else {
24242431
date = dateShort(c);
24252432
}
24262433
int ageYears = -1;
24272434
int daysTillBirthday = 0;
24282435
if (birthdate.year != 0) {
24292436
Calendar now = DateUtils.getNowCalendar();
2430-
ageYears = now.get(Calendar.YEAR) - c.get(Calendar.YEAR);
2437+
ageYears = now.get(Calendar.YEAR) - birthdate.year;
24312438
int today = now.get(Calendar.DAY_OF_YEAR);
2432-
int birthday = c.get(Calendar.DAY_OF_YEAR);
2433-
if (today < birthday) {
2439+
if (today < birthDayOfThisYear) {
24342440
ageYears--;
24352441
}
2436-
daysTillBirthday = birthday - today;
2442+
daysTillBirthday = birthDayOfThisYear - today;
24372443
}
24382444
if (includeAge && ageYears > 0) {
24392445
CharSequence age;

0 commit comments

Comments
 (0)