diff options
author | George Hazan <ghazan@miranda.im> | 2022-01-29 19:33:13 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-01-29 19:33:13 +0300 |
commit | f627783781218a38e066a010654bbfce28775b35 (patch) | |
tree | 0a5201bdddb7b61ddb7c9768e394125b118981b1 /plugins/UserInfoEx | |
parent | 8ac32fb44ce4218555fe51e5afc75bd870319575 (diff) |
UInfoEx: average age calculation fix
Diffstat (limited to 'plugins/UserInfoEx')
-rw-r--r-- | plugins/UserInfoEx/src/classMAnnivDate.cpp | 8 | ||||
-rw-r--r-- | plugins/UserInfoEx/src/dlg_anniversarylist.cpp | 10 |
2 files changed, 11 insertions, 7 deletions
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
|