void DateTimeTester::subtractMillisecond() { DateTime dt1(QDate(2006, 1, 1), QTime(0, 0, 0, 0 )); DateTime dt2(QDate(2006, 1, 1), QTime(0, 0, 0, 1)); Duration d(0, 0, 0, 0, 1); QVERIFY((dt2-dt1).toString() == d.toString()); QVERIFY((dt1-dt2).toString() == d.toString()); // result always positive QVERIFY((dt2-d) == dt1); dt1 = DateTime(QDate(2006, 1, 1), QTime(0, 0, 0, 1 )); dt2 = DateTime(QDate(2006, 1, 1), QTime(0, 0, 0, 0)); d = Duration(0, 0, 0, 0, 1); QVERIFY((dt2-dt1).toString() == d.toString()); QVERIFY((dt1-dt2).toString() == d.toString()); // result always positive QVERIFY((dt1-d) == dt2); dt1 = DateTime(QDate(2006, 1, 1), QTime(0, 0, 1, 1 )); dt2 = DateTime(QDate(2006, 1, 1), QTime(0, 1, 0, 0)); d = Duration(0, 0, 0, 58, 999); QVERIFY((dt2-dt1).toString() == d.toString()); QVERIFY((dt1-dt2).toString() == d.toString()); // result always positive QVERIFY((dt2-d) == dt1); }
void TsUtility::testTimeUtilsAddYear() { std::string dateTime = "2016-Apr-12 12:59:00.373302BRT+00"; boost::posix_time::ptime boostDate(boost::posix_time::time_from_string(dateTime)); boost::local_time::time_zone_ptr zone(new boost::local_time::posix_time_zone("+00")); boost::local_time::local_date_time date(boostDate.date(), boostDate.time_of_day(), zone, true); std::shared_ptr< te::dt::TimeInstantTZ > dt(new te::dt::TimeInstantTZ(date)); terrama2::core::TimeUtils::addYear(dt, 3); terrama2::core::TimeUtils::addYear(dt, -1); std::string dateTime2 = "2018-Apr-12 12:59:00.373302BRT+00"; boost::posix_time::ptime boostDate2(boost::posix_time::time_from_string(dateTime2)); boost::local_time::time_zone_ptr zone2(new boost::local_time::posix_time_zone("+00")); boost::local_time::local_date_time date2(boostDate2.date(), boostDate2.time_of_day(), zone2, true); std::shared_ptr< te::dt::TimeInstantTZ > dt2(new te::dt::TimeInstantTZ(date2)); if(*dt.get() != *dt2.get()) QFAIL("Should not be here!"); }
void DateTimeTester::addDay() { DateTime dt1(QDate(2006, 1, 1), QTime(8, 0, 0, 0 )); DateTime dt2(QDate(2006, 1, 2), QTime(8, 0, 0, 0)); Duration d(1, 0, 0, 0, 0); QVERIFY((dt1+d) == dt2); }
void DateTimeTester::addMinute() { DateTime dt1(QDate(2006, 1, 1), QTime(0, 0, 0, 0 )); DateTime dt2(QDate(2006, 1, 1), QTime(0, 1, 0, 0)); Duration d(0, 0, 1, 0, 0); QVERIFY((dt1+d) == dt2); }
void dt1() { //printf("\nEnter <dt1>"); if(!strcmp(token,"ASSIGN")) { consume(); dt2(); } //printf("\nExit <dt1>"); }
void DateTimeTester::subtractMinute() { DateTime dt1(QDate(2006, 1, 1), QTime(0, 0, 0, 0 )); DateTime dt2(QDate(2006, 1, 1), QTime(0, 1, 0, 0)); Duration d(0, 0, 1, 0, 0); QVERIFY((dt2-dt1).toString() == d.toString()); QVERIFY((dt1-dt2).toString() == d.toString()); // result always positive QVERIFY((dt2-d).toString() == dt1.toString()); }
void CTCnfStep::CreateConv1L() { _LIT(KEnglishabc,"english_abc"); _LIT(KEnglishdef,"english_def"); _LIT(KFrenchabc,"french_abc"); _LIT(KFrenchdef,"french_def"); TInt ret = 0; CMimeInfo* mime = CMimeInfo::NewLC(mimeWord_Tcnf); mime->AddLanguageL(TLanguageInfo(ELangEnglish,engword_Tcnf)); mime->AddLanguageL(TLanguageInfo(ELangFrench,frword_Tcnf)); CleanupStack::PopAndDestroy(); //mime _LIT(KPath,"z:\\resource\\convert\\10004c41.RSC"); TFileName resourceFile; resourceFile.Copy(KPath); CCnaConvInfoFileReader2* readConverter=CCnaConvInfoFileReader2::NewL(resourceFile); CleanupStack::PushL(readConverter); readConverter->RestoreL(); CCnaConverter* con2 = readConverter->AtL(0); CleanupStack::PushL(con2); TLanguage originalLanguage = User::Language(); TRAP(ret,ChangeLocaleL(ELangEnglish)); TEST(ret == KErrNone); TEST(User::Language() == ELangEnglish); TDataType dt1(_L8("text/abc")); TTranslation trans = con2->MimeFromText(dt1); TEST(trans == KEnglishabc); TDataType dt2(_L8("text/def")); trans = con2->MimeToText(dt2); TEST(trans == KEnglishdef); TRAP(ret,ChangeLocaleL(ELangFrench)); TEST(ret == KErrNone); TEST(User::Language() == ELangFrench); if(User::Language() == ELangFrench) { trans = con2->MimeFromText(dt1); TEST(trans == KFrenchabc); trans = con2->MimeToText(dt2); TEST(trans == KFrenchdef); } TRAP(ret,ChangeLocaleL(originalLanguage)); TEST(ret == KErrNone); CleanupStack::PopAndDestroy(2); //con2 and readConverter }
TEST_F(DateTimeTests,OperatorDateTimeEqualResultTrueTest) { tm stm; stm.tm_sec = 10; stm.tm_min = 47; stm.tm_hour = 9; stm.tm_year = 2017-1900; stm.tm_mon = 7-1; stm.tm_mday = 2; DateTime dt1(stm); DateTime dt2(stm); ASSERT_EQ(dt1 == dt2,true); }
TEST_F(DateTimeTests,OperatorGraterThanTest) { tm stm; stm.tm_sec = 10; stm.tm_min = 47; stm.tm_hour = 9; stm.tm_year = 2017-1900; stm.tm_mon = 7-1; stm.tm_mday = 2; DateTime dt1(stm); stm.tm_min = 48; DateTime dt2(stm); ASSERT_EQ(dt1 < dt2,true); ASSERT_EQ(dt1 > dt2,false); }
TEST_F(DateTimeTests,DateSubtract) { int diffSecondsExpected = 11; tm stm; stm.tm_sec = 10; stm.tm_min = 47; stm.tm_hour = 9; stm.tm_year = 2017-1900; stm.tm_mon = 7-1; stm.tm_mday = 2; DateTime dt1(stm); stm.tm_sec += diffSecondsExpected; DateTime dt2(stm); auto diffSeconds = dt2 - dt1; ASSERT_EQ(diffSecondsExpected,diffSeconds); }
void ScheduleTester::initTestCase() { date = QDate::currentDate(); t1 = QTime( 9, 0, 0 ); t2 = QTime( 12, 0, 0 ); t3 = QTime( 17, 0, 0 ); DateTime dt1(date, t1 ); DateTime dt2( date, t3 ); resourceSchedule.addAppointment( &nodeSchedule, dt1, dt2, 100. ); dt1 = DateTime( date.addDays(1), t1 ); dt2 = DateTime( date.addDays(1), t2 ); resourceSchedule.addAppointment( &nodeSchedule, dt1, dt2, 100. ); dt1 = DateTime( date.addDays(1), t2 ); dt2 = DateTime( date.addDays(1), t3 ); resourceSchedule.addAppointment( &nodeSchedule, dt1, dt2, 100. ); dt1 = DateTime( date.addDays(2), t1 ); dt2 = DateTime( date.addDays(2), t3 ); resourceSchedule.addAppointment( &nodeSchedule, dt1, dt2, 100. ); }
void testMyDateTimeStore() { __int64 tmp; fielddefs* fds = fielddefs::create(); fielddef f; memset(&f, 0, sizeof(fielddef)); f.len = 8; f.pos = 0; //timestamp f.type = ft_mytimestamp; f.decimals = 6; field fd((unsigned char* )&tmp, f, fds); myTimeStamp dt(f.decimals, true); dt = "2010-10-10 00:00:00.123456"; fd = dt.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt.i64, "ft_mytimestamp7 value = " << fd.i64()); //Legacy format myTimeStamp dtl(f.decimals, false); dtl = "2010-10-10 00:00:00"; fd = dtl.i64; BOOST_CHECK_MESSAGE(fd.i64() == dtl.i64, "ft_mytimestamp legacy value = " << fd.i64()); f.decimals = 4; f.len = 7; myTimeStamp dt2(f.decimals, true); dt2 = "2010-10-10 00:00:12.9988"; fd = dt2.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt2.i64, "ft_mytimestamp6 value = " << fd.i64()); f.decimals = 2; f.len = 6; myTimeStamp dt3(f.decimals, true); dt3 = "2010-10-10 00:00:12.23"; fd = dt3.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt3.i64, "ft_mytimestamp5 value = " << fd.i64()); f.decimals = 0; f.len = 5; myTimeStamp dt4(f.decimals, true); dt4 = "2010-10-10 00:00:12"; fd = dt4.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt4.i64, "ft_mytimestamp4 value = " << fd.i64()); //datetime f.decimals = 6; f.len = 8; f.type = ft_mydatetime; myDateTime dt5(f.decimals, true); dt5 = "2015-10-10 00:00:12.445566"; fd = dt5.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt5.i64, "ft_mydatetime8 value = " << fd.i64()); //Legacy format myDateTime dt5l(f.decimals, true); dt5l = "2015-10-10 00:00:12"; fd = dt5l.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt5l.i64, "ft_mydatetime Legacy value = " << fd.i64()); f.decimals = 4; f.len = 7; myDateTime dt6(f.decimals, true); dt6 = "2015-10-10 00:00:12.7788"; fd = dt6.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt6.i64, "ft_mydatetime7 value = " << fd.i64()); f.decimals = 2; f.len = 6; myDateTime dt7(f.decimals, true); dt7 = "2015-10-10 00:00:12.00"; fd = dt7.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt7.i64, "ft_mydatetime6 value = " << fd.i64()); f.decimals = 0; f.len = 5; myDateTime dt71(f.decimals, true); dt71 = "2015-10-10 00:00:12"; fd = dt71.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt71.i64, "ft_mydatetime5 value = " << fd.i64()); //mariadb datetime f.setOptions(FIELD_OPTION_MARIADB); f.decimals = 6; f.len = 8; f.type = ft_mydatetime; maDateTime dta(f.decimals, true); dta = "2015-10-10 00:00:12.445566"; fd = dta.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta.i64, "ft_mydatetime8 maridb value = " << fd.i64()); f.decimals = 4; f.len = 7; maDateTime dta1(f.decimals, true); dta1 = "2015-10-10 00:00:12.7788"; fd = dta1.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta1.i64, "ft_mydatetime7 maridb value = " << fd.i64()); f.decimals = 2; f.len = 6; maDateTime dta2(f.decimals, true); dta2 = "2015-10-10 00:00:12.00"; fd = dta2.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta2.i64, "ft_mydatetime6 maridb value = " << fd.i64()); f.decimals = 0; f.len = 5; maDateTime dta20(f.decimals, true); dta20 = "2015-10-10 00:00:12"; fd = dta20.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta20.i64, "ft_mydatetime6 maridb value = " << fd.i64()); // mariadb time f.decimals = 6; f.len = 6; f.type = ft_mytime; maTime dtma1(f.decimals, true); dtma1 = "00:00:12.123456"; fd = dtma1.i64; BOOST_CHECK_MESSAGE(fd.i64() == dtma1.i64, "ft_mytime6 maridb value = " << fd.i64()); f.decimals = 4; f.len = 5; maTime dtma2(f.decimals, true); dtma2 = "00:00:12.1234"; fd = dtma2.i64; BOOST_CHECK_MESSAGE(fd.i64() == dtma2.i64, "ft_mytime5 maridb value = " << fd.i64()); f.decimals = 2; f.len = 4; maTime dta3(f.decimals, true); dta3 = "00:00:12.12"; fd = dta3.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta3.i64, "ft_mytime4 maridb value = " << fd.i64()); f.decimals = 0; f.len = 3; maTime dta4(f.decimals, true); dta4 = "00:00:12"; fd = dta4.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta4.i64, "ft_mytime3 maridb value = " << fd.i64()); maTime dta5(f.decimals, false); dta5 = "00:00:12"; fd = dta5.i64; BOOST_CHECK_MESSAGE(fd.i64() == dta5.i64, "ft_mytime Legacy maridb value = " << fd.i64()); // MySQl time f.setOptions(0); f.decimals = 6; f.len = 6; f.type = ft_mytime; myTime dt10(f.decimals, true); dt10 = "00:00:12.123456"; fd = dt10.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt10.i64, "ft_mytime6 value = " << fd.i64()); f.decimals = 4; f.len = 5; myTime dt11(f.decimals, true); dt11 = "00:00:12.1234"; fd = dt11.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt11.i64, "ft_mytime5 value = " << fd.i64()); f.decimals = 2; f.len = 4; myTime dt12(f.decimals, true); dt12 = "00:00:12.12"; fd = dt12.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt12.i64, "ft_mytime4 value = " << fd.i64()); f.decimals = 0; f.len = 3; myTime dt13(f.decimals, true); dt13 = "00:00:12"; fd = dt13.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt13.i64, "ft_mytime3 value = " << fd.i64()); myTime dt13l(f.decimals, false); dt13l = "00:00:12"; fd = dt13l.i64; BOOST_CHECK_MESSAGE(fd.i64() == dt13l.i64, "ft_mytime Legacy value = " << fd.i64()); //print f.type = ft_mydatetime; f.decimals = 6; f.len = 8; fd = _T("2015-10-01 20:50:36.002000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.002000")) , "ft_mydatetime string8 = " << fd.c_str()); f.decimals = 4; f.len = 7; fd = _T("2015-10-01 20:50:36.002000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.0020")) , "ft_mydatetime string7 = " << fd.c_str()); f.decimals = 2; f.len = 6; fd = _T("2015-10-01 20:50:36.052000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.05")) , "ft_mydatetime string6 = " << fd.c_str()); f.decimals = 0; f.len = 5; fd = _T("2015-10-01 20:50:36.002000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36")) , "ft_mydatetime string5 = " << fd.c_str()); f.type = ft_mytimestamp; f.decimals = 6; f.len = 7; fd = _T("2015-10-01 20:50:36.052001"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.052001")) , "ft_mytimestamp string7 = " << fd.c_str()); f.decimals = 4; f.len = 6; fd = _T("2015-10-01 20:50:36.052001"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.0520")) , "ft_mytimestamp string6 = " << fd.c_str()); f.decimals = 2; f.len = 5; fd = _T("2015-10-01 20:50:36.052000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36.05")) , "ft_mytimestamp string5 = " << fd.c_str()); f.decimals = 0; f.len = 4; fd = _T("2015-10-01 20:50:36.952000"); BOOST_CHECK_MESSAGE(fd.c_str() == _tstring(_T("2015-10-01 20:50:36")) , "ft_mytimestamp string4 = " << fd.c_str()); fds->release(); }
bool KQuestCommon::IsSameDay(time_t t1, time_t t2) { KDatetime dt1(t1); KDatetime dt2(t2); return dt1.ToLocalDays() == dt2.ToLocalDays(); }
void Testdata(ostream &fo) { Date now; string p[]= { "--","d--","dd--","-m-", "d-m-","dd-m-","-mm-","d-mm-", "dd-mm-","-mmm-","d-mmm-","dd-mmm-", "--yy","d--yy","dd--yy","-m-yy", "d-m-yy","dd-m-yy","-mm-yy","d-mm-yy", "dd-mm-yy","-mmm-yy","d-mmm-yy","dd-mmm-yy", "--yyyy","d--yyyy","dd--yyyy","-m-yyyy", "d-m-yyyy","dd-m-yyyy","-mm-yyyy","d-mm-yyyy", "dd-mm-yyyy","-mmm-yyyy","d-mmm-yyyy","dd-mmm-yyyy" }; //printing all the date formats fo<<"********************************************************************************"<<endl; fo<<"Printing all types formats"<<endl; DateFormat *format[36]; for(int k=0; k<36; k++) { format[k]=checkformat1(fo,p[k]); fo<<"\n"; } fo<<"********************************************************************************"<<endl; fo<<"Printing all types formats if given input in different format"<<endl; for(int k=0; k<36; k++) { int d=p[k].find_first_of("-",0); int y=p[k].find_first_of("-",d+1); string a,b,c; a=p[k].substr(0,d); b=p[k].substr(d+1,y-d-1); c=p[k].substr(y+1); checkformat2(fo,a,b,c); } fo<<"********************************************************************************"<<endl; checkdate1(fo); fo<<"********************************************************************************"<<endl; checkdate2(fo); fo<<"********************************************************************************"<<endl; Date now2(now); fo<<"Testing ++,++(int) operators"<<endl; fo<<++now<<"\n"<<endl; fo<<now++<<"\n"<<endl; fo<<"********************************************************************************"<<endl; fo<<"Testing --,--(int) operators"<<endl; fo<<--now<<"\n"<<endl; fo<<now--<<"\n"<<endl; Date datevar1("10-03-2019"); fo<<"********************************************************************************"<<endl; fo<<"Testing + operator"<<endl; Date datevar2(D09,Mar,2016); fo<<datevar2+1<<"--> ITS MY BIRTHDAY!!!"<<endl; fo<<"Wish me at https://www.facebook.com/sricharan6996 "<<"\n"<<endl; try { fo<<datevar2+100000<<"\n"<<endl; } catch(exception &e) { fo<<e.what()<<"\n"<<endl; } fo<<"********************************************************************************"<<endl; fo<<"Testing operator(-) "<<endl; Date dt1 (D15,Mar,2020),dt2(D30,Sep,2025); fo<<dt2-dt1<<"\n"<<endl; fo<<"********************************************************************************"<<endl; fo<<"Testing Weekday operators"<<endl; fo<<(WeekDay)dt2<<"\n"<<endl; fo<<(WeekDay)(dt2+1)<<"\n"<<endl; fo<<"********************************************************************************"<<endl; fo<<"Testing weeknumber operators"<<endl; fo<<(WeekNumber)dt2<<"\n"<<endl; fo<<(WeekNumber)(dt2+1)<<"\n" <<endl; fo<<"********************************************************************************"<<endl; fo<<"Testing month operators"<<endl; fo<<(Month)now<<"\n"<<endl; fo<<(Month)(now+365)<<"\n"<<endl; fo<<now.leapYear()<<"\n"<<endl; fo<<datevar2.leapYear()<<"\n"<<endl; fo<<"********************************************************************************"<<endl; fo<<"Testing == ,!=,<=,<,>=,> operators"<<endl; fo<<(datevar1==datevar2)<<"\n"<<endl; fo<<(datevar1!=datevar2)<<"\n"<<endl; fo<<(datevar1<=datevar2)<<"\n"<<endl; fo<<(datevar1<datevar2)<<"\n"<<endl; fo<<(datevar1>=datevar2)<<"\n"<<endl; fo<<(datevar1>datevar2)<<"\n"<<endl; fo<<"********************************************************************************"<<endl; fo<<"Testing set and get formats"<<endl; for(int k=0; k<36; k++) { Date::setFormat(*format[k]); fo<<Date::getFormat().getdate()<<"\n"<<endl; fo<<Date::getFormat().getmonth()<<"\n"<<endl; fo<<Date::getFormat().getyear()<<"\n"<<endl; } fo<<"********************************************************************************"<<endl; fo<<"Testing assignment operator"<<endl; datevar2=now; fo<<datevar2<<"\n"<<endl; fo<<"********************************************************************************"<<endl; fo<<"Testing operators"<<endl; for(int k=0; k<36; k++) { fo<<p[k]; Date::setFormat(*format[k]); fo<<now<<"\n"<<endl; } delete [] format; }
void create_point_test() { // create point with specified parameterization { piecewise_curve_type pc; point_creator_type pt_creator(4); data_type dt0(3), dt1(2), dt2(3), dt3(2), t0(-1), dt; point_type p0, ptemp; // set the point p0 << 1, 2, 3; pt_creator.set_point(p0); // set the times pt_creator.set_t0(t0); pt_creator.set_segment_dt(dt0, 0); pt_creator.set_segment_dt(dt1, 1); pt_creator.set_segment_dt(dt2, 2); pt_creator.set_segment_dt(dt3, 3); // test point setting ptemp=pt_creator.get_point(); TEST_ASSERT(p0==ptemp); // test time step settings TEST_ASSERT(pt_creator.get_t0()==t0); dt=pt_creator.get_segment_dt(0); TEST_ASSERT(dt==dt0); dt=pt_creator.get_segment_dt(1); TEST_ASSERT(dt==dt1); dt=pt_creator.get_segment_dt(2); TEST_ASSERT(dt==dt2); dt=pt_creator.get_segment_dt(3); TEST_ASSERT(dt==dt3); // create the polygon TEST_ASSERT(pt_creator.create(pc)); } // create point with default parameterization { piecewise_curve_type pc; point_creator_type pt_creator(4); data_type dt; point_type p0, ptemp; // set the corners p0 << 1, 0, 0; pt_creator.set_point(p0); // test corner settings ptemp=pt_creator.get_point(); TEST_ASSERT(p0==ptemp); // test time step settings TEST_ASSERT(pt_creator.get_t0()==0); dt=pt_creator.get_segment_dt(0); TEST_ASSERT(dt==1); dt=pt_creator.get_segment_dt(1); TEST_ASSERT(dt==1); dt=pt_creator.get_segment_dt(2); TEST_ASSERT(dt==1); dt=pt_creator.get_segment_dt(3); TEST_ASSERT(dt==1); // create the polygon TEST_ASSERT(pt_creator.create(pc)); } }