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; }
int GetContactAge(MCONTACT hContact) { int year, month, day; time_t tNow; time(&tNow); struct tm *now = localtime(&tNow); GetContactDOB(hContact, year, month, day); return (now->tm_year + 1900) - year; }
/* returns -1 if notify is not necesarry returns daysToBirthday if it should notify */ int NotifyContactBirthday(MCONTACT hContact, time_t now, int daysInAdvance) { int year, month, day; GetContactDOB(hContact, year, month, day); int daysToBirthday = DaysToBirthday(now, year, month, day); if (daysInAdvance >= daysToBirthday) return daysToBirthday; return -1; }
// returns -1 if notify is not necessary // returns daysAfterBirthday if it should notify int NotifyMissedContactBirthday(MCONTACT hContact, time_t now, int daysAfter) { if (daysAfter > 0) { int year, month, day; GetContactDOB(hContact, year, month, day); int daysAfterBirthday = DaysAfterBirthday(now, year, month, day); if ((daysAfterBirthday >= 0) && (daysAfter >= daysAfterBirthday)) { return daysAfterBirthday; } } return -1; }