Пример #1
0
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);   
}
Пример #2
0
int main(int argc, char* argv[])
{

  ScopedThread t1([]
                  {
                    tcInfo.Init();
                    while (keepRunning) std::this_thread::yield();
                  });
  ScopedThread t2([]
                  {
                    tcInfo.Init();
                    while (keepRunning) std::this_thread::yield();
                  });
  ScopedThread t3([]
                  {
                    tcInfo.Init();
                    while (keepRunning) std::this_thread::yield();
                  });
  ScopedThread dt1([]
                   { tcInfo.Init(); }); // Nothing to do

  while (totalCreatedThreadCount != 4 && totalLiveThreadCount != 3)
    ; // Loop

  std::cout << "Total threads spawned: " << totalCreatedThreadCount
            << "\nTotal live threads: " << totalLiveThreadCount << std::endl;

  keepRunning = false;
}
Пример #3
0
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);
}
Пример #4
0
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);
}
Пример #5
0
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());
}
Пример #6
0
double RRConverter::curOADate() {
    QDateTime dt2 = QDateTime::currentDateTimeUtc();
    dt2 = dt2.addSecs(3600*3);
    QDateTime dt1(QDate(1899, 12, 30), QTime());

    double res2 = dt1.time().secsTo(dt2.time());
    double res3 = (double)dt1.date().daysTo(dt2.date());
    res2 = res2/86400.0 + res3;
    return res2;
}
Пример #7
0
void dt()
{
 //printf("\nEnter <dt>");
 if(!strcmp(token,"ID"))
 {
 consume();
 dt1();
 }
 else
 error("Declaration syntax error. Expecting IDENTIFIER or TERMINATOR");
 //printf("\nExit <dt>");
}
Пример #8
0
void tst_QDate::weekNumber()
{
    int yearNumber;
    QFETCH( int, year );
    QFETCH( int, month );
    QFETCH( int, day );
    QFETCH( int, expectedWeekNum );
    QFETCH( int, expectedYearNum );
    QDate dt1( year, month, day );
    QCOMPARE( dt1.weekNumber( &yearNumber ), expectedWeekNum );
    QCOMPARE( yearNumber, expectedYearNum );
}
Пример #9
0
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
	}
Пример #10
0
double RRConverter::OBTS2OADate(double obts) {
    QDateTime dt2 = OBTSFirstDay();
    dt2 = dt2.addSecs(obts);
    dt2 = dt2.addSecs(-3600*3);

    QDateTime dt1(QDate(1899, 12, 30), QTime());


    double res2 = dt1.time().secsTo(dt2.time());
    double res3 = (double)dt1.date().daysTo(dt2.date());
    res2 = res2/86400.0 + res3;
    return res2;
}
Пример #11
0
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);
}
Пример #12
0
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);
}
Пример #13
0
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);
}
Пример #14
0
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. );
}
Пример #15
0
int init() {
    QTextStream out(stdout);
    
    QDate dt1(2011, 4, 12);
    out << "The dae is " << dt1.toString() << endl;
    
    QDate dt2;
    dt2.setDate(2011, 3, 3);
    out << "The date is " << dt2.toString() << endl;
    
    QTime tm1(17, 30, 12, 55);
    out << "The time is " << tm1.toString("hh:mm:ss.zzz") << endl;
    
    QTime tm2;
    tm2.setHMS(13, 53, 45, 155);
    out << "The time is " << tm2.toString("hh:mm:ss.zzz") << endl;
    
    return 0;
}
Пример #16
0
void DateTimeTester::timeZones()
{
    QByteArray tz("TZ=Europe/Copenhagen");
    putenv(tz.data());
    
    QTimeZone testZone("Europe/London");
    
    DateTime dt1(QDate(2006, 1, 1), QTime(8, 0, 0, 0 ), testZone);
    
    DateTime dt2 = dt1;
    qDebug()<<dt1<<dt2;
    QCOMPARE(dt1.timeZone(), dt2.timeZone());
    
    dt2 += Duration(1, 0, 0, 0, 0);
    qDebug()<<dt2;
    QCOMPARE(dt1.timeZone(), dt2.timeZone());
    
    dt2 -= Duration(1, 0, 0, 0, 0);
    qDebug()<<dt1<<dt2;
    QCOMPARE(dt1.timeZone(), dt2.timeZone());
    QCOMPARE(dt2, dt1);
    
    dt2 = dt1 + Duration(1, 0, 0, 0, 0);
    qDebug()<<dt1<<dt2;
    QCOMPARE(dt1.timeZone(), dt2.timeZone());

    dt2 = dt2 - Duration(1, 0, 0, 0, 0);
    qDebug()<<dt1<<dt2;
    QCOMPARE(dt1.timeZone(), dt2.timeZone());
    QCOMPARE(dt2, dt1);
    
    DateTime dt3 = QDateTime(QDate(2006, 1, 1), QTime(8, 0, 0, 0 ), testZone);
    qDebug()<<dt3;
    QCOMPARE(dt3.timeZone(), testZone);
    
    DateTime dt4(QDateTime(QDate(2006, 1, 1), QTime(8, 0, 0, 0 ), Qt::UTC));
    dt4 += Duration(1, 0, 0, 0, 0);
    qDebug()<<dt4;
    QCOMPARE(dt4.timeSpec(), Qt::UTC);
    
}
void CBCGPRecurrence::Query (XBCGPAppointmentArray& ar, const COleDateTime& date1, const COleDateTime& date2) const
{
	ar.RemoveAll ();

	POSITION Pos = m_Exceptions.GetStartPosition ();
	COleDateTime Key;
	XBCGPRecurrenceException* Val = NULL;

	CList<COleDateTime, const COleDateTime&> exceptions;

	CBCGPAppointment* pApp = NULL;

	while (Pos != NULL)
	{
		m_Exceptions.GetNextAssoc (Pos, Key, Val);

		if (Val != NULL && !Val->m_Deleted)
		{
			if ((date1 <= Val->m_dtStart && Val->m_dtStart <= date2) || 
				(date1 <= Val->m_dtFinish && Val->m_dtFinish <= date2) ||
				(Val->m_dtStart < date1 && date2 < Val->m_dtFinish))
			{
				pApp = CreateClone (Key);

				if (pApp != NULL)
				{
					exceptions.AddTail (Key);
					ar.Add (pApp);
				}
			}
		}
	}

	CBCGPRecurrenceBaseRule* pRule = GetRule ();
	ASSERT_VALID(pRule);

	if (pRule == NULL)
	{
		return;
	}

	BOOL bNext = TRUE;
	COleDateTime dt1 (pRule->GetDateStart ());

	if (!CBCGPPlannerView::IsOneDay (m_pAppointment->GetStart (), 
			m_pAppointment->GetFinish ()))
	{
		if (dt1 < date1)
		{
			COleDateTimeSpan span ((double)((int)
				((double)m_pAppointment->GetDuration () + 0.5)));

			COleDateTime d (date1 - span);
			if (d > dt1)
			{
				dt1 = pRule->GetSiblingEventDay (d);
			}

			bNext = FALSE;
		}
	}

	if (bNext)
	{
		if (dt1 <= date2)
		{
			if (dt1 <= date1)
			{
				dt1 = pRule->GetSiblingEventDay (date1);
			}
		}
	}

	if (dt1 == COleDateTime ())
	{
		return;
	}

	while (dt1 <= date2)
	{
		if (exceptions.Find (dt1) == NULL 
			&& !ExceptionExists (dt1))
		{
			pApp = CreateClone (dt1);

			if (pApp != NULL)
			{
				if (pApp->GetFinish () != date1 ||
					(pApp->GetStart () == pApp->GetFinish () && pApp->GetFinish () == date1))
				{
					ar.Add (pApp);
				}
				else
				{
					delete pApp;
				}
			}
		}

		dt1 = pRule->GetNextEventDay (dt1);

		if (dt1 == COleDateTime ())
		{
			break;
		}
	}
}
Пример #18
0
bool KQuestCommon::IsSameDay(time_t t1, time_t t2)
{
	KDatetime dt1(t1);
	KDatetime dt2(t2);
	return dt1.ToLocalDays() == dt2.ToLocalDays();
}
Пример #19
0
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;

}
Пример #20
0
Type nldens(Type x, Type mu, Type sd, Type p){
  Type z=(x-mu)/sd;
  return -log(1.0/sd*((1.0-p)*dnorm(z,Type(0.0),Type(1.0),false)+p*dt1(z)));
}
    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));
      }
    }