int GetContactDOB(MCONTACT hContact, int &year, int &month, int &day) { year = db_get_w(hContact, "UserInfo", "DOBy", 0); month = db_get_b(hContact, "UserInfo", "DOBm", 0); day = db_get_b(hContact, "UserInfo", "DOBd", 0); if ( IsDOBValid(year, month, day)) return DOB_USERINFO; char *szProto = GetContactProto(hContact); year = db_get_w(hContact, szProto, "BirthYear", 0); month = db_get_b(hContact, szProto, "BirthMonth", 0); day = db_get_b(hContact, szProto, "BirthDay", 0); if ( IsDOBValid(year, month, day)) return DOB_PROTOCOL; year = db_get_w(hContact, "BirthDay", "BirthYear", 0); month = db_get_b(hContact, "BirthDay", "BirthMonth", 0); day = db_get_b(hContact, "BirthDay", "BirthDay", 0); if ( IsDOBValid(year, month, day)) return DOB_BIRTHDAYREMINDER; year = db_get_w(hContact, "mBirthday", "BirthYear", 0); month = db_get_b(hContact, "mBirthday", "BirthMonth", 0); day = db_get_b(hContact, "mBirthday", "BirthDay", 0); if ( IsDOBValid(year, month, day)) return DOB_MBIRTHDAY; year = db_get_dw(hContact, "micqBirthday", "BirthYear", 0); month = db_get_dw(hContact, "micqBirthday", "BirthMonth", 0); day = db_get_dw(hContact, "micqBirthday", "BirthDay", 0); if ( IsDOBValid(year, month, day)) return DOB_MICQBIRTHDAY; return DOB_UNKNOWN; }
int DoExport(TCHAR *fileName) { FILE *fout = _tfopen(fileName, _T("wt")); if (!fout) { MessageBox(0, TranslateT("Could not open file to export birthdays"), TranslateT("Error"), MB_OK | MB_ICONERROR); return 1; } _ftprintf(fout, _T("%c%s"), _T(COMMENT_CHAR), TranslateT("Please do not edit this file by hand. Use the export function of WhenWasIt plugin.\n")); _ftprintf(fout, _T("%c%s"), _T(COMMENT_CHAR), TranslateT("Warning! Please do not mix Unicode and Ansi exported birthday files. You should use the same version (Ansi/Unicode) of WhenWasIt that was used to export the info.\n")); _ftprintf(fout, _T("%c%s"), _T(COMMENT_CHAR), TranslateT("This file was exported with a Unicode version of WhenWasIt. Please only use a Unicode version of the plugin to import the birthdays.\n")); for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { int year, month, day; GetContactDOB(hContact, year, month, day); if (IsDOBValid(year, month, day)) { char *szProto = GetContactProto(hContact); TCHAR *szHandle = GetContactID(hContact, szProto); if ((szHandle) && (mir_strlen(szProto) > 0)) _ftprintf(fout, _T(BIRTHDAYS_EXPORT_FORMAT), szHandle, szProto, day, month, year); if (szHandle) free(szHandle); } } fclose(fout); return 0; }
unsigned int DaysToBirthday(time_t now, int ctYear, int ctMonth, int ctDay) { if ( IsDOBValid(ctYear, ctMonth, ctDay)) { struct tm ct = {0}; struct tm *tmp = gmtime(&now); ct.tm_year = tmp->tm_year; ct.tm_mon = ctMonth - 1; ct.tm_mday = ctDay; time_t ctBirthday = mktime(&ct); return GetDaysDifference(ctBirthday, now); } return -1; }