Exemplo n.º 1
0
/* Create new item in app database */
static UInt16
DoTheBoogie(KleenexPtr kleenexP, DmOpenRef dbR, UInt16 *index)
{
    ApptDBRecordType datebook;
    ApptDateTimeType dbwhen;
    AlarmInfoType dbalarm;
    UInt32 secs;

    MemSet(&datebook, sizeof(ApptDBRecordType), 0);
    MemSet(&dbwhen, sizeof(ApptDateTimeType), 0);
    MemSet(&dbalarm, sizeof(AlarmInfoType), 0);
    datebook.when = &dbwhen;
    datebook.alarm = &dbalarm;

    // Set up the record
    datebook.repeat = kleenexP->repeat;
    datebook.note = kleenexP->note;
    datebook.description = kleenexP->text;

    // Set date and time
    if (!(secs = kleenexP->alarm_secs))
        secs = TimGetSeconds();
    DateSecondsToDate(secs, &dbwhen.date);
    if (kleenexP->alarm_secs % 86400) {
        SetSaneTimes(secs, &dbwhen.startTime, &dbwhen.endTime);
    } else {
        TimeToInt(dbwhen.startTime) = apptNoTime;
        TimeToInt(dbwhen.endTime) = apptNoTime;
    }

    // Set the alarm
    dbalarm.advanceUnit = aauMinutes;
    if (kleenexP->alarm_secs) {
        dbalarm.advance = 0;
    } else {
        dbalarm.advance = apptNoAlarm;
        datebook.alarm = NULL;
    }

    // Add it to the DB
    return (ApptNewRecord(dbR, &datebook, index));
}
Exemplo n.º 2
0
Boolean Ln2SlFormHandleEvent(EventPtr e)
{
    Boolean handled = false;
    DateType dt = {0, 0};
    FormPtr frm = FrmGetFormPtr(Ln2SlForm);

    switch (e->eType) {
    case frmOpenEvent:
        if(gbVgaExists)
       		VgaFormModify(frm, vgaFormModify160To240);

        DateSecondsToDate(TimGetSeconds(), &dt);
        DateToAsciiLong(dt.month, dt.day, dt.year + 1904,
					gPrefdfmts, gAppErrStr);
        SetFieldTextFromStr(Ln2SlFormInput, gAppErrStr);

        FrmDrawForm(frm);
        handled = true;
        break;

    case ctlSelectEvent:
        switch(e->data.ctlSelect.controlID) {
        case Ln2SlFormOk:
            FrmReturnToForm(0);

            handled = true;
            break;

        case Ln2SlFormConvert:
        {
            HappyDaysFlag dummy;
            Int16 year, month, day;
            Char* input;
            int ret;
            
            input = FldGetTextPtr(GetObjectPointer(frm, Ln2SlFormInput));

            if ((ret = AnalysisHappyDays(input, &dummy,
                                         &year, &month, &day))) {
                int syear, smonth, sday;
                int leapyes
                    = CtlGetValue(GetObjectPointer(frm, Ln2SlFormInputLeap));

                ret = lunarL2S(lunarRefNum, year, month, day, leapyes, &syear, &smonth, &sday);
                if (ret == errNone) {
                    Char temp[15];
                    SysCopyStringResource(temp, DayOfWeek(smonth, sday, syear) + SunString);

                    DateToAsciiLong(smonth, sday, syear, gPrefdfmts, gAppErrStr);
                    StrNCat(gAppErrStr, " [", AppErrStrLen);
                    StrNCat(gAppErrStr, temp, AppErrStrLen);
                    StrNCat(gAppErrStr, "]", AppErrStrLen);

                    FldDrawField(SetFieldTextFromStr(Ln2SlFormResult, gAppErrStr));
                }
                else DisplayInvalidDateErrorString(Ln2SlFormResult);
            }
            else {
                DisplayInvalidDateErrorString(Ln2SlFormResult);
            }
            
            handled = true;
            break;
        }
        
        default:
            break;
                
        }
        break;

    case menuEvent:
        handled = TextMenuHandleEvent(e->data.menu.itemID, Ln2SlFormInput);
        break;

    default:
        break;
    }

    return handled;
}
Exemplo n.º 3
0
/***********************************************************************
 *
 * 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;
}
Exemplo n.º 4
0
Boolean Sl2LnFormHandleEvent(EventPtr e)
{
    Boolean handled = false;
    DateType dt = {0, 0};
    FormPtr frm = FrmGetFormPtr(Sl2LnForm);

    switch (e->eType) {
    case frmOpenEvent:
        if(gbVgaExists)
       		VgaFormModify(frm, vgaFormModify160To240);

        DateSecondsToDate(TimGetSeconds(), &dt);

        DateToAsciiLong(dt.month, dt.day, dt.year + 1904,
                        gPrefdfmts, gAppErrStr);

        SetFieldTextFromStr(Sl2LnFormInput, gAppErrStr);

        FrmDrawForm(frm);
        handled = true;
        break;

    case ctlSelectEvent:
        switch(e->data.ctlSelect.controlID) {
        case Sl2LnFormConvert:
        {
            HappyDaysFlag dummy;
            Int16 year, month, day;
            int lyear, lmonth, lday;
            Char* input;
            int ret = false;

            input = FldGetTextPtr(GetObjectPointer(frm, Sl2LnFormInput));
            if ((ret = AnalysisHappyDays(input, &dummy,
                                         &year, &month, &day))) {
                int leapyes = 0;

                ret = lunarS2L(lunarRefNum, year, month, day, &lyear, &lmonth, &lday, &leapyes);
                if (ret == errNone) {
                    if (leapyes) {
                        StrCopy(gAppErrStr, "#)");
                    }
                    else {
                        StrCopy(gAppErrStr, "-)");
                    }
                    DateToAsciiLong(lmonth, lday, lyear, gPrefdfmts, &gAppErrStr[2]);
                          
                    FldDrawField(SetFieldTextFromStr(Sl2LnFormResult,
                                                     gAppErrStr));
                }
                else DisplayInvalidDateErrorString(Sl2LnFormResult);

            }
            else DisplayInvalidDateErrorString(Sl2LnFormResult);

            handled = true;
            break;
        }

        case Sl2LnFormOk:
            FrmReturnToForm(0);

            handled = true;
            break;
            
        default:
            break;
                
        }
        break;

    case menuEvent:
        handled = TextMenuHandleEvent(e->data.menu.itemID, Sl2LnFormInput);
        break;

    default:
        break;
    }

    return handled;
}