//////////////////////////////////////////////////////////////////////// // FUNCTION: DayOfWeek // // DESCRIPTION: This routine return the day of the week // // PARAMETERS: (UInt16) months - Months. // (UInt16) days - Days // (UInt16) years - Years // // RETURNED: Returns the day of the week. // // REVISION HISTORY: // Name Date Description // ---- ---- ----------- // Jerry 7/05/01 Initial Revision //////////////////////////////////////////////////////////////////////// Int16 DayOfWeek (Int16 month, Int16 day, Int16 year) { DateType date; date.year = (year-SYSSTARTYEAR); date.month = month; date.day = day; #ifdef LINUX return (Int16)(((DateToDays (date)-1)+4)%7); // 1970/1/1 is Thursday(4). #else return (Int16)(((DateToDays (date)-1)+5)%7); // 1904/1/1 is Friday(5). #endif }
//////////////////////////////////////////////////////////////////////// // FUNCTION: DateAdjust // // DESCRIPTION: This routine return a new date +/- the days adjustment. // // PARAMETERS: (DatePtr) dateP - A DateType structure with the date to // be adjusted. // (Int32) adjustment - The Adjustment in number of days. // // RETURNED: Returns nothing. // // REVISION HISTORY: // Name Date Description // ---- ---- ----------- // Jerry 5/10/01 Initial Revision //////////////////////////////////////////////////////////////////////// void DateAdjust (DatePtr dateP, Int32 adjustment) { UInt32 days; days = DateToDays (*dateP); days += adjustment; DateDaysToDate (days, dateP); }
BOOL CheckTimeIsValid(RTC_DATE_TIME* Time) { BOOL TimeModifyFlag = TRUE; if((Time->Year > RTC_END_YEAR) || (Time->Year < RTC_START_YEAR)) { Time->Year = 1980; TimeModifyFlag = FALSE; } if((Time->Mon > 12) || (Time->Mon == 0)) { Time->Mon = 1; TimeModifyFlag = FALSE; } if((Time->Date == 0) || (Time->Date > GetMonthDays(Time->Year, Time->Mon))) { Time->Date = 1; TimeModifyFlag = FALSE; } if(Time->WDay > 6) { Time->WDay = WeekDayGet(DateToDays(Time)); TimeModifyFlag = FALSE; } if(Time->Hour > 23) { Time->Hour = 0; TimeModifyFlag = FALSE; } if(Time->Min > 59) { Time->Min = 0; TimeModifyFlag = FALSE; } if(Time->Sec > 59) { Time->Sec = 0; TimeModifyFlag = FALSE; } return TimeModifyFlag; }
//////////////////////////////////////////////////////////////////////// // FUNCTION: TimDateTimeToSeconds // // DESCRIPTION: This routine return the number of seconds since 1/1/1904 // to the passed date and time. // // PARAMETERS: (DateTimePtr) dateTimeP - Pointer to a DateTimeType structure. // // RETURNED: Returns the time in seconds since 1/1/1904. // // REVISION HISTORY: // Name Date Description // ---- ---- ----------- // Jerry 5/10/01 Initial Revision //////////////////////////////////////////////////////////////////////// UInt32 TimDateTimeToSeconds (DateTimePtr dateTimeP) { DateType date; UInt32 seconds=0; date.year = (dateTimeP->year-SYSSTARTYEAR); date.month = dateTimeP->month; date.day = dateTimeP->day; seconds = (DateToDays (date)-1) * secondsInADay ; seconds += (dateTimeP->hour+timeZoneDiff)*secondsInAHour; seconds += dateTimeP->minute*secondsInAMinute; seconds += dateTimeP->minute; return seconds; }
BOOL CheckAlarmTime(BYTE AlarmNum, BYTE AlarmMode, RTC_DATE_TIME* Time) { if(GetAlarmStatus(AlarmNum) == 2) { DBG(("闹钟由关闭到打开,注意调整闹钟时间\n")); if((AlarmMode <= ALARM_MODE_PER_WEEK) && (AlarmMode >= ALARM_MODE_ONCE_ONLY)) { gAlarmMode = AlarmMode; } else { gAlarmMode = ALARM_MODE_ONCE_ONLY; } } if(AlarmMode == ALARM_MODE_ONCE_ONLY) { if(CheckTimeIsValid(Time) == FALSE) { DBG(("闹钟时间非法已纠正\n")); } } else if(AlarmMode == ALARM_MODE_PER_DAY) { Time->Year = 1980; Time->Mon = 1; Time->Date = 1; } else if(AlarmMode == ALARM_MODE_PER_WEEK) { Time->Year = 1980; Time->Mon = 1; if(Time->WDay > 6) { Time->WDay = WeekDayGet(DateToDays(Time)); } } else { return FALSE; } return TRUE; }
/*********************************************************************** * * FUNCTION: ApptRepeatsOnDate * * DESCRIPTION: This routine returns true if a repeating appointment * occurrs on the specified date. * * PARAMETERS: apptRec - a pointer to an appointment record * date - date to check * * RETURNED: true if the appointment occurs on the date specified * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * art 6/14/95 Initial Revision * ***********************************************************************/ Boolean ApptRepeatsOnDate (ApptDBRecordPtr apptRec, DateType date) { Int16 i; UInt16 freq; UInt16 weeksDiff; UInt16 dayInMonth; UInt16 dayOfWeek; UInt16 dayOfMonth; UInt16 firstDayOfWeek; long dateInDays; long startInDays; Boolean onDate = false; DatePtr exceptions; DateType startDate; // Is the date passed before the start date of the appointment? if (DateCompare (date, apptRec->when->date) < 0) return (false); // Is the date passed after the end date of the appointment? if (DateCompare (date, apptRec->repeat->repeatEndDate) > 0) return (false); // Get the frequency of occurrecne // (ex: every 2nd day, every 3rd month, etc.). freq = apptRec->repeat->repeatFrequency; // Get the date of the first occurrecne of the appointment. startDate = apptRec->when->date; switch (apptRec->repeat->repeatType) { // Daily repeating appointment. case repeatDaily: dateInDays = DateToDays (date); startInDays = DateToDays (startDate); onDate = ((dateInDays - startInDays) % freq) == 0; break; // Weekly repeating appointment (ex: every Monday and Friday). // Yes, weekly repeating appointment can occur more then once a // week. case repeatWeekly: // Are we on a day of the week that the appointment repeats on. dayOfWeek = DayOfWeek (date.month, date.day, date.year+firstYear); onDate = ((1 << dayOfWeek) & apptRec->repeat->repeatOn); if (! onDate) break; // Are we in a week in which the appointment occurrs, if not // move to that start of the next week in which the appointment // does occur. dateInDays = DateToDays (date); startInDays = DateToDays (startDate); firstDayOfWeek = (DayOfWeek (1, 1, firstYear) - apptRec->repeat->repeatStartOfWeek + daysInWeek) % daysInWeek; weeksDiff = (((dateInDays + firstDayOfWeek) / daysInWeek) - ((startInDays + firstDayOfWeek) / daysInWeek)) %freq; onDate = (weeksDiff == 0); break; // // Compute the first occurrence of the appointment that occurs // // on the same day of the week as the date passed. // startDayOfWeek = DayOfWeek (startDate.month, startDate.day, // startDate.year+firstYear); // startInDays = DateToDays (startDate); // if (startDayOfWeek < dayOfWeek) // startInDays += dayOfWeek - startDayOfWeek; // else if (startDayOfWeek > dayOfWeek) // startInDays += dayOfWeek+ (daysInWeek *freq) - startDayOfWeek; // // // Are we in a week in which the appointment repeats. // dateInDays = DateToDays (date); // onDate = (((dateInDays - startInDays) / daysInWeek) % freq) == 0; // break; // Monthly-by-day repeating appointment (ex: the 3rd Friday of every // month). case repeatMonthlyByDay: // Are we in a month in which the appointment repeats. onDate = ((((date.year - startDate.year) * monthsInYear) + (date.month - startDate.month)) % freq) == 0; if (! onDate) break; // Do the days of the month match (ex: 3rd Friday) dayOfMonth = DayOfMonth (date.month, date.day, date.year+firstYear); onDate = (dayOfMonth == apptRec->repeat->repeatOn); if (onDate) break; // If the appointment repeats on one of the last days of the month, // check if the date passed is also one of the last days of the // month. By last days of the month we mean: last sunday, // last monday, etc. if ((apptRec->repeat->repeatOn >= domLastSun) && (dayOfMonth >= dom4thSun)) { dayOfWeek = DayOfWeek (date.month, date.day, date.year+firstYear); dayInMonth = DaysInMonth (date.month, date.year+firstYear); onDate = (((date.day + daysInWeek) > dayInMonth) && (dayOfWeek == (apptRec->repeat->repeatOn % daysInWeek))); } break; // Monthly-by-date repeating appointment (ex: the 15th of every // month). case repeatMonthlyByDate: // Are we in a month in which the appointment repeats. onDate = ((((date.year - startDate.year) * monthsInYear) + (date.month - startDate.month)) % freq) == 0; if (! onDate) break; // Are we on the same day of the month as the start date. onDate = (date.day == startDate.day); if (onDate) break; // If the staring day of the appointment is greater then the // number of day in the month passed, and the day passed is the // last day of the month, then the appointment repeats on the day. dayInMonth = DaysInMonth (date.month, date.year+firstYear); onDate = ((startDate.day > dayInMonth) && (date.day == dayInMonth)); break; // Yearly repeating appointment. case repeatYearly: // Are we in a year in which the appointment repeats. onDate = ((date.year - startDate.year) % freq) == 0; if (! onDate) break; // Are we on the month and day that the appointment repeats. onDate = (date.month == startDate.month) && (date.day == startDate.day); if (onDate) break; // Specal leap day processing. if ( (startDate.month == february) && (startDate.day == 29) && (date.month == february) && (date.day == DaysInMonth (date.month, date.year+firstYear))) { onDate = true; } break; default: break; } // Check for an exception. if ((onDate) && (apptRec->exceptions)) { exceptions = &apptRec->exceptions->exception; for (i = 0; i < apptRec->exceptions->numExceptions; i++) { if (DateCompare (date, exceptions[i]) == 0) { onDate = false; break; } } } return (onDate); }
/*********************************************************************** * * FUNCTION: NextRepeat * * DESCRIPTION: This routine computes the date of the next * occurrence of a repeating appointment. * * PARAMETERS: rec - a pointer to a DiddleBug record * date - passed: date to start from * returned: date of next occurrence * * RETURNED: true if the appointment occurs again * ***********************************************************************/ Boolean NextRepeat(DiddleBugRecordType* rec, DateTimeType* dateP) { /* ** Get the frequency on occurrence **(ex: every 2nd day, every 3rd month, etc). */ const UInt16 freq = rec->repeatInfo.repeatFrequency; Int16 i = 0; UInt16 day; UInt16 year; UInt16 adjust; UInt16 weeksDiff; UInt16 monthsDiff; UInt16 daysInMonth; UInt16 dayOfWeek; UInt16 apptWeekDay; UInt16 firstDayOfWeek; UInt16 daysTilNext; UInt16 monthsTilNext; UInt32 dateInDays; UInt32 startInDays; DateType start, date, when, next; DateTimeType nextReal; UInt32 startSecs, nextSecs; DateSecondsToDate(TimDateTimeToSeconds(dateP), &date); TimSecondsToDateTime(rec->alarmSecs, &nextReal); nextReal.year = dateP->year; nextReal.month = dateP->month; nextReal.day = dateP->day; nextReal.weekDay = dateP->weekDay; /* Calculate alarm date */ DateSecondsToDate(rec->alarmSecs, &when); /* Is the date passed after the end date of the appointment? */ if (DateCompare(date, rec->repeatInfo.repeatEndDate) > 0) return false; /* Is the date passed before the start date of the appointment? */ if (DateCompare(date, when) < 0) date = when; /* Get the date of the first occurrecne of the appointment. */ start = when; switch (rec->repeatInfo.repeatType) { /* Hourly repeating appointment */ case repeatHourly: startSecs = TimDateTimeToSeconds(dateP); nextSecs = rec->alarmSecs; while (nextSecs < startSecs) nextSecs += freq * hoursInSeconds; TimSecondsToDateTime(nextSecs, &nextReal); DateSecondsToDate(nextSecs, &next); break; /* Daily repeating appointment. */ case repeatDaily: dateInDays = DateToDays(date); startInDays = DateToDays(start); daysTilNext = (dateInDays - startInDays + freq - 1) / freq * freq; if (startInDays + daysTilNext > (UInt32) maxDays) return false; DateDaysToDate (startInDays + daysTilNext, &next); break; /* ** Weekly repeating appointment (ex: every Monday and Friday). ** Yes, weekly repeating appointment can occur more then once a ** week. */ case repeatWeekly: dateInDays = DateToDays(date); startInDays = DateToDays(start); firstDayOfWeek = (DayOfWeek (1, 1, firstYear) - rec->repeatInfo.repeatStartOfWeek + daysInWeek) % daysInWeek; dayOfWeek = DayOfWeek(date.month, date.day, date.year+firstYear); apptWeekDay = (dayOfWeek - rec->repeatInfo.repeatStartOfWeek + daysInWeek) % daysInWeek; /* ** Are we in a week in which the appointment occurrs, if not ** move to that start of the next week in which the appointment ** does occur. */ weeksDiff = (((dateInDays + firstDayOfWeek) / daysInWeek) - ((startInDays + firstDayOfWeek) / daysInWeek)) % freq; if (weeksDiff) { adjust = ((freq - weeksDiff) * daysInWeek) - apptWeekDay; apptWeekDay = 0; dayOfWeek = (dayOfWeek + adjust) % daysInWeek; } else { adjust = 0; } /* Find the next day on which the appointment repeats. */ for (; i < daysInWeek; i++) { if (rec->repeatInfo.repeatOn & (1 << dayOfWeek)) break; adjust++; if (++dayOfWeek == daysInWeek) dayOfWeek = 0; if (++apptWeekDay == daysInWeek) adjust += (freq - 1) * daysInWeek; } if (dateInDays + adjust > (UInt32) maxDays) return false; DateDaysToDate (dateInDays + adjust, &next); break; /* ** Monthly-by-day repeating appointment ** (ex: the 3rd Friday of every month). */ case repeatMonthlyByDay: /* Compute the number of month until the appointment repeats again. */ monthsTilNext = ((((date.year - start.year) * monthsInYear) + (date.month - start.month)) + freq - 1) / freq * freq; while (true) { year = start.year + (start.month - 1 + monthsTilNext) / monthsInYear; if (year >= numberOfYears) return false; next.year = year; next.month = (start.month - 1 + monthsTilNext) % monthsInYear + 1; dayOfWeek = DayOfWeek (next.month, 1, next.year+firstYear); if ((rec->repeatInfo.repeatOn % daysInWeek) >= dayOfWeek) day = rec->repeatInfo.repeatOn - dayOfWeek + 1; else day = rec->repeatInfo.repeatOn + daysInWeek - dayOfWeek + 1; /* ** If repeat-on day is between the last sunday and the last ** saturday, make sure we're not passed the end of the month. */ if ( (rec->repeatInfo.repeatOn >= domLastSun) && (day > DaysInMonth (next.month, next.year+firstYear))) { day -= daysInWeek; } next.day = day; /* ** Its posible that "next date" calculated above is ** before the date passed. If so, move forward ** by the length of the repeat freguency and preform ** the calculation again. */ if (DateToInt(date) > DateToInt(next)) monthsTilNext += freq; else break; } break; /* ** Monthly-by-date repeating appointment ** (ex: the 15th of every month). */ case repeatMonthlyByDate: /* Compute the number of month until the appointment repeats again. */ monthsDiff = (date.year - start.year) * monthsInYear + date.month - start.month; monthsTilNext = (monthsDiff + freq - 1) / freq * freq; if (date.day > start.day && !(monthsDiff % freq)) monthsTilNext += freq; year = start.year + (start.month - 1 + monthsTilNext) / monthsInYear; if (year >= numberOfYears) return false; next.year = year; next.month = (start.month - 1 + monthsTilNext) % monthsInYear + 1; next.day = start.day; /* Make sure we're not passed the last day of the month. */ daysInMonth = DaysInMonth(next.month, next.year+firstYear); if (next.day > daysInMonth) next.day = daysInMonth; break; /* Yearly repeating appointment. */ case repeatYearly: next.day = start.day; next.month = start.month; year = start.year + ((date.year - start.year + freq - 1) / freq * freq); if (date.month > start.month || (date.month == start.month && date.day > start.day)) year += freq; /* Specal leap day processing. */ if (next.month == february && next.day == 29 && next.day > DaysInMonth(next.month, year+firstYear)) { next.day = DaysInMonth (next.month, year+firstYear); } if (year >= numberOfYears) return false; next.year = year; break; default: /* ignore */ } /* Is the next occurrence after the end date of the appointment? */ if (DateCompare(next, rec->repeatInfo.repeatEndDate) > 0) return false; dateP->day = next.day; dateP->month = next.month; dateP->year = next.year + firstYear; dateP->hour = nextReal.hour; dateP->minute = nextReal.minute; dateP->second = nextReal.second; return true; }
Boolean NextRepeat (ApptDBRecordPtr apptRec, DatePtr dateP) { Int16 i; UInt16 day; UInt16 freq; UInt16 year; UInt16 adjust; UInt16 weeksDiff; UInt16 monthsDiff; UInt16 daysInMonth; UInt16 dayOfWeek; UInt16 apptWeekDay; UInt16 firstDayOfWeek; UInt16 daysTilNext; UInt16 monthsTilNext; UInt32 dateInDays; UInt32 startInDays; DateType start; DateType date; DateType next; date = *dateP; // Is the date passed after the end date of the appointment? if (DateCompare (date, apptRec->repeat->repeatEndDate) > 0) return (false); // Is the date passed before the start date of the appointment? if (DateCompare (date, apptRec->when->date) < 0) date = apptRec->when->date; // Get the frequency on occurrecne (ex: every 2nd day, every 3rd month, etc). freq = apptRec->repeat->repeatFrequency; // Get the date of the first occurrecne of the appointment. start = apptRec->when->date; switch (apptRec->repeat->repeatType) { // Daily repeating appointment. case repeatDaily: dateInDays = DateToDays (date); startInDays = DateToDays (start); daysTilNext = (dateInDays - startInDays + freq - 1) / freq * freq; if (startInDays + daysTilNext > (UInt32) maxDays) return (false); DateDaysToDate (startInDays + daysTilNext, &next); break; // Weekly repeating appointment (ex: every Monday and Friday). // Yes, weekly repeating appointment can occur more then once a // week. case repeatWeekly: dateInDays = DateToDays (date); startInDays = DateToDays (start); firstDayOfWeek = (DayOfWeek (1, 1, firstYear) - apptRec->repeat->repeatStartOfWeek + daysInWeek) % daysInWeek; dayOfWeek = DayOfWeek (date.month, date.day, date.year+firstYear); apptWeekDay = (dayOfWeek - apptRec->repeat->repeatStartOfWeek + daysInWeek) % daysInWeek; // Are we in a week in which the appointment occurrs, if not // move to that start of the next week in which the appointment // does occur. weeksDiff = (((dateInDays + firstDayOfWeek) / daysInWeek) - ((startInDays + firstDayOfWeek) / daysInWeek)) %freq; if (weeksDiff) { adjust = ((freq - weeksDiff) * daysInWeek)- apptWeekDay; apptWeekDay = 0; dayOfWeek = (dayOfWeek + adjust) % daysInWeek; } else adjust = 0; // Find the next day on which the appointment repeats. for (i = 0; i < daysInWeek; i++) { if (apptRec->repeat->repeatOn & (1 << dayOfWeek)) break; adjust++; if (++dayOfWeek == daysInWeek) dayOfWeek = 0; if (++apptWeekDay == daysInWeek) adjust += (freq - 1) * daysInWeek; } if (dateInDays + adjust > (UInt32) maxDays) return (false); DateDaysToDate (dateInDays + adjust, &next); // next = date; // DateAdjust (&next, adjust); break; // Monthly-by-day repeating appointment (ex: the 3rd Friday of every // month). case repeatMonthlyByDay: // Compute the number of month until the appointment repeats again. monthsTilNext = (date.month - start.month); monthsTilNext = ((((date.year - start.year) * monthsInYear) + (date.month - start.month)) + freq - 1) / freq * freq; while (true) { year = start.year + (start.month - 1 + monthsTilNext) / monthsInYear; if (year >= numberOfYears) return (false); next.year = year; next.month = (start.month - 1 + monthsTilNext) % monthsInYear + 1; dayOfWeek = DayOfWeek (next.month, 1, next.year+firstYear); if ((apptRec->repeat->repeatOn % daysInWeek) >= dayOfWeek) day = apptRec->repeat->repeatOn - dayOfWeek + 1; else day = apptRec->repeat->repeatOn + daysInWeek - dayOfWeek + 1; // If repeat-on day is between the last sunday and the last // saturday, make sure we're not passed the end of the month. if ( (apptRec->repeat->repeatOn >= domLastSun) && (day > DaysInMonth (next.month, next.year+firstYear))) { day -= daysInWeek; } next.day = day; // Its posible that "next date" calculated above is // before the date passed. If so, move forward // by the length of the repeat freguency and preform // the calculation again. if ( DateToInt(date) > DateToInt (next)) monthsTilNext += freq; else break; } break; // Monthly-by-date repeating appointment (ex: the 15th of every // month). case repeatMonthlyByDate: // Compute the number of month until the appointment repeats again. monthsDiff = ((date.year - start.year) * monthsInYear) + (date.month - start.month); monthsTilNext = (monthsDiff + freq - 1) / freq * freq; if ((date.day > start.day) && (!(monthsDiff % freq))) monthsTilNext += freq; year = start.year + (start.month - 1 + monthsTilNext) / monthsInYear; if (year >= numberOfYears) return (false); next.year = year; next.month = (start.month - 1 + monthsTilNext) % monthsInYear + 1; next.day = start.day; // Make sure we're not passed the last day of the month. daysInMonth = DaysInMonth (next.month, next.year+firstYear); if (next.day > daysInMonth) next.day = daysInMonth; break; // Yearly repeating appointment. case repeatYearly: next.day = start.day; next.month = start.month; year = start.year + ((date.year - start.year + freq - 1) / freq * freq); if ((date.month > start.month) || ((date.month == start.month) && (date.day > start.day))) year += freq; // Specal leap day processing. if ( (next.month == february) && (next.day == 29) && (next.day > DaysInMonth (next.month, year+firstYear))) { next.day = DaysInMonth (next.month, year+firstYear); } if (year >= numberOfYears) return (false); next.year = year; break; default: break; } // Is the next occurrence after the end date of the appointment? if (DateCompare (next, apptRec->repeat->repeatEndDate) > 0) return (false); ErrFatalDisplayIf ((DateToInt (next) < DateToInt (*dateP)), "Calculation error"); *dateP = next; return (true); }
/** * @brief * @param dbP Happydays DB pointer * @param AddrCategory The category of Address to be displayed * @param start Start position * @return The number of total Item * @remarks * @endif */ UInt16 AddrGetHappyDays(DmOpenRef dbP, UInt16 AddrCategory, DateType start) { UInt16 totalItems; UInt16 recordNum = 0; MemHandle recordH = 0; LineItemPtr ptr; PackedHappyDays* rp; HappyDays r; DateType converted; UInt16 currindex = 0; Int16 age; // if exist, free the memory // if (gTableRowHandle) { MemHandleFree(gTableRowHandle); gTableRowHandle = 0; } totalItems = DmNumRecordsInCategory(dbP, AddrCategory); if (totalItems > 0) { gTableRowHandle = MemHandleNew(sizeof(LineItemType)* totalItems); ErrFatalDisplayIf(!gTableRowHandle, "Out of memory"); if ((ptr = MemHandleLock(gTableRowHandle))) { for (recordNum = 0; recordNum < totalItems; recordNum++) { if ((recordH = DmQueryNextInCategory(dbP, &currindex, (UInt16)AddrCategory))) { ptr[recordNum].birthRecordNum = currindex; rp = (PackedHappyDays *) MemHandleLock(recordH); /* * Build the unpacked structure for an AddressDB * record. It is just a bunch of pointers into the rp * structure. */ UnpackHappyDays(&r, rp); // original r(in MainDB) not changed // local change for LineItemType // converted = r.date; if (r.flag.bits.nthdays) { int syear, smonth, sday; if (r.flag.bits.lunar || r.flag.bits.lunar_leap) { if (lunarL2S(lunarRefNum, converted.year + firstYear, converted.month, converted.day, r.flag.bits.lunar_leap, &syear, &smonth, &sday) != errNone) { MemHandleUnlock(recordH); currindex++; recordNum--; totalItems--; continue; } converted.day = sday; converted.month = smonth; converted.year = syear - firstYear; } DateAdjust(&converted, r.nth); if (DateToDays(converted) < DateToDays(start)) { MemHandleUnlock(recordH); currindex++; recordNum--; totalItems--; continue; } } else if (r.flag.bits.lunar || r.flag.bits.lunar_leap) { if (!FindNearLunar(&converted, start, r.flag.bits.lunar_leap)) { // ignore the records // converted.year = INVALID_CONV_DATE; // max year(for sorting) // indicate for invalid date } } else if (r.flag.bits.solar) { int maxtry = 4; DateType dt; dt = start; DateToInt(dt) = (DateToInt(dt) > DateToInt(converted)) ? DateToInt(dt) : DateToInt(converted); if (converted.month < dt.month || ( converted.month == dt.month && converted.day < dt.day)) { // birthdate is in last year? while (DaysInMonth(converted.month, ++dt.year) < converted.day && maxtry-- > 0) ; } else { while (DaysInMonth(converted.month, dt.year) < converted.day && maxtry-- >0) { dt.year++; } } if (maxtry >0) converted.year = dt.year; else { converted.year = INVALID_CONV_DATE; // max year // indicate for invalid date } } if (converted.year != INVALID_CONV_DATE && !r.flag.bits.nthdays && r.flag.bits.year && (age = CalculateAge(converted, r.date, r.flag)) >= 0) { // calculate age if year exists // ptr[recordNum].age = age; } else { ptr[recordNum].age = -1; } // save the converted data // ptr[recordNum].date = converted; MemHandleUnlock(recordH); currindex++; } } // sort the order if sort order is converted date // if (gPrefsR.sort == 1) { // date sort SysInsertionSort(ptr, totalItems, sizeof(LineItemType), (_comparF *)CompareHappyDaysFunc, 1L); } else if (gPrefsR.sort == 3) { // age sort SysInsertionSort(ptr, totalItems, sizeof(LineItemType), (_comparF *)CompareAgeFunc, 1L); } else if (gPrefsR.sort == 2) { // age sort(re) SysInsertionSort(ptr, totalItems, sizeof(LineItemType), (_comparF *)CompareAgeFunc, -1L); } MemPtrUnlock(ptr); } else return 0; } return totalItems; }
static VOID RtcTimeDown(RTC_DATE_TIME* Time) { switch(RtcSubState) { #ifdef FUNC_ALARM_EN case RTC_SET_ALARM_NUM: RtcAlarmNum--; if(RtcAlarmNum < 1) { //RtcAlarmNum = 8; RtcAlarmNum = MAX_ALARM_NUM; } gAlarmMode = GetAlarmTime(RtcAlarmNum, Time); DBG(("RtcAlarmNum:%bu\n", RtcAlarmNum)); break; case RTC_SET_ALARM_MODE: if(ALARM_MODE_ONCE_ONLY == gAlarmMode) { AlarmTemp = *Time; } else if(ALARM_MODE_PER_WEEK == gAlarmMode) { AlarmTemp.WDay = Time->WDay; } gAlarmMode--; if(gAlarmMode < ALARM_MODE_ONCE_ONLY) { gAlarmMode = ALARM_MODE_PER_WEEK; } if(ALARM_MODE_ONCE_ONLY == gAlarmMode) { Time->Year = AlarmTemp.Year; Time->Mon = AlarmTemp.Mon; Time->Date = AlarmTemp.Date; Time->WDay = AlarmTemp.WDay; } else if(ALARM_MODE_PER_WEEK == gAlarmMode) { Time->WDay = AlarmTemp.WDay; } DBG(("gAlarmMode[%bu]=%s\n", gAlarmMode, ModeDisp[gAlarmMode - 1])); break; #ifdef AU6210K_CAR_MODEL_DEMO case RTC_SET_ALARM_ONOFF: if(gAlarmState == ALARM_STATUS_OPEN) { gAlarmState = ALARM_STATUS_CLOSE; DBG(("ALARM_STATUS_CLOSE\n")); } else { gAlarmState = ALARM_STATUS_OPEN; DBG(("ALARM_STATUS_OPEN\n")); } break; #endif #endif case RTC_SET_YEAR: Time->Year--; if(Time->Year < RTC_START_YEAR) { Time->Year = RTC_END_YEAR; } Time->WDay = WeekDayGet(DateToDays(Time)); break; case RTC_SET_MON: Time->Mon--; if(Time->Mon == 0) { Time->Mon = 12; } if(Time->Date > GetMonthDays(Time->Year, Time->Mon)) { Time->Date = GetMonthDays(Time->Year, Time->Mon); } Time->WDay = WeekDayGet(DateToDays(Time)); break; case RTC_SET_DATE: Time->Date--; if(Time->Date == 0) { Time->Date = GetMonthDays(Time->Year, Time->Mon); } Time->WDay = WeekDayGet(DateToDays(Time)); break; #ifdef FUNC_ALARM_EN case RTC_SET_WEEK: if(Time->WDay > 0) { Time->WDay--; } else { Time->WDay = 6; } break; #endif case RTC_SET_HR: Time->Sec = 0; Time->Hour--; if(Time->Hour > 23) { Time->Hour = 23; } break; case RTC_SET_MIN: Time->Sec = 0; Time->Min--; if(Time->Min > 59) { Time->Min = 59; } break; #ifdef AU6210K_BOOMBOX_DEMO case RTC_SET_ALARM_SOURCE: if(gAlarmSource > RTC_ALARM_SOURCE_RADIO) { gAlarmSource--; } break; case RTC_SET_ALARM_VOLUME: if(gAlarmVolume > VOLUME_MIN) { gAlarmVolume--; } break; #endif default: break; } }
static VOID RtcTimeUp(RTC_DATE_TIME* Time) { switch(RtcSubState) { #ifdef FUNC_ALARM_EN case RTC_SET_ALARM_NUM: RtcAlarmNum++; if(RtcAlarmNum > MAX_ALARM_NUM) { RtcAlarmNum = 1; } gAlarmMode = GetAlarmTime(RtcAlarmNum, Time); DBG(("RtcAlarmNum:%bu\n", RtcAlarmNum)); break; case RTC_SET_ALARM_MODE: if(ALARM_MODE_ONCE_ONLY == gAlarmMode) { AlarmTemp = *Time; } else if(ALARM_MODE_PER_WEEK == gAlarmMode) { AlarmTemp.WDay = Time->WDay; } gAlarmMode++; if(gAlarmMode > ALARM_MODE_PER_WEEK) { gAlarmMode = ALARM_MODE_ONCE_ONLY; } if(ALARM_MODE_ONCE_ONLY == gAlarmMode) { Time->Year = AlarmTemp.Year; Time->Mon = AlarmTemp.Mon; Time->Date = AlarmTemp.Date; Time->WDay = AlarmTemp.WDay; } else if(ALARM_MODE_PER_WEEK == gAlarmMode) { Time->WDay = AlarmTemp.WDay; } DBG(("gAlarmMode[%bu]=%s\n", gAlarmMode,ModeDisp[gAlarmMode-1])); break; #ifdef AU6210K_CAR_MODEL_DEMO case RTC_SET_ALARM_ONOFF: if(gAlarmState == ALARM_STATUS_OPEN) { gAlarmState = ALARM_STATUS_CLOSE; DBG(("ALARM_STATUS_CLOSE\n")); } else { gAlarmState = ALARM_STATUS_OPEN; DBG(("ALARM_STATUS_OPEN\n")); } break; #endif #endif case RTC_SET_YEAR: DBG(("Time->Year:%u\n", Time->Year)); Time->Year++; if(Time->Year > RTC_END_YEAR) { Time->Year = RTC_START_YEAR; } Time->WDay = WeekDayGet(DateToDays(Time)); break; case RTC_SET_MON: Time->Mon++; if(Time->Mon > 12) { Time->Mon = 1; } if(Time->Date > GetMonthDays(Time->Year, Time->Mon)) { Time->Date = GetMonthDays(Time->Year, Time->Mon); } Time->WDay = WeekDayGet(DateToDays(Time)); break; case RTC_SET_DATE: Time->Date++; if(Time->Date > GetMonthDays(Time->Year, Time->Mon)) { Time->Date = 1; } Time->WDay = WeekDayGet(DateToDays(Time)); break; #ifdef FUNC_ALARM_EN case RTC_SET_WEEK: if(Time->WDay < 6) { Time->WDay++; } else { Time->WDay = 0; } break; #endif case RTC_SET_HR: Time->Sec = 0; Time->Hour++; if(Time->Hour > 23) { Time->Hour = 0; } break; case RTC_SET_MIN: Time->Sec = 0; Time->Min++; if(Time->Min > 59) { Time->Min = 0; } break; #ifdef AU6210K_BOOMBOX_DEMO case RTC_SET_ALARM_SOURCE: if(gAlarmSource < RTC_ALARM_ONOFF) { gAlarmSource++; } break; case RTC_SET_ALARM_VOLUME: if(gAlarmVolume < VOLUME_MAX) { gAlarmVolume++; } break; #endif default: break; } }