From f627783781218a38e066a010654bbfce28775b35 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 29 Jan 2022 19:33:13 +0300 Subject: UInfoEx: average age calculation fix --- plugins/UserInfoEx/src/classMAnnivDate.cpp | 8 +++++--- plugins/UserInfoEx/src/dlg_anniversarylist.cpp | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'plugins/UserInfoEx/src') diff --git a/plugins/UserInfoEx/src/classMAnnivDate.cpp b/plugins/UserInfoEx/src/classMAnnivDate.cpp index be8f50995f..462b7ee500 100644 --- a/plugins/UserInfoEx/src/classMAnnivDate.cpp +++ b/plugins/UserInfoEx/src/classMAnnivDate.cpp @@ -345,14 +345,16 @@ int MAnnivDate::DBGetDate(MCONTACT hContact, LPCSTR pszModule, LPCSTR szDay, LPC { ZeroDate(); - uint16_t wtmp = db_get_w(hContact, pszModule, szYear, 0); + int wtmp = db_get_w(hContact, pszModule, szYear); + if (wtmp <= 1900) + wtmp = 0; Year(wtmp); - wtmp = db_get_w(hContact, pszModule, szMonth, 0); + wtmp = db_get_w(hContact, pszModule, szMonth); if (wtmp > 0 && wtmp < 13) { Month(wtmp); - wtmp = db_get_w(hContact, pszModule, szDay, 0); + wtmp = db_get_w(hContact, pszModule, szDay); if (wtmp > 0 && wtmp <= DaysInMonth(Month())) { Day(wtmp); // date was correctly read from db diff --git a/plugins/UserInfoEx/src/dlg_anniversarylist.cpp b/plugins/UserInfoEx/src/dlg_anniversarylist.cpp index 25b15c6206..7a6b0e89e0 100644 --- a/plugins/UserInfoEx/src/dlg_anniversarylist.cpp +++ b/plugins/UserInfoEx/src/dlg_anniversarylist.cpp @@ -704,7 +704,7 @@ class CAnnivList { MAnnivDate ad; int i = 0; - uint32_t age = 0; + int totalAge = 0; int wDaysBefore = g_plugin.getWord(SET_REMIND_OFFSET, DEFVAL_REMIND_OFFSET); int numMale = 0; int numFemale = 0; @@ -738,8 +738,10 @@ class CAnnivList } if (!ad.DBGetBirthDate(hContact, pszProto)) { - age += ad.Age(&mtNow); - numBirthContacts++; + if (int age = ad.Age(&mtNow)) { + totalAge += age; + numBirthContacts++; + } // add birthday if ((_filter.bFilterIndex != FILTER_ANNIV) && (!_filter.pszProto || !_strcmpi(pszProto, _filter.pszProto))) @@ -761,7 +763,7 @@ class CAnnivList SetDlgItemInt(_hDlg, TXT_NUMCONTACT, numContacts, FALSE); SetDlgItemInt(_hDlg, TXT_FEMALE, numFemale, FALSE); SetDlgItemInt(_hDlg, TXT_MALE, numMale, FALSE); - SetDlgItemInt(_hDlg, TXT_AGE, numBirthContacts > 0 ? (age - (age % numBirthContacts)) / numBirthContacts : 0, FALSE); + SetDlgItemInt(_hDlg, TXT_AGE, numBirthContacts > 0 ? totalAge / numBirthContacts : 0, FALSE); } // This method deletes all items from the listview -- cgit v1.2.3