void addDaysToDate(int daysToAdd, DATE* dateToModify) { printf("Adding %d days to ", daysToAdd); showDate(dateToModify); dateToModify->day += daysToAdd; if(dateToModify->day > DAYS_PER_MONTH) { dateToModify->month += dateToModify->day / DAYS_PER_MONTH; //Increase months by excess month(s) in days dateToModify->day %= DAYS_PER_MONTH; //Keep remaining days that don't exceed a month } if(dateToModify->month > MONTHS_PER_YEAR) { dateToModify->year += dateToModify->month / MONTHS_PER_YEAR; //Increase years by excess year(s) in months dateToModify->month %= MONTHS_PER_YEAR; //Keep remaining months that don't exceed a year } //Note: There'a problem with this logic. We'll get months numbered 0 to 11 instead of 1 to 12, // and days 0 to 29 instead of 1 to 30! printf(" results in "); showDate(dateToModify); printf(".\n"); }
void TimeZoneBoundaryTest::findDaylightBoundaryUsingDate(UDate d, const char* startMode, UDate expectedBoundary) { UnicodeString str; if (dateToString(d, str).indexOf(startMode) == - 1) { logln(UnicodeString("Error: ") + startMode + " not present in " + str); } UDate min = d; UDate max = min + SIX_MONTHS; while ((max - min) > INTERVAL) { UDate mid = (min + max) / 2; UnicodeString* s = &dateToString(mid, str); if (s->indexOf(startMode) != - 1) { min = mid; } else { max = mid; } } logln("Date Before: " + showDate(min)); logln("Date After: " + showDate(max)); UDate mindelta = expectedBoundary - min; UDate maxdelta = max - expectedBoundary; if (mindelta >= 0 && mindelta <= INTERVAL && maxdelta >= 0 && maxdelta <= INTERVAL) logln(UnicodeString("PASS: Expected boundary at ") + expectedBoundary); else dataerrln(UnicodeString("FAIL: Expected boundary at ") + expectedBoundary); }
void TimeZoneBoundaryTest::testUsingBinarySearch(SimpleTimeZone* tz, UDate d, UDate expectedBoundary) { UErrorCode status = U_ZERO_ERROR; UDate min = d; UDate max = min + SIX_MONTHS; UBool startsInDST = tz->inDaylightTime(d, status); if (failure(status, "SimpleTimeZone::inDaylightTime", TRUE)) return; if (tz->inDaylightTime(max, status) == startsInDST) { errln("Error: inDaylightTime(" + dateToString(max) + ") != " + ((!startsInDST)?"true":"false")); } if (failure(status, "SimpleTimeZone::inDaylightTime")) return; while ((max - min) > INTERVAL) { UDate mid = (min + max) / 2; if (tz->inDaylightTime(mid, status) == startsInDST) { min = mid; } else { max = mid; } if (failure(status, "SimpleTimeZone::inDaylightTime")) return; } logln("Binary Search Before: " + showDate(min)); logln("Binary Search After: " + showDate(max)); UDate mindelta = expectedBoundary - min; UDate maxdelta = max - expectedBoundary; if (mindelta >= 0 && mindelta <= INTERVAL && maxdelta >= 0 && maxdelta <= INTERVAL) logln(UnicodeString("PASS: Expected boundary at ") + expectedBoundary); else errln(UnicodeString("FAIL: Expected boundary at ") + expectedBoundary); }
void testDates(void) { DATE* birthday=NULL; DATE* today=NULL; int distance; today=getDateFromUser("today's date"); printf("You entered:"); showDate(today); printf("\n"); birthday=getDateFromUser("your birthday"); distance = daysFromTo(birthday, today); printf("That's about %d days ago\n", distance); addDaysToDate(distance, today); printf("Just think: in %d more days, it'll be ", distance); showDate(today); printf("!\n"); }
void showClock() { LCDGotoXY(0,0) ; showTime() ; LCDGotoXY(0,1) ; showDate() ; // only show the running time when we arn't selecting a menu if (menuFunction == MENU_NONE) showRunningTime(); }
void CInfoBar::clickLeft(tribool down, bool previousState) { if (down) { if (state == HERO || state == TOWN) showGameStatus(); else if (state == GAME) showDate(); else showSelection(); } }
void TimeZoneBoundaryTest::findDaylightBoundaryUsingTimeZone(UDate d, UBool startsInDST, UDate expectedBoundary, TimeZone* tz) { UErrorCode status = U_ZERO_ERROR; UnicodeString str; UDate min = d; UDate max = min + SIX_MONTHS; if (tz->inDaylightTime(d, status) != startsInDST) { dataerrln("FAIL: " + tz->getID(str) + " inDaylightTime(" + dateToString(d) + ") != " + (startsInDST ? "true" : "false")); startsInDST = !startsInDST; } if (failure(status, "TimeZone::inDaylightTime", TRUE)) return; if (tz->inDaylightTime(max, status) == startsInDST) { dataerrln("FAIL: " + tz->getID(str) + " inDaylightTime(" + dateToString(max) + ") != " + (startsInDST ? "false" : "true")); return; } if (failure(status, "TimeZone::inDaylightTime")) return; while ((max - min) > INTERVAL) { UDate mid = (min + max) / 2; UBool isIn = tz->inDaylightTime(mid, status); if (failure(status, "TimeZone::inDaylightTime")) return; if (isIn == startsInDST) { min = mid; } else { max = mid; } } logln(tz->getID(str) + " Before: " + showDate(min)); logln(tz->getID(str) + " After: " + showDate(max)); UDate mindelta = expectedBoundary - min; UDate maxdelta = max - expectedBoundary; if (mindelta >= 0 && mindelta <= INTERVAL && maxdelta >= 0 && maxdelta <= INTERVAL) logln(UnicodeString("PASS: Expected boundary at ") + expectedBoundary); else errln(UnicodeString("FAIL: Expected boundary at ") + expectedBoundary); }
ExtDate timeBox::createDate (bool */*ok*/) { QString entry = text().stripWhiteSpace(); // if entry is an empty string or invalid date use current date ExtDate date = ExtDate().fromString(entry); if ( !date.isValid() ) { kdDebug() << k_funcinfo << "Invalid date" << endl; showDate(ExtDate::currentDate()); entry = text().stripWhiteSpace(); return ExtDate::currentDate(); } else { return date; } }
void doMenu() { while(bButton) readInputs(); // set the new time if (menuFunction == MENU_NONE | menuFunction == MENU_TIME) { int h,m,s ; h = hour ; m = minute ; s = seconds ; LCDClear(); LCDWriteString(setText); LCDWriteString("Hours"); LCDGotoXY(0,1) ; showTime(); while(!bButton) { readInputs(); if (state & DIR_CW) { hour++; if (hour > 23) hour = 0 ; } else if (state & DIR_CCW) { hour--; if (hour < 0) hour = 0 ; } if (state & 0x30) { LCDGotoXY(0,1) ; showTime(); } } while(bButton) readInputs(); LCDGotoXY(0,0) ; LCDWriteString(setText); LCDWriteString("Minutes"); while(!bButton) { readInputs(); if (state & DIR_CW) { minute++; if (minute > 59) minute = 0 ; } else if (state & DIR_CCW) { minute--; if (minute < 0) minute = 0 ; } if (state & 0x30) { LCDGotoXY(0,1) ; showTime(); } } while(bButton) readInputs(); LCDGotoXY(0,0) ; LCDWriteString(setText); LCDWriteString("Seconds"); while(!bButton) { readInputs(); if (state & DIR_CW) { seconds++; if (seconds > 59) seconds = 0 ; } else if (state & DIR_CCW) { seconds--; if (seconds < 0) seconds = 0 ; } if (state & 0x30) { LCDGotoXY(0,1) ; showTime(); } } // save changes if (h != hour || m != minute || s != seconds) { // we only update the RTC if changes have been made h = ((hour / 10) << 4) + hour % 10 ; m = ((minute / 10) << 4) + minute % 10 ; s = ((seconds / 10) << 4) + seconds % 10 ; DS1307_SetTime(h,m,s) ; runningMinute = minute ; } while(bButton) readInputs(); } // set the new date if (menuFunction == MENU_NONE | menuFunction == MENU_DATE) { int n,d,m,y ; n = day ; d = date ; m = month ; y = year ; LCDClear(); LCDWriteString(setText); LCDWriteString("Year"); LCDGotoXY(0,1) ; showDate(); while(!bButton) { readInputs(); if (state & DIR_CW) { year++; if (year > 99) year = 0 ; } else if (state & DIR_CCW) { year--; if (year < 0) date = 99 ; } if (state & 0x30) { LCDGotoXY(0,1) ; showDate(); } } while(bButton) readInputs(); LCDGotoXY(0,0) ; LCDWriteString(setText); LCDWriteString("Month"); while(!bButton) { readInputs(); if (state & DIR_CW) { month++; if (month > 12) month = 1 ; } else if (state & DIR_CCW) { month--; if (!month) month = 12 ; } if (state & 0x30) { LCDGotoXY(0,1) ; showDate(); } } while(bButton) readInputs(); LCDGotoXY(0,0) ; LCDWriteString(setText); LCDWriteString("Date "); while(!bButton) { readInputs(); if (state & DIR_CW) { date++; if (date > monthDays[month-1]) date = 1 ; } else if (state & DIR_CCW) { date--; if (date < 0) date = monthDays[month-1] ; } if (state & 0x30) { LCDGotoXY(0,1) ; showDate(); } } while(bButton) readInputs(); LCDGotoXY(0,0) ; LCDWriteString(setText); LCDWriteString("Day "); while(!bButton) { readInputs(); if (state & DIR_CW) { day++; if (day > 7) day = 1 ; } else if (state & DIR_CCW) { day--; if (day < 0) day = 7 ; } if (state & 0x30) { LCDGotoXY(0,1) ; showDate(); } } if (n != day || d != date || m != month || y != year) { // again, we only update the RTC if changes have been made n = ((day / 10) << 4) + day % 10 ; d = ((date / 10) << 4) + date % 10 ; m = ((month / 10) << 4) + month % 10 ; y = ((year / 10) << 4) + year % 10 ; DS1307_SetDate(n,d,m,y) ; } while(bButton) readInputs(); } }
void DigitalClock::mousePressEvent( QMouseEvent *e ) { if ( e->button() == QMouseEvent::LeftButton ) // left button pressed showDate(); }
Dates(int m, int d, int y){ showDate(m,d,y); };