void TestCase4_OperatorLessthanOrEqualOverload(void) { #if !defined (OPERATOR_OVERLOAD_OUTSIDE_CLASS) Date date1(1941, 12, 7), date2(1990, 1, 22), date3(1941, 12, 7); if (date1 < date2) { date1.display(); std::cout<<" is less than "; date2.display(); } std::cout<<"\n"<<std::endl; if (date1 == date3) { date1.display(); std::cout<<" is equal to "; date3.display(); } std::cout<<"\n"<<std::endl; if (date1 <= date3) { date1.display(); std::cout<<"is less than or equal to "; date3.display(); } return; #endif /* OPERATOR_OVERLOAD_OUTSIDE_CLASS */ }
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 date_test_object_t::test<5>() { LLDate date1(VALID_DATE); LLDate date2(date1.secondsSinceEpoch()); ensure_equals("secondsSinceEpoch not equal",date1.secondsSinceEpoch(), date2.secondsSinceEpoch()); ensure_equals("LLDate created using secondsSinceEpoch not equal", date1.asString(), date2.asString()); }
//查询两个日期之间的支出 QVector<QString> WQuery::queryBetweenTwoDatesExpense(QDate dateFrom, QDate dateTo){ //将时间转化为字符串 QDateTime date1(dateFrom),date2(dateTo.addDays(1)); QString date3 = date1.toString("yyyy-MM-dd hh:mm:ss"); QString date4 = date2.toString("yyyy-MM-dd hh:mm:ss"); //从数据库获取信息 DBTransactionRecordManip transferManip; DBPaymentRecordManip paymentManip; QString selectInfo1,selectInfo2; selectInfo1 = QString("SELECT sum,time,type FROM transactionRecord WHERE accountKey1 = %1 AND time > datetime('%2') AND time < datetime('%3')") .arg(DBAccountManip::dbSelectAccountKey(number)).arg(date3).arg(date4); selectInfo2 = QString("SELECT sum,time,type FROM paymentRecord WHERE accountKey = %1 AND time > datetime('%2') AND time < datetime('%3')") .arg(DBAccountManip::dbSelectAccountKey(number)).arg(date3).arg(date4); QVector<QString> transactionRecord; QVector<QString> paymentRecord; transactionRecord = transferManip.dbSelect(selectInfo1,3); paymentRecord = paymentManip.dbSelect(selectInfo2,3); //创建返回的QVector int size1 = transactionRecord.size()/3; int size2 = paymentRecord.size()/3; QVector<QString> expenseBetweenTwoDates; for(int i = 0;i<size1*3;i++) expenseBetweenTwoDates.push_back(transactionRecord[i]); for(int i = 0;i<size2*3;i++) expenseBetweenTwoDates.push_back(paymentRecord[i]); //创建对应的QDatetime int rows = size1 + size2; QDateTime times[rows]; for(int i = 0;i<rows;i++) times[i] = QDateTime::fromString(expenseBetweenTwoDates[3*i + 1],"yyyy-MM-dd hh:mm:ss"); //比较,冒泡排序 for(int i = 0;i<rows -1;i++) for(int j = 0;j<rows -1;j++){ if(times[j]<times[j + 1]){ QDateTime temp; temp = times[j]; times[j] = times[j + 1]; times[j + 1] = temp; QString temps[3]; temps[0] = expenseBetweenTwoDates[3*j]; temps[1] = expenseBetweenTwoDates[3*j + 1]; temps[2] = expenseBetweenTwoDates[3*j + 2]; expenseBetweenTwoDates[3*j] = expenseBetweenTwoDates[3*(j+1)]; expenseBetweenTwoDates[3*j + 1] = expenseBetweenTwoDates[3*(j+1) + 1]; expenseBetweenTwoDates[3*j + 2] = expenseBetweenTwoDates[3*(j+1) + 2]; expenseBetweenTwoDates[3*(j+1)] = temps[0]; expenseBetweenTwoDates[3*(j+1) + 1] = temps[1]; expenseBetweenTwoDates[3*(j+1) + 2] = temps[2]; } } return expenseBetweenTwoDates; }
TEST(MeetingTest, getEndDate) { Date date1(2014, 7, 1, 22, 11); Date date2(2014, 5, 3, 1, 1); Meeting meeting("ly", "lyly", date1, date2, "tt"); meeting.setSponsor("tq"); EXPECT_TRUE(meeting.getSponsor() == "tq"); meeting.setParticipator("233"); EXPECT_TRUE("233" == meeting.getParticipator()); EXPECT_TRUE(meeting.getStartDate() == date1); EXPECT_TRUE(meeting.getEndDate() == date2); }
void main() { FCPartitionDesc dbl("dbl","dbl"); FCPartitionDesc lng("lng","lng"); FCPartitionDesc charp("charp","charp"); FCPartitionDesc date("date","date"); FCPartitionDesc dblx("dblx","dblx"); FCPartitionDesc lngx("lngx","lngx"); FCPartitionDesc charpx("charpx","charpx"); FCPartitionDesc datex("datex","datex"); PDFriend::MakeADouble(dbl); PDFriend::MakeACharPtr(charp); PDFriend::MakeALong(lng); PDFriend::MakeAColDate(date); // test copy constructor.. FCPartitionDesc dbl2(dbl); FCPartitionDesc lng2(lng); FCPartitionDesc charp2(charp); FCPartitionDesc date2(date); dblx = dbl; lngx = lng; charpx = charp; datex = date; cout << "dbl----" << endl << dbl ; cout << "lng----" << endl << lng ; cout << "charp--" << endl << charp ; cout << "date---" << endl << date << endl; cout << "dbl2----" << endl << dbl2 ; cout << "lng2----" << endl << lng2 ; cout << "charp2--" << endl << charp2 ; cout << "date2---" << endl << date2 << endl; cout << "dblx----" << endl << dblx ; cout << "lngx----" << endl << lngx ; cout << "charpx--" << endl << charpx ; cout << "date2x--" << endl << datex << endl; cout << dbl.GetDouble() << endl; cout << charp.GetCharPtr() << endl; cout << lng.GetLong() << endl; cout << date.GetColDate().nMonth << "/" << date.GetColDate().nDay << "/" << date.GetColDate().nYear << endl; }
//查询两个日期间的收入 QVector<QString> WQuery::queryBetweenTwoDatesIncome(QDate dateFrom, QDate dateTo){ //将时间转化为字符串 QDateTime date1(dateFrom),date2(dateTo.addDays(1)); QString date3 = date1.toString("yyyy-MM-dd hh:mm:ss"); QString date4 = date2.toString("yyyy-MM-dd hh:mm:ss"); //从数据库获取信息 DBTransactionRecordManip transferManip; QString selectInfo; selectInfo = QString("SELECT sum,time,type FROM transactionRecord WHERE accountKey2 = %1 AND time > datetime('%2') AND time < datetime('%3')") .arg(DBAccountManip::dbSelectAccountKey(number)).arg(date3).arg(date4); QVector<QString> infoBetweenTwoDays; infoBetweenTwoDays = transferManip.dbSelect(selectInfo,3); for(int i = 0;i<infoBetweenTwoDays.size()/3;i++) if(infoBetweenTwoDays[3*i + 2] == "transfer to other") infoBetweenTwoDays[3*i + 2] = "be transfered into"; //构造相应的datetime对象 int rows = infoBetweenTwoDays.size()/3; QDateTime times[rows]; for(int i = 0;i<rows;i++) times[i] = QDateTime::fromString(infoBetweenTwoDays[3*i + 1],"yyyy-MM-dd hh:mm:ss"); //比较,冒泡排序 for(int i = 0;i<rows -1;i++) for(int j = 0;j<rows -1;j++){ if(times[j]<times[j + 1]){ QDateTime temp; temp = times[j]; times[j] = times[j + 1]; times[j + 1] = temp; QString temps[3]; temps[0] = infoBetweenTwoDays[3*j]; temps[1] = infoBetweenTwoDays[3*j + 1]; temps[2] = infoBetweenTwoDays[3*j + 2]; infoBetweenTwoDays[3*j] = infoBetweenTwoDays[3*(j+1)]; infoBetweenTwoDays[3*j + 1] = infoBetweenTwoDays[3*(j+1) + 1]; infoBetweenTwoDays[3*j + 2] = infoBetweenTwoDays[3*(j+1) + 2]; infoBetweenTwoDays[3*(j+1)] = temps[0]; infoBetweenTwoDays[3*(j+1) + 1] = temps[1]; infoBetweenTwoDays[3*(j+1) + 2] = temps[2]; } } return infoBetweenTwoDays; }
void HandlerFile::download(string fileName) { Date* date1 = Date::newInstance(); Date date2(prop->getValue("up_date"), Date::DB_FORMAT); long dif = (*date1 - date2); dif = dif / 86400; if (fileExists(fileName.c_str())) { if (dif == 0) return; } CURL *curl; CURLcode res; curl = curl_easy_init(); if (!curl) return; //set_proxy_settings(curl);//my function //read settings file //////////////////////////////////// string rest = prop->getValue("rest_query1")+to_string(dif)+prop->getValue("rest_query2"); //////////////////////////////////// //SSL Options //curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER , 1); //curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST , 1); //Provide CA Certs from http://curl.haxx.se/docs/caextract.html */ //curl_easy_setopt(curl, CURLOPT_CAINFO, "G:/LaSpaceProg/SPACETRACK(LIBCURL)/Debug/ca-bundle.crt"); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE); // Set up a couple initial paramaters that we will not need to mofiy later. curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0"); curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie"); // Visit the login page curl_easy_setopt(curl, CURLOPT_URL, "https://www.space-track.org/ajaxauth/login"); char data[192]; strcpy(data, "identity="); strcat(data, prop->getValue("user").c_str()); strcat(data, "&password="******"password").c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); printf("login: "******": %s\n", curl_easy_strerror(res)); curl_easy_setopt(curl, CURLOPT_HEADER, 0L); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); FILE *data_file = fopen(fileName.c_str(), "wb");//fopen(files[i].c_str(), "wb"); curl_easy_setopt(curl, CURLOPT_URL,rest.c_str()); //cout << "Rest is = " << rest.c_str() << endl; curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_func); curl_easy_setopt(curl, CURLOPT_WRITEDATA, data_file); res = curl_easy_perform(curl); //if (res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); //else printf("rest query %2i: %s\n", i, curl_easy_strerror(res)); fclose(data_file); curl_easy_cleanup(curl); //Always cleanup //printf("End. Press any key...\n"); //getchar(); changeDate(*date1, file); };
void date_test_object_t::test<4>() { LLDate date1(VALID_DATE); LLDate date2(date1); ensure_equals("LLDate(const LLDate& date) constructor failed", date1.asString(), date2.asString()); }
void RelativeDateUnitTest::test_lifecycle_valid() { //test: RelativeDateUnit::RelativeDateUnit(); /**< Defaults to 1D*/ RelativeDateUnit date1; CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Day, date1.getUnit()); CPPUNIT_ASSERT_EQUAL(0, date1.getQuantity()); //test: RelativeDateUnit::RelativeDateUnit(const RelativeDate& other); RelativeDateUnit date2(date1); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Day, date2.getUnit()); CPPUNIT_ASSERT_EQUAL(0, date2.getQuantity()); //test: RelativeDateUnit::RelativeDateUnit(const String& stringRep); RelativeDateUnit date3("1Y"); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Year, date3.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date3.getQuantity()); RelativeDateUnit date4("1y"); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Year, date4.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date4.getQuantity()); RelativeDateUnit date5("1M"); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Month, date5.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date3.getQuantity()); RelativeDateUnit date6("1m"); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Month, date6.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date4.getQuantity()); RelativeDateUnit date7("1W"); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Week, date7.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date7.getQuantity()); RelativeDateUnit date8("1w"); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Week, date8.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date8.getQuantity()); RelativeDateUnit date9("1D"); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Day, date9.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date7.getQuantity()); RelativeDateUnit date10("1d"); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Day, date10.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date8.getQuantity()); //test: RelativeDateUnit::RelativeDateUnit(Integer quantity, RelativeDateUnit::eRelativeDateUnit unit); RelativeDateUnit date11(1, RelativeDateUnitType::Year); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Year, date11.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date11.getQuantity()); RelativeDateUnit date12(1, RelativeDateUnitType::Month); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Month, date12.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date12.getQuantity()); RelativeDateUnit date13(1, RelativeDateUnitType::Week); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Week, date13.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date13.getQuantity()); RelativeDateUnit date14(1, RelativeDateUnitType::Day); CPPUNIT_ASSERT_EQUAL(RelativeDateUnitType::Day, date14.getUnit()); CPPUNIT_ASSERT_EQUAL(1, date14.getQuantity()); }
void DateTimeTextMatchPlugin::doGetPossibleMatches( const QString& text ) { // // check for years (numbers between 1900 and 2020 for example) // check for stuff like "June 22" or even "June 22-26th" (the latter can be used as start and end time already) // check for "2 o'clock" // check for "14:23" // check for 12.6.2009 and 6/12/2009 and 6/12/09 and 6.12.09 // m_years.clear(); m_dates.clear(); m_times.clear(); m_dateRanges.clear(); m_text = text; // we are english-only here! QStringList longMonthNames; QStringList shortMonthNames; for ( int i = 1; i <= 12; ++i ) { longMonthNames << m_enLocale.monthName( i, QLocale::LongFormat ); shortMonthNames << m_enLocale.monthName( i, QLocale::ShortFormat ); } // // most of the dates and times can be checked with QRegExp // // DD.MM.YYYY QRegExp date1( "\\b\\d{1,2}\\.\\d{1,2}\\.\\d{4,4}\\b" ); // DD.MM.YY QRegExp date2( "\\b\\d{1,2}\\.\\d{1,2}\\.\\d{2,2}\\b" ); // MM/DD/YYYY QRegExp date3( "\\b\\d{1,2}/\\d{1,2}/\\d{4,4}\\b" ); // MM/DD/YY QRegExp date4( "\\b\\d{1,2}/\\d{1,2}/\\d{2,2}\\b" ); // January MM [YYYY] (no word boundry at the end for 'st' or 'nd' or 'th') (also excluding ranges) QRegExp date5( QString( "\\b(%1)\\s\\d{1,2}(?!(\\d|\\s?-\\s?\\d))(\\s\\d{4,4})?" ).arg( longMonthNames.join( "|" ) ) ); // January, MM [YYYY] (no word boundry at the end for 'st' or 'nd' or 'th') (also excluding ranges) QRegExp date6( QString( "\\b(%1),\\s?\\d{1,2}(?!(\\d|\\s?-\\s?\\d))(\\s\\d{4,4})?" ).arg( longMonthNames.join( "|" ) ) ); // FIXME: date ranges 1-4 QRegExp dateRange5( QString( "(\\b(?:%1)\\s\\d{1,2})\\s?-\\s?(\\d{1,2})(\\s\\d{4,4})?" ).arg( longMonthNames.join( "|" ) ) ); QRegExp dateRange6( QString( "(\\b(?:%1),\\s?\\d{1,2})\\s?-\\s?(\\d{1,2})(\\s\\d{4,4})?" ).arg( longMonthNames.join( "|" ) ) ); // YYYY (exclude those in full dates matched by the above) QRegExp year( "[^\\./]\\d{4,4}\\b" ); // hh:mm[pm|am] QRegExp time1( "\\b\\d{1,2}\\:\\d{2,2}\\s?(pm|am|AM|PM)?\\b" ); // hh:mm QRegExp time2( "\\b\\d{1,2}\\:\\d{2,2}\\b(?!\\s?(pm|am|AM|PM))\\b" ); // hh o'clock // QRegExp time3( "\\b\\d{1,2}\\so'clock\\b" ); lookForYears( year ); lookForDates( date1, "d.M.yyyy" ); lookForDates( date2, "d.M.yy" ); lookForDates( date3, "M/d/yyyy" ); lookForDates( date4, "M/d/yy" ); lookForDates( date5, "MMMM d", true ); lookForDates( date5, "MMMM d yyyy" ); lookForDates( date6, "MMMM, d", true ); lookForDates( date6, "MMMM,d", true ); lookForDates( date6, "MMMM, d yyyy" ); lookForDates( date6, "MMMM,d yyyy" ); lookForDateRanges( dateRange5, "MMMM d", 1, 2, 3, true ); lookForDateRanges( dateRange5, "MMMM d yyyy", 1, 2, 3, false ); lookForDateRanges( dateRange6, "MMMM,d", 1, 2, 3, true ); lookForDateRanges( dateRange6, "MMMM, d", 1, 2, 3, true ); lookForDateRanges( dateRange6, "MMMM,d yyyy", 1, 2, 3, false ); lookForDateRanges( dateRange6, "MMMM, d yyyy", 1, 2, 3, false ); lookForTimes( time1, "h:map" ); lookForTimes( time1, "h:m ap" ); lookForTimes( time2, "h:m" ); // FIXME: do a date and time proximity search to create combined datetime objects // // Now use the dates and times to create statements // for ( QHash<int, QPair<QDate, int> >::const_iterator it = m_dates.constBegin(); it != m_dates.constEnd(); ++it ) { // FIXME: this is not great: 1. dtstart has range dateTime, 2. we do not know that it is a start // better use something else or even create Scribo::Literal as alternative to Entity Scribo::Statement s( Nepomuk::Vocabulary::PIMO::dtstart(), Nepomuk::Variant( it.value().first ), Soprano::Graph() ); Scribo::TextOccurrence oc; oc.setStartPos( it.key() ); oc.setLength( it.value().second ); // oc.setRelevance( 0.9 ); ????????? s.addOccurrence( oc ); addNewMatch( s ); } for ( QHash<int, QPair<QTime, int> >::const_iterator it = m_times.constBegin(); it != m_times.constEnd(); ++it ) { // FIXME: this is not great: 1. dtstart has range dateTime, 2. we do not know that it is a start // better use something else or even create Scribo::Literal as alternative to Entity Scribo::Statement s( Nepomuk::Vocabulary::PIMO::dtstart(), Nepomuk::Variant( it.value().first ), Soprano::Graph() ); Scribo::TextOccurrence oc; oc.setStartPos( it.key() ); oc.setLength( it.value().second ); // oc.setRelevance( 0.9 ); ????????? s.addOccurrence( oc ); addNewMatch( s ); } for ( QHash<int, QPair<QPair<QDate, QDate>, int> >::const_iterator it = m_dateRanges.constBegin(); it != m_dateRanges.constEnd(); ++it ) { // FIXME: this is not great: 1. dtstart has range dateTime, 2. we do not know that it is a start // better use something else or even create Scribo::Literal as alternative to Entity Scribo::Statement s1( Nepomuk::Vocabulary::PIMO::dtstart(), Nepomuk::Variant( it.value().first.first ), Soprano::Graph() ); Scribo::TextOccurrence oc1; oc1.setStartPos( it.key() ); oc1.setLength( it.value().second ); // oc.setRelevance( 0.9 ); ????????? s1.addOccurrence( oc1 ); addNewMatch( s1 ); Scribo::Statement s2( Nepomuk::Vocabulary::PIMO::dtend(), Nepomuk::Variant( it.value().first.second ), Soprano::Graph() ); Scribo::TextOccurrence oc2; oc2.setStartPos( it.key() ); oc2.setLength( it.value().second ); // oc.setRelevance( 0.9 ); ????????? s2.addOccurrence( oc2 ); addNewMatch( s2 ); } emitFinished(); }
//查询某两个日期之间的交易和付款记录 QVector<QString> WQuery::queryBetweenTwoDates(QDate dateFrom, QDate dateTo){ //将时间转化为字符串 QDateTime date1(dateFrom),date2(dateTo.addDays(1)); QString date3 = date1.toString("yyyy-MM-dd hh:mm:ss"); QString date4 = date2.toString("yyyy-MM-dd hh:mm:ss"); //从数据库获取信息 DBTransactionRecordManip transferManip; DBPaymentRecordManip paymentManip; QString selectInfo1,selectInfo2,selectInfo3; selectInfo1 = QString("SELECT sum,time,type FROM transactionRecord WHERE accountKey1 = %1 AND time > datetime('%2') AND time < datetime('%3')") .arg(DBAccountManip::dbSelectAccountKey(number)).arg(date3).arg(date4); selectInfo2 = QString("SELECT sum,time,type FROM transactionRecord WHERE accountKey1 != %1 AND accountKey2 = %1 AND time > datetime('%2') AND time < datetime('%3')") .arg(DBAccountManip::dbSelectAccountKey(number)).arg(date3).arg(date4); selectInfo3 = QString("SELECT sum,time,type FROM paymentRecord WHERE accountKey = %1 AND time > datetime('%2') AND time < datetime('%3')") .arg(DBAccountManip::dbSelectAccountKey(number)).arg(date3).arg(date4); QVector<QString> transactionRecord1, transactionRecord2,paymentRecord; transactionRecord1 = transferManip.dbSelect(selectInfo1,3); transactionRecord2 = transferManip.dbSelect(selectInfo2,3); paymentRecord = paymentManip.dbSelect(selectInfo3,3); //构造返回的QVector QVector<QString> infoBetweenTwoDays; int size1 = transactionRecord1.size()/3; int size2 = transactionRecord2.size()/3; int size3 = paymentRecord.size()/3; for(int i = 0;i<size1*3;i++) infoBetweenTwoDays.push_back(transactionRecord1[i]); for(int i = 0;i<size2;i++){ infoBetweenTwoDays.push_back(transactionRecord1[3*i]); infoBetweenTwoDays.push_back(transactionRecord1[3*i + 1]); infoBetweenTwoDays.push_back("be transfered into"); } for(int i = 0;i<size3*3;i++) infoBetweenTwoDays.push_back(paymentRecord[i]); //构造相应的datetime对象 int rows = size1 + size2 + size3; QDateTime times[rows]; for(int i = 0;i<rows;i++) times[i] = QDateTime::fromString(infoBetweenTwoDays[3*i + 1],"yyyy-MM-dd hh:mm:ss"); //比较,冒泡排序 for(int i = 0;i<rows -1;i++) for(int j = 0;j<rows -1;j++){ if(times[j]<times[j + 1]){ QDateTime temp; temp = times[j]; times[j] = times[j + 1]; times[j + 1] = temp; QString temps[3]; temps[0] = infoBetweenTwoDays[3*j]; temps[1] = infoBetweenTwoDays[3*j + 1]; temps[2] = infoBetweenTwoDays[3*j + 2]; infoBetweenTwoDays[3*j] = infoBetweenTwoDays[3*(j+1)]; infoBetweenTwoDays[3*j + 1] = infoBetweenTwoDays[3*(j+1) + 1]; infoBetweenTwoDays[3*j + 2] = infoBetweenTwoDays[3*(j+1) + 2]; infoBetweenTwoDays[3*(j+1)] = temps[0]; infoBetweenTwoDays[3*(j+1) + 1] = temps[1]; infoBetweenTwoDays[3*(j+1) + 2] = temps[2]; } } return infoBetweenTwoDays; }
void test() { cout << " zDate Class Demo \n\n"; // default constructor, Jan 1 0000 zDate a; cout << a << endl; // Various versions of the constructors zDate x(zDate::oct,20,1962); cout << x << endl; // constructor with a julian zDate z( 2450000L ); cout << z << endl; // make a date with system date (tests copy constructor) zDate s(zDate::Today()); cout << s << endl; // init with the day of year zDate y(33, 1996); cout << y << endl; // init from current system time time_t secs_now = time(NULL); zDate n(localtime(&secs_now)); cout << n << endl; // using date addition and subtraction zDate adder = x + 10; cout << adder << endl; adder = adder - 25; cout << adder << endl; //using subtraction of two date objects zDate a1(zDate::Today()); zDate a2 = a1 + 14; cout << (a1 - a2) << endl; cout << (a2 += 10) << endl; a1++; cout << "Tommorrow= " << a1 << endl; a1 = zDate(zDate::jul, 14, 1991); cout << "a1 (7-14-91) < a2 (" << a2 << ")? ==> " << ((a1 < a2) ? "TRUE" : "FALSE") << endl; cout << "a1 (7-14-91) > a2 ("<< a2 << ")? ==> " << ((a1 > a2) ? "TRUE" : "FALSE") << endl; cout << "a1 (7-14-91) < 8-01-91 ? ==> " << ((a1 < zDate(zDate::aug, 1, 1991)) ? "TRUE" : "FALSE") << endl; cout << "a1 (7-14-91) > 8-01-91 ? ==> " << ((a1 > zDate(zDate::aug, 1, 1991)) ? "TRUE" : "FALSE") << endl; cout << "a1 (7-14-91) == 7-14-91 ? ==> " << ((a1==zDate(zDate::jul, 14, 1991)) ? "TRUE" : "FALSE") << endl; zDate a3 = a1; cout << "a1 (" << a1 << ") == a3 (" << a3 << ") ? ==> " << ((a1==a3) ? "TRUE" : "FALSE") << endl; zDate a4 = a1; ++a4; cout << "a1 ("<< a1 <<") == a4 (" << a4 << ") ? ==> " << ((a1==a4) ? "TRUE" : "FALSE") << endl; zDate a5(zDate::Today()); cout << "Today is: " << a5 << endl; a4 = zDate::Today(); cout << "Today (a4) is: " << a4 << endl; cout << "Today + 4 is: " << (a4 += 4) << endl; a4 = zDate::Today(); cout << "Today - 4 is: " << (a4 -= 4) << endl; cout << "=========== Leap Year Test ===========\n"; a1 = zDate(zDate::jan, 15, 1992); cout << a1 << "\t" << ((a1.IsLeapYear()) ? "Leap" : "non-Leap"); cout << "\t" << "day of year: " << a1.DayOfYear() << endl; a1 = zDate(zDate::feb, 16, 1993); cout << a1 << "\t" << ((a1.IsLeapYear()) ? "Leap" : "non-Leap"); cout << "\t" << "day of year: " << a1.DayOfYear() << endl; zDate v4(zDate::Today()); cout << "---------- Add Stuff -----------\n"; cout << "Start => " << v4 << endl; cout << "Add 4 Weeks => " << v4.AddWeeks(4) << endl; cout << "Sub 52 Weeks => " << v4.AddWeeks(-52) << endl; cout << "Add 2 Years => " << v4.AddYears(2) << endl; cout << flush; cout << "---------- Misc Stuff -----------\n"; cout << "The date aboves' day of the month is => " << v4.Day() << endl; cout << "There are " << v4.DaysInMonth() << " days in this month.\n"; cout << "This day happens to be " << v4.DayOfWeek() << " day of week" << endl; cout << "on the " << v4.WeekOfYear() << " week of the year," << endl; cout << "on the " << v4.WeekOfMonth() << " week of the month, " << endl; cout << "which is the "<< (int)v4.Month() << "nth month in the year.\n"; cout << "The year alone is " << v4.Year() << endl; cout << "And this is the " << v4.DayOfYear() << " day of year" << endl; cout << "of a year with " << v4.DaysInYear() << " days in it" << endl; cout << "which makes exatcly " << v4.WeeksInYear() << " weeks" << endl; zDate birthday(zDate::jul, 16, 1973); cout << "The age test: i was born on " << birthday << " which makes me " << v4.Age(birthday) << " years old" << endl; zDate D2(zDate::jul, 4, 1776); int I1 = 4; cout << "Before: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "---------- Postfix '++' test -----------\n"; cout << "Test : I1++ = " << I1++ << ", D2++ = " << D2++ << endl; cout << "After: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "---------- Prefix '++' test -----------\n"; cout << "Test : ++I1 = " << ++I1 << ", ++D2 = " << ++D2 << endl; cout << "After: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "---------- Postfix '--' test -----------\n"; cout << "Test : I1-- = " << I1-- << ", D2-- = " << D2-- << endl; cout << "After: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "---------- Prefix '--' test -----------\n"; cout << "Test : --I1 = " << --I1 << ", --D2 = " << --D2 << endl; cout << "After: I1 = " << I1 << ", D2 = " << D2 << endl; cout << "Last day of this year is dayno " << zDate(zDate::dec, 31, 1996).DayOfYear() << endl; cout << "Last day of prev year is dayno " << zDate(zDate::dec, 31, 1995).DayOfYear() << endl; cout << "Today the moon is " << zDate::Today().MoonPhase() << endl; zDate today = zDate::Today(); cout << "DST for " << today.Year() << " starts on " << today.BeginDST() << " and ends on " << today.EndDST() << endl; cout << "Today, " << today << ", DST is " << (today.IsDST() ? "" : "not") << "in effect" << endl; zDate date1(zDate::aug, 31, 1996); cout << "Adding 6 months to " << date1 << " results in " << date1.AddMonths(6) << endl; zDate date2(zDate::mar, 31, 1996); cout << "Subtracting 1 month from " << date2 << " results in " << date2.AddMonths(-1) << endl; zDate date3(zDate::jul, 4, 1776); cout << "Adding 2400 months to " << date3 << " results in " << date3.AddMonths(2400) << endl; cout << "Today's day number is " << zDate::Today().DayNumber() << endl; zDate date4(zDate::feb, 29, 1996); cout << date4 << " subtract two years = " << date4.AddYears(-2) << endl; cout << "In 1996, DST began on " << zDate::BeginDST(1996) << endl; zDate date5(zDate::sep, 26, 1996); cout << "Moon phase on " << date5 << " was " << date5.MoonPhase() << endl; zDate date6(zDate::oct, 3, 1996); cout << date6 << " + 55 days is " << (date6 + 55) << endl; zDate date7(zDate::oct, 4, 1996); cout << date7 << " + 217 days is "; date7 += 217; cout << date7 << endl; date7 = zDate(zDate::oct, 4, 1996); cout << "Same date - (-217) days is "; date7 -= -217; cout << date7 << endl; cout << "For 1996, Easter is on " << zDate::Easter(1996) << endl; }
int main(int argc, const char *argv[]) { { // 日期创建 boost::gregorian::date date1(boost::gregorian::from_string("2016-2-9")); boost::gregorian::date date2(boost::gregorian::from_simple_string("2016-2-9")); boost::gregorian::date date3(boost::gregorian::from_simple_string("2016-Feb-9")); boost::gregorian::date date4(boost::gregorian::from_undelimited_string("20160209")); boost::gregorian::date date5(boost::gregorian::date_from_iso_string("20160209")); boost::gregorian::date date6(2016, 2, 9); boost::gregorian::date date7(2016, boost::gregorian::Feb, 9); std::cout << "date1: " << date1 << std::endl; std::cout << "date2: " << date2 << std::endl; std::cout << "date3: " << date3 << std::endl; std::cout << "date4: " << date4 << std::endl; std::cout << "date5: " << date5 << std::endl; std::cout << "date6: " << date6 << std::endl; std::cout << "date7: " << date7 << std::endl; } { // 当前日期 boost::gregorian::date today(boost::gregorian::day_clock::local_day()); std::cout << "today: " << today << std::endl; } { // 日期运算 boost::gregorian::date today(boost::gregorian::day_clock::local_day()); boost::gregorian::date date1 = today + boost::gregorian::days(100); std::cout << "today: " << date1 << std::endl; std::cout << "duration: " << (date1 - today).days() << std::endl; std::cout << "date1 > today: " << (date1 > today) << std::endl; } { // 日期字符串 boost::gregorian::date today(boost::gregorian::day_clock::local_day()); std::cout << "today: " << boost::gregorian::to_iso_string(today) << std::endl; std::cout << "today: " << boost::gregorian::to_iso_extended_string(today) << std::endl; } { // 日期属性 boost::gregorian::date today(boost::gregorian::day_clock::local_day()); std::cout << "year: " << today.year() << std::endl; std::cout << "month: " << today.month() << std::endl; // Jan, Feb std::cout << "month: " << today.month().as_number() << std::endl; // month of year 1-12 std::cout << "day: " << today.day() << std::endl; // day of month 1-31 std::cout << "day of year: " << today.day_of_year() << std::endl; // day of year 1-366 std::cout << "day of week: " << today.day_of_week() << std::endl; // Mon, Tue std::cout << "day of week: " << today.day_of_week().as_number() << std::endl; // 1-7 std::cout << "week number: " << today.week_number() << std::endl; // 1-53 std::cout << "day number: " << today.day_number() << std::endl; // total day std::cout << "end of month: " << today.end_of_month() << std::endl; // 2016-Feb-29 } { // 日期循环 boost::gregorian::date t1(boost::gregorian::from_simple_string("2016-2-9")); boost::gregorian::date t2(boost::gregorian::from_simple_string("2016-3-9")); for (boost::gregorian::date d = t1; d != t2; d += boost::gregorian::days(1)) { std::cout << d << std::endl; } } { // ptime boost::posix_time::ptime t1(boost::gregorian::date(2016, 2, 9), boost::posix_time::hours(18)); boost::posix_time::ptime t2(boost::gregorian::date(2016, 2, 9), boost::posix_time::time_duration(19, 1, 1, 0)); auto d = t2 - t1; std::cout << d.total_seconds() << std::endl; } return 0; }