void CalendarTestParams::testDates() { setYear( 2008 ); int m = getMonth( "february" ); CPPUNIT_ASSERT_EQUAL( 2, m ); m = getMonth( "rubbish" ); CPPUNIT_ASSERT_EQUAL( 0, m ); int d = getDate( /*month*/1, /*day*/1, /*week*/1 ); // first Monday is 6th CPPUNIT_ASSERT_EQUAL( 7, d ); // Tuesday 1st, first Monday is 7th d = getDate( /*month*/5, /*day*/6, /*week*/3 ); // May 144 CPPUNIT_ASSERT_EQUAL( 17, d ); // Tuesday 1st, first Monday is 7th d = getDate( /*month*/6, /*day*/7, /*week*/2 ); CPPUNIT_ASSERT_EQUAL( 8, d ); // 2nd sunday in june d = getDate( /*month*/6, /*day*/2, /*week*/5 ); CPPUNIT_ASSERT_EQUAL( 0, d ); // 5th Tuesday in june TDateTime t = TDateTime( 2008, 5, 1 ); t += TDateTime( 0, 0, 0, 0 ); TDateTime t2 = localToUTC( t ); CPPUNIT_ASSERT_EQUAL( 3600, ( int ) ( ( double( t - t2 ) + 0.5 / 86400 ) * 86400 ) ); t = TDateTime( 2008, 10, 25 ); t += TDateTime( 0, 0, 0, 0 ); t2 = localToUTC( t ); CPPUNIT_ASSERT_EQUAL( 3600, ( int ) ( ( double( t - t2 ) + 0.5 / 86400 ) * 86400 ) ); t = TDateTime( 2008, 10, 26 ); t += TDateTime( 0, 0, 0, 0 ); t2 = localToUTC( t ); CPPUNIT_ASSERT_EQUAL( 0, ( int ) ( ( double( t - t2 ) + 0.5 / 86400 ) * 86400 ) ); }
/*! * \brief 日付時間をミリ秒に変換 */ int64_t DateTime::toMilliSeconds() const { enum { January = 0, February = January + 31, March = February + 28, April = March + 31, May = April + 30, June = May + 31, July = June + 30, August = July + 31, September = August + 31, October = September + 30, November = October + 31, December = November + 30, }; static const int64_t daySpan[] = { January, February, March, April, May, June, July, August, September, October, November, December, }; int64_t y = getYear(); int64_t m = getMonth(); int64_t d = getDay(); int64_t dy = (y - 1) * 365; // 年数分の日数 int64_t dl = (y / 4) - (y / 100) + (y / 400); // 閏年分の日数 int64_t dm = daySpan[m - 1]; // 1月1日からm月1日までの日数 int64_t result = dy + dl + dm + d - 1; result = (result * 24 * 60 * 60 * 1000) + (getHour() * 60 * 60 * 1000) + (getMinute() * 60 * 1000) + (getSecond() * 1000) + getMilliSecond(); return result; }
// Convert to tm struct tm strToTm(const char *strDate) { struct tm tmDate = { 0 }; int year = 0; char strMonth[4] = {0},strDay[4] = { 0 }; sscanf(strDate, "%3s, %d %3s %d %d:%d:%d %*s", strDay, &(tmDate.tm_mday), strMonth, &year, &(tmDate.tm_hour), &(tmDate.tm_min), &(tmDate.tm_sec)); tmDate.tm_wday = getDay(strDay); tmDate.tm_mon = getMonth(strMonth); tmDate.tm_year = year - 1900; tmDate.tm_isdst = -1; return tmDate; }
/*! * 曜日を取得する */ int32_t DateTime::getWeekDay() const { static int32_t t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; int32_t y = getYear(); int32_t m = getMonth(); int32_t d = getDay(); if (m < 3) y--; return ((y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7); }
const string TimeStamp::getYYYYMMDD_HHMMSS() const { const uint32_t MONTH = getMonth(); const uint32_t DAY = getDay(); const uint32_t HOUR = getHour(); const uint32_t MINUTE = getMinute(); const uint32_t SECOND = getSecond(); stringstream s; s << getYear() << "-" << ( (MONTH < 10) ? "0" : "" ) << MONTH << "-" << ( (DAY < 10) ? "0" : "" ) << DAY << " " << ( (HOUR < 10) ? "0" : "" ) << HOUR << ":" << ( (MINUTE < 10) ? "0" : "" ) << MINUTE << ":" << ( (SECOND < 10) ? "0" : "" ) << SECOND; return s.str(); }
TQString ArkUtils::getTimeStamp(const TQString &_month, const TQString &_day, const TQString &_yearOrTime) { // Make the date format sortable. // Month is in _month, day is in _day. // In _yearOrTime is either a year or a time. // If it's March, we'll see the year for all dates up to October 1999. // (five months' difference - e.g., if it's Apr, then get years up to Nov) char month[4]; strncpy(month, _month.ascii(), 3); month[3] = '\0'; int nMonth = getMonth(month); int nDay = _day.toInt(); kdDebug(1601) << "Month is " << nMonth << ", Day is " << nDay << endl; time_t t = time(0); if (t == -1) exit(1); struct tm *now = localtime(&t); int thisYear = now->tm_year + 1900; int thisMonth = now->tm_mon + 1; TQString year, timestamp; if (_yearOrTime.contains(":")) // it has a timestamp so we have to figure out the year { year.sprintf("%d", ArkUtils::getYear(nMonth, thisYear, thisMonth)); timestamp = _yearOrTime; } else { year = _yearOrTime; if (year.right(1) == " ") year = year.left(4); if (year.left(1) == " ") year = year.right(4); timestamp = "??:??"; } TQString retval; retval.sprintf("%s-%.2d-%.2d %s", year.utf8().data(), nMonth, nDay, timestamp.utf8().data()); return retval; }
int MrgSorter::compareTo ( const DateType &lhObject, // in: Left-hand object const DateType &rhObject // in: Right-hand object ) { int comp; // Check years comp = getYear( lhObject ) - getYear( rhObject ); if( comp != 0 ) { return comp; } // Years same, check months comp = getMonth( lhObject ) - getMonth( rhObject ); if( comp != 0 ) { return comp; } // Years and Months same, check days return getDay( lhObject ) - getDay( rhObject ); }
/** * Set the current date of the picker. * @param date A date struct that specifies a valid date. * @return Any of the following result codes: * - #MAW_RES_OK if the property could be set. * - #MAW_RES_INVALID_PROPERTY_VALUE if the property value was invalid. * - #MAW_RES_ERROR otherwise. */ int DatePicker::setDate(const struct Date date) { //Saving the date, in case of error this will be restored. int year = getYear(); int month = getMonth(); int day = getDayOfMonth(); //Set the day on 1. Used to avoid errors when setting certain dates. int errorCode = setDayOfMonth(1); if(MAW_RES_OK != errorCode) { return errorCode; } else { errorCode = setYear(date.year); if(MAW_RES_OK != errorCode) { //reset the day. setDayOfMonth(day); return errorCode; } else { errorCode = setMonth(date.month); if(MAW_RES_OK != errorCode) { //reset the year and the day. setYear(year); setDayOfMonth(day); return errorCode; } else { errorCode = setDayOfMonth(date.day); if(MAW_RES_OK != errorCode) { //reset year, month and day setYear(year); setMonth(month); setDayOfMonth(day); return errorCode; } } } } return errorCode; }
char* getDate() { char* date = malloc(sizeof(char) * 512); time_t curTime = time(NULL); struct tm t; localtime_r(&curTime, &t); sprintf(date,/* ctime(&curTime));*/ "%s %02d %s %d %02d:%02d:%02d %s", getDayOfWeek(t.tm_wday), t.tm_mday, getMonth(t.tm_mon), t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec, "GMT"); return date; /* char* testdate = malloc(sizeof(char) * 512); sprintf(testdate, "Mon 21 Jan 2008 18:06:16 GMT"); return testdate ;*/ }
void Date::adjustMonth( int aAmount ) throw( DateException ) { int addMonth = aAmount + getMonth(); if( addMonth >= 12 ) { adjustYear( addMonth / 12 ); addMonth = addMonth % 12; } setMonth( addMonth ); } /* end Date::adjustMonth() */
void getSignupDate(Client *pClients, unsigned short pos) { unsigned short day; unsigned short month; unsigned short year; printf(MSG_SIGNUPDATE, NEWLINE); day = getDay(); month = getMonth(); year = getYear(); pClients[pos].birthDay.tm_mday = day; pClients[pos].birthDay.tm_mon = month; pClients[pos].birthDay.tm_year = year; }
void getBirthday(Client *pClients, unsigned short pos) { unsigned short day; unsigned short month; unsigned short year; printf(MSG_BIRTHDAY, NEWLINE); day = getDay(); month = getMonth(); year = getYear(); pClients[pos].birthDay.tm_mday = day; pClients[pos].birthDay.tm_mon = month; pClients[pos].birthDay.tm_year = year; }
ossimRefPtr<ossimXmlNode> ossimLocalTm::saveXml()const { ossimRefPtr<ossimXmlNode> result = new ossimXmlNode; result->setTag("ossimDate"); result->addAttribute("version", "1"); result->addChildNode("month", ossimString::toString(getMonth())); result->addChildNode("day", ossimString::toString(getDay())); result->addChildNode("year", ossimString::toString(getYear())); result->addChildNode("hour", ossimString::toString(getHour())); result->addChildNode("minutes", ossimString::toString(getMin())); result->addChildNode("seconds", ossimString::toString(getSec())); result->addChildNode("fractionalSecond", ossimString::toString(getFractionalSecond())); return result.get(); }
string Date::toString(){ stringstream y; y << getYear(); stringstream m; m << getMonth(); stringstream d; d << getDay(); string output = ""; output += y.str(); output += ':'; output += m.str(); output += ':'; output += d.str(); return output; }
bool Date::isLessThan( const Date& aDate ) const { if( aDate.getYear() > getYear() ) return true; else if( aDate.getMonth() > getMonth() ) return true; else if( aDate.getDay() > getDay() ) return true; else if( aDate.getSecond() > getSecond() ) return true; else return false; } /* end Date::isLessThan() */
/* * Get the timestamp (Unix Epoch) for date, time in * strings, as seen in the log file. */ int getTimestamp(const char *date, const char *time) { int ts; struct tm epoc, current; epoc.tm_hour = 0; epoc.tm_min = 0; epoc.tm_sec = 0; epoc.tm_year = 1970-1900; epoc.tm_mon = 0; epoc.tm_mday = 1; epoc.tm_isdst = -1; // Daylight Saving Time correction: let mktime() guess current.tm_hour = getHour(time); current.tm_min = getMinute(time); current.tm_sec = 0; current.tm_year = getYear(date)-1900; current.tm_mon = getMonth(date)-1; current.tm_mday = getDay(date); current.tm_isdst = -1; ts = difftime(mktime(¤t), mktime(&epoc)); return ts; }
// #1: Sun, 06 Nov 1994 08:49:37 GMT ;RFC 822, updated by RFC 1123 time_t atotime1 ( const char *s ) { // this time structure, once filled, will help yield a time_t struct tm t; // DAY OF WEEK t.tm_wday = getWeekday ( s ); while ( *s && ! isdigit(*s) ) s++; // DAY OF MONTH t.tm_mday = atol ( s ); while ( *s && ! isalpha (*s) ) s++; // MONTH t.tm_mon = getMonth ( s ); while ( *s && ! isdigit (*s) ) s++; // YEAR t.tm_year = atol ( s ) - 1900 ; // # of years since 1900 while ( isdigit (*s) ) s++; while ( isspace (*s) ) s++; // TIME getTime ( s , &t.tm_sec , &t.tm_min , &t.tm_hour ); // unknown if we're in daylight savings time t.tm_isdst = -1; // translate using mktime time_t global = timegm ( &t ); // skip HH:MM:SS while ( *s && ! isspace (*s) ) s++; // no timezone following??? fix core. if ( ! *s ) return global; // skip spaces while ( isspace (*s) ) s++; // convert local time to "utc" or whatever timezone "s" points to, // which is usually gmt or utc int32_t tzoff = getTimeZone ( s ) ; if ( tzoff != BADTIMEZONE ) global += tzoff; return global; // now, convert to utc //time_t utc = time(NULL); // get time here locally //time_t here = localtime(&utc); // what is the diff? //int32_t delta = here - utc; // modify our time to make it into utc //return local - delta; }
/** * @description Funcao responsavel por ler os atributos da struct emprestimo. * @param e Parametro do tipo emprestimo que ira guardar os valores digitados pelo usuario. */ void leituraEmprestimo(TEmprestimo *e) { e->dataSaida.dia = getDay(); e->dataSaida.mes = getMonth(); e->dataSaida.ano = getYear(); int validation = -1; do { printf("Digite a data de entrega do livro: "); scanf("%d/%d/%d", &e->dataEntrega.dia, &e->dataEntrega.mes, &e->dataEntrega.ano); validation = validateDate(e->dataEntrega.dia, e->dataEntrega.mes, e->dataEntrega.ano); if (validation == -1) printf("\nData Invalida! Digite novamente...\n\n"); } while (validation == -1); printf("\nOBS: A data de devolucao sera 99/99/9999 a principio. Quando o livro for devolvido, esta assumira a data de devolucao.\n\n"); e->dataDevolucao.dia = 99; e->dataDevolucao.mes = 99; e->dataDevolucao.ano = 9999; }
void SelectareLunaFereastra::construiesteLunile(QString anul) { m_comboBoxLuna->clear(); int lastMonth = 12; if (anul.toInt() == QDate::currentDate().year()) { lastMonth = QDate::currentDate().month(); } for (int i=1; i <= lastMonth; ++i) { m_comboBoxLuna->addItem(getMonth(i)); } m_comboBoxLuna->setCurrentIndex(m_comboBoxLuna->count()-1); }
int main(){ int d=0, m=0, y=0; int res=0; /* char mydate01[11] = {'0', '3', '/', '1', '1', '/', '2', '0', '0', '8', '\0'}; */ char mydate1[11] = "03/11/2008"; char mydate2[11] = "26/11/2008"; printf("\n"); printf("testing the conversion of a date representation from string to integers (d, m, y): \n"); d = getDay(mydate1); if(d<0){ printf("<main> Error (code %d) in converting the day: %s\n", d, mydate1); return -1; } m = getMonth(mydate1); if(m<0){ printf("<main> Error (code %d) in converting the month: %s\n", m, mydate1); return -1; } y = getYear(mydate1); if(y<0){ printf("<main> Error (code %d) in converting the year: %s\n", y, mydate1); return -1; } printf("%s ==> %d-%d-%d\n", mydate1, d, m, y); printf("\n"); printf("testing dateCompare: \n"); //MY CODE res = dateCompare(mydate1, mydate2); if(res == -9) printf("Error with dates \n"); if(res == -1) printf("%s is before %s \n", mydate1, mydate2); if(res == 1) printf("%s is after %s \n", mydate1, mydate2); if(res == 0) printf("%s is the same as %s \n", mydate1, mydate2); system("PAUSE"); return(1); }
struct direntry mkFCB(uchar type, char *name, int size, uint *clusNum) { char buf[4] = {0xff,0xff,0xff,0xff}; struct direntry de; strncpy((char*)(de.deName), name, 11); // memset(de.deExtension, 0, sizeof(de.deExtension)); de.deAttributes = type; // 文件创建时间和日期 de.deCTime = combineUchar(getHour(), getMinute()); de.deCDate = combineUchar(getMonth(), getDay()); de.deMTime = de.deCTime; de.deMDate = de.deCDate; de.deFileSize = size; *clusNum = cnallloc(); de.deHighClust = (ushort)((*clusNum) >> 16); de.deLowCluster = (ushort)(*clusNum); wsect4bytes(fatFstSec, *clusNum, buf); return de; }
const std::string Date::getMonthAsString() const { switch(getMonth()) { case 1: return std::string(_("January")); case 2: return std::string(_("February")); case 3: return std::string(_("Mars")); case 4: return std::string(_("April")); case 5: return std::string(_("May")); case 6: return std::string(_("June")); case 7: return std::string(_("July")); case 8: return std::string(_("August")); case 9: return std::string(_("September")); case 10: return std::string(_("October")); case 11: return std::string(_("November")); case 12: return std::string(_("December")); } // TODO return std::string("ERROR"); }
nint NDateTime::compareTo(const INObject * other) const { if (this == other) return 0; try { const NDateTime * obj = dynamic_cast<const NDateTime *>(other); if (obj != NULL) { int result = 0; if ((result = getYear() - obj->getYear()) == 0) { if ((result = getMonth() - obj->getMonth()) == 0) { if ((result = getDay() - obj->getDay()) == 0) { if ((result = getHour() - obj->getHour()) == 0) { if ((result = getMinute() - obj->getMinute()) == 0) { if ((result = getSecond() - obj->getSecond()) == 0) { result = getMillisecond() - obj->getMillisecond(); } } } } } } return result; } else { return 1; } } catch (bad_cast &) { return 1; } }
void Store::markTasksDueToday() { log.log("Store: changing due status"); string todayDay = currentDay(); string todayMonth = currentMonth(); string todayYear = currentYear(); for(int i = 0; i < taskList.size(); i++) { if(getDay(i) == todayDay && getMonth(i) == todayMonth && getYear(i) == todayYear) { taskList[i].isBold = true; } else { taskList[i].isBold = false; } } markTasksOverdue(); }
//SET METHODS void Timestamp::setYear(int year) { int month = getMonth(); int newDate = getDate(); //윤달에 29일인데 addYear을 하려는 경우 if ( month == 2 && newDate == 29 //현재가 윤달 29일 && !( year == 4 && !((year % 100 == 0 && year % 400 != 0)) ) //바꿀 연도의 2월은 윤달이 아님 ) newDate = 28; setTimestamp(year, month, newDate, getHour(), getMinute(), getSecond()); };
void loadCurrentReminder(char **rStr) { char str[256]; sprintf(str,"%s%02d%02d%04d.REM",d_reminder,getMonth(),getDay(),getYear()); if(DRAGON_FileExists(str) == FE_FILE) { DRAGON_FILE *fFile = DRAGON_fopen(str, "r"); u32 tLen = DRAGON_flength(fFile); *rStr = (char *)trackMalloc(tLen+5, "tmp reminder"); memset(*rStr, 0, tLen+5); DRAGON_fread(*rStr, 1, tLen, fFile); DRAGON_fclose(fFile); } else { *rStr = (char *)trackMalloc(1, "tmp reminder"); *rStr[0] = 0; } }
uint32_t RTCDue::unixtime () { uint32_t _ticks; uint16_t _days; _hour = getHours (); _minute = getMinutes (); _second = getSeconds (); _day = getDay (); _month = getMonth (); _year = getYear (); //4 digits // Based on https://github.com/punkiller/workspace/blob/master/string2UnixTimeStamp.cpp // days of the years between start of unixtime and now _days = 365 * (_year - 1970); // add days from switch years in between except year from date for( int i = 1970; i < _year; i++ ){ if( switch_years (i) ) { _days++; } } // Based on https://github.com/adafruit/RTClib/blob/master/RTClib.cpp // add switch day from actuall year if necessary for ( int i = 1; i < _month; ++i ) _days += daysInMonth[i - 1]; if ( _month > 2 && switch_years (_year) ) ++_days; _days += _day - 1; _ticks = ((_days * 24 + _hour) * 60 + _minute) * 60 + _second; return _ticks; }
// . #4: 06 Nov 1994 08:49:37 GMT ;RFC 822, updated by RFC 1123 // . like atotime1() time_t atotime4 ( char *s ) { // this time structure, once filled, will help yield a time_t struct tm t; // DAY OF WEEK //t.tm_wday = getWeekday ( s ); //while ( *s && ! isdigit(*s) ) s++; // DAY OF MONTH t.tm_mday = atol ( s ); while ( *s && ! isalpha (*s) ) s++; // MONTH t.tm_mon = getMonth ( s ); while ( *s && ! isdigit (*s) ) s++; // YEAR t.tm_year = atol ( s ) - 1900 ; // # of years since 1900 while ( isdigit (*s) ) s++; while ( isspace (*s) ) s++; // TIME getTime ( s , &t.tm_sec , &t.tm_min , &t.tm_hour ); // unknown if we're in daylight savings time t.tm_isdst = -1; // translate using mktime return mktime ( &t ); }
//implemented for non-leap years void Store::markTasksDueTomorrow() { vector<string> returnedVector = getDateTomorrow(); string tomorrowDay = returnedVector[0]; string tomorrowMonth = returnedVector[1]; string tomorrowYear = returnedVector[2]; for(int i =0; i < taskList.size(); i++) { if(getDay(i) == tomorrowDay && getMonth(i) == tomorrowMonth && getYear(i) == tomorrowYear) { taskList[i].isTomorrow = true; } else taskList[i].isTomorrow = false; } //taskList[1].isTomorrow = true; } //this returns the tasks marked with tomorrow! now check if tomorrow really works!
void Date::setDayName() { string dayName; int yyyy = getYear(); int mm = getMonth(); int dd = getDay(); dd += ((yyyy-1)*365 + (yyyy-1)/4 - (yyyy-1)/100 + (yyyy-1)/400) % 7;//Daycode for prev year 31st Dec switch(mm) { case 12:dd += 334;break; case 11:dd += 304;break; case 10:dd += 273;break; case 9:dd += 243;break; case 8:dd += 212;break; case 7:dd += 181;break; case 6:dd += 151;break; case 5:dd += 120;break; case 4:dd += 90;break; case 3:dd += 59;break; case 2:dd += 31;break; } if ((!(yyyy % 4) && ((yyyy % 100) || !(yyyy % 400)))&& mm > 2) dd++; dd = dd%7; switch(dd) { case 0:dayName = "SUNDAY";break; case 1:dayName = "MONDAY";break; case 2:dayName = "TUESDAY";break; case 3:dayName = "WEDNESDAY";break; case 4:dayName = "THURSDAY";break; case 5:dayName = "FRIDAY";break; case 6:dayName = "SATURDAY";break; } setDayw(getHalfDayName(dayName)); }