void WorkInfoCacheTester::fullDay()
{
    Calendar cal("Test");
    QDate wdate(2012,1,2);

    QTime t1(0,0,0);
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate.addDays( 1 ), t1);
    long length = ( wdt2 - wdt1 ).milliseconds();
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    cal.addDay(day);
    QVERIFY(cal.findDay(wdate) == day);

    Resource r;
    r.setCalendar( &cal );
    const Resource::WorkInfoCache &wic = r.workInfoCache();
    QVERIFY( ! wic.isValid() );

    r.calendarIntervals( wdt1, wdt2 );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 1 );

    day = new CalendarDay(wdt2.date(), CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    cal.addDay(day);

    r.calendarIntervals( wdt1, DateTime( wdt2.addDays( 2 ) ) );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 2 );
}
Пример #2
0
void CalendarTester::testSingleDay() {
    Calendar t("Test");
    QDate wdate(2006,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate, t2);
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    t.addDay(day);
    QVERIFY(t.findDay(wdate) == day);
    
    QVERIFY(t.hasInterval(after, DateTime( after.addDays(1))) == false);
    QVERIFY(t.hasInterval(before, DateTime(before.addDays(-1))) == false);
    
    QVERIFY(t.hasInterval(after, before) == false);
    QVERIFY(t.hasInterval(before, after));
    
    QVERIFY((t.firstAvailableAfter(after, DateTime(after.addDays(10)))).isValid() == false);
    QVERIFY((t.firstAvailableBefore(before, DateTime(before.addDays(-10)))).isValid() == false);
    
    QCOMPARE(t.firstAvailableAfter(before,after), wdt1);
    QCOMPARE(t.firstAvailableBefore(after, before), wdt2);
    
    Duration e(0, 2, 0);
    QCOMPARE((t.effort(before, after)).toString(), e.toString());
}
void WorkInfoCacheTester::addBefore()
{
    Calendar cal("Test");
    QDate wdate(2012,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    QTime t3(12,0,0);
    QTime t4(14,0,0);
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate, t2);
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    length = t3.msecsTo( t4 );
    day->addInterval(TimeInterval(t3, length));
    cal.addDay(day);
    QVERIFY(cal.findDay(wdate) == day);

    Resource r;
    r.setCalendar( &cal );
    const Resource::WorkInfoCache &wic = r.workInfoCache();
    QVERIFY( ! wic.isValid() );

    r.calendarIntervals( before, after );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 2 );

    wdt1 = wdt1.addDays( 1 );
    wdt2 = wdt2.addDays( 1 );
    day = new CalendarDay(wdt1.date(), CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    cal.addDay(day);

    // wdate: 8-10, 12-14
    // wdate+1: 8-10
    r.calendarIntervals( DateTime( wdate.addDays( 1 ), t1 ), DateTime( wdate.addDays( 1 ), t2 ) );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 1 );

    r.calendarIntervals( DateTime( wdate, t3 ), DateTime( wdate, t4 ) );
    QCOMPARE( wic.intervals.map().count(), 2 );

    r.calendarIntervals( DateTime( wdate, t1 ), DateTime( wdate, t2 ) );
    QCOMPARE( wic.intervals.map().count(), 3 );
}
Пример #4
0
void CalendarTester::testTimezone()
{
    Calendar t("Test");
    QDate wdate(2006,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate, t2);
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    t.addDay(day);
    Debug::print( &t, "Time zone testing" );
    QVERIFY(t.findDay(wdate) == day);

    // local zone: Europe/Berlin ( 1 hours from London )
    KTimeZone lo = KSystemTimeZones::zone("Europe/London");
    QVERIFY( lo.isValid() );
    KDateTime dt1 = KDateTime( wdate, t1, lo ).addSecs( -2 * 3600 );
    KDateTime dt2 = KDateTime( wdate, t2, lo ).addSecs( 0 * 3600 );

    qDebug()<<KDateTime( wdt1 )<<KDateTime( wdt2 );
    qDebug()<<dt1<<dt2<<"("<<dt1.toLocalZone()<<dt2.toLocalZone()<<")";
    QCOMPARE(t.firstAvailableAfter( DateTime( dt1 ), after ), wdt1 );
    QCOMPARE(t.firstAvailableBefore( DateTime( dt2 ), before ), wdt2 );

    Duration e(0, 2, 0);
    QCOMPARE( t.effort( DateTime( dt1 ), DateTime( dt2 ) ).toString(), e.toString() );

    // local zone: Europe/Berlin ( 9 hours from America/Los_Angeles )
    KTimeZone la = KSystemTimeZones::zone("America/Los_Angeles");
    QVERIFY( la.isValid() );
    KDateTime dt3 = KDateTime( wdate, t1, la ).addSecs( -10 * 3600 );
    KDateTime dt4 = KDateTime( wdate, t2, la ).addSecs( -8 * 3600 );

    qDebug()<<KDateTime( wdt1 )<<KDateTime( wdt2 );
    qDebug()<<dt3<<dt4<<"("<<dt3.toLocalZone()<<dt4.toLocalZone()<<")";
    QCOMPARE(t.firstAvailableAfter( DateTime( dt3 ), after ), wdt1 );
    QCOMPARE(t.firstAvailableBefore( DateTime( dt4 ), before ), wdt2 );

    QCOMPARE( t.effort( DateTime( dt3 ), DateTime( dt4 ) ).toString(), e.toString() );

    QString s = "Test Cairo:";
    qDebug()<<s;
    // local zone: Europe/Berlin ( 1 hour from cairo )
    KTimeZone ca = KSystemTimeZones::zone("Africa/Cairo");
    KDateTime dt5 = KDateTime( wdate, t1, ca ).addSecs( 0 * 3600 );
    KDateTime dt6 = KDateTime( wdate, t2, ca ).addSecs( 2 * 3600 );

    qDebug()<<KDateTime( wdt1 )<<KDateTime( wdt2 );
    qDebug()<<dt5<<dt6<<"("<<dt5.toLocalZone()<<dt6.toLocalZone()<<")";
    QCOMPARE(t.firstAvailableAfter( DateTime( dt5 ), after ), wdt1 );
    QCOMPARE(t.firstAvailableBefore( DateTime( dt6 ), before ), wdt2 );

    QCOMPARE( t.effort( DateTime( dt5 ), DateTime( dt6 ) ).toString(), e.toString() );
}
Пример #5
0
void CalendarTester::workIntervals()
{
    Calendar t("Test");
    QDate wdate(2006,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(8,0,0);
    QTime t2(10,0,0);
    DateTime wdt1( wdate, t1 );
    DateTime wdt2( wdate, t2 );
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval( TimeInterval( t1, length ) );
    t.addDay(day);
    QVERIFY(t.findDay(wdate) == day);
    
    AppointmentIntervalList lst = t.workIntervals( before, after, 100. );
    QCOMPARE( lst.map().count(), 1 );
    QCOMPARE( wdate, lst.map().values().first().startTime().date() );
    QCOMPARE( t1, lst.map().values().first().startTime().time() );
    QCOMPARE( wdate, lst.map().values().first().endTime().date() );
    QCOMPARE( t2, lst.map().values().first().endTime().time() );
    QCOMPARE( 100., lst.map().values().first().load() );
    
    QTime t3( 12, 0, 0 );
    day->addInterval( TimeInterval( t3, length ) );
    
    lst = t.workIntervals( before, after, 100. );
    Debug::print( lst );
    QCOMPARE( lst.map().count(), 2 );
    QCOMPARE( wdate, lst.map().values().first().startTime().date() );
    QCOMPARE( t1, lst.map().values().first().startTime().time() );
    QCOMPARE( wdate, lst.map().values().first().endTime().date() );
    QCOMPARE( t2, lst.map().values().first().endTime().time() );
    QCOMPARE( 100., lst.map().values().first().load() );
    
    QCOMPARE( wdate, lst.map().values().at( 1 ).startTime().date() );
    QCOMPARE( t3, lst.map().values().at( 1 ).startTime().time() );
    QCOMPARE( wdate, lst.map().values().at( 1 ).endTime().date() );
    QCOMPARE( t3.addMSecs( length ), lst.map().values().at( 1 ).endTime().time() );
    QCOMPARE( 100., lst.map().values().at( 1 ).load() );
}
Пример #6
0
void CalendarTester::workIntervalsFullDays()
{
    Calendar t("Test");
    QDate wdate(2006,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(10), QTime());

    CalendarDay *day = new CalendarDay( wdate, CalendarDay::Working );
    day->addInterval( TimeInterval( QTime( 0, 0, 0), 24*60*60*1000 ) );
    t.addDay(day);

    QCOMPARE( day->numIntervals(), 1 );
    QVERIFY( day->intervalAt( 0 )->endsMidnight() );

    DateTime start = day->start();
    DateTime end = day->end();

    QCOMPARE( t.workIntervals( start, end, 100. ).map().count(), 1 );
    QCOMPARE( t.workIntervals( before, after, 100. ).map().count(), 1 );

    day = new CalendarDay( wdate.addDays( 1 ), CalendarDay::Working );
    day->addInterval( TimeInterval( QTime( 0, 0, 0), 24*60*60*1000 ) );
    t.addDay( day );

    end = day->end();

    QCOMPARE( t.workIntervals( start, end, 100. ).map().count(), 2 );
    QCOMPARE( t.workIntervals( before, after, 100. ).map().count(), 2 );

    day = new CalendarDay( wdate.addDays( 2 ), CalendarDay::Working );
    day->addInterval( TimeInterval( QTime( 0, 0, 0), 24*60*60*1000 ) );
    t.addDay( day );

    end = day->end();

    QCOMPARE( t.workIntervals( start, end, 100. ).map().count(), 3 );
    QCOMPARE( t.workIntervals( before, after, 100. ).map().count(), 3 );

}
Пример #7
0
static Calendar *createCalendar( Project &p )
{
    Calendar *c = new Calendar();
    c->setDefault( true );
    QTime t1( 9, 0, 0 );
    QTime t2 ( 17, 0, 0 );
    int length = t1.msecsTo( t2 );
    for ( int i=1; i <= 7; ++i ) {
        CalendarDay *d = c->weekday( i );
        d->setState( CalendarDay::Working );
        d->addInterval( t1, length );
    }
    p.addCalendar( c );
    return c;
}
void WorkInfoCacheTester::timeZone()
{
    Calendar cal("Test");
    // local zone: Europe/Berlin ( 9 hours from America/Los_Angeles )
    KTimeZone la = KSystemTimeZones::zone("America/Los_Angeles");
    QVERIFY( la.isValid() );
    cal.setTimeZone( la );

    QDate wdate(2012,1,2);
    DateTime before = DateTime(wdate.addDays(-1), QTime());
    DateTime after = DateTime(wdate.addDays(1), QTime());
    QTime t1(14,0,0); // 23 LA
    QTime t2(16,0,0); // 01 LA next day
    DateTime wdt1(wdate, t1);
    DateTime wdt2(wdate, t2);
    int length = t1.msecsTo( t2 );
    CalendarDay *day = new CalendarDay(wdate, CalendarDay::Working);
    day->addInterval(TimeInterval(t1, length));
    cal.addDay(day);
    QVERIFY(cal.findDay(wdate) == day);

    Debug::print( &cal, "America/Los_Angeles" );
    Resource r;
    r.setCalendar( &cal );
    const Resource::WorkInfoCache &wic = r.workInfoCache();
    QVERIFY( ! wic.isValid() );

    r.calendarIntervals( before, after );
    qDebug()<<wic.intervals.map();
    QCOMPARE( wic.intervals.map().count(), 2 );

    QCOMPARE( wic.intervals.map().value( wdate ).startTime(), DateTime( wdate, QTime( 23, 0, 0 ) ) );
    QCOMPARE( wic.intervals.map().value( wdate ).endTime(), DateTime( wdate.addDays( 1 ), QTime( 0, 0, 0 ) ) );

    wdate = wdate.addDays( 1 );
    QCOMPARE( wic.intervals.map().value( wdate ).startTime(), DateTime( wdate, QTime( 0, 0, 0 ) ) );
    QCOMPARE( wic.intervals.map().value( wdate ).endTime(), DateTime( wdate, QTime( 1, 0, 0 ) ) );
}
void ResourceModelTester::initTestCase()
{
    m_project = new Project();
    m_project->setName( "P1" );
    m_project->setId( m_project->uniqueNodeId() );
    m_project->registerNodeId( m_project );
    DateTime targetstart = DateTime( QDate::currentDate(), QTime(0,0,0) );
    DateTime targetend = DateTime( targetstart.addDays( 3 ) );
    m_project->setConstraintStartTime( targetstart );
    m_project->setConstraintEndTime( targetend);

    // standard worktime defines 8 hour day as default
    QVERIFY( m_project->standardWorktime() );
    QCOMPARE( m_project->standardWorktime()->day(), 8.0 );
    m_calendar = new Calendar( "Test" );
    m_calendar->setDefault( true );
    QTime t1( 9, 0, 0 );
    QTime t2 ( 17, 0, 0 );
    int length = t1.msecsTo( t2 );
    for ( int i=1; i <= 7; ++i ) {
        CalendarDay *d = m_calendar->weekday( i );
        d->setState( CalendarDay::Working );
        d->addInterval( t1, length );
    }
    m_project->addCalendar( m_calendar );


    ResourceGroup *g = new ResourceGroup();
    g->setName( "G1" );
    m_project->addResourceGroup( g );
    m_resource = new Resource();
    m_resource->setName( "R1" );
    m_resource->setCalendar( m_calendar );
    m_project->addResource( g, m_resource );

    m_task = m_project->createTask();
    m_task->setName( "T1" );
    m_project->addTask( m_task, m_project );
    m_task->estimate()->setUnit( Duration::Unit_h );
    m_task->estimate()->setExpectedEstimate( 8.0 );
    m_task->estimate()->setType( Estimate::Type_Effort );


    ResourceGroupRequest *gr = new ResourceGroupRequest( g );
    gr->addResourceRequest( new ResourceRequest( m_resource, 100 ) );
    m_task->addRequest( gr );

    m_model.setProject( m_project );

    QModelIndex idx;
    int rows = m_model.rowCount( idx );
    QCOMPARE( rows, 1 );
    idx = m_model.index( 0, 0, idx );
    QCOMPARE( g->name(), m_model.data( idx ).toString() );
    
    rows = m_model.rowCount( idx );
    QCOMPARE( rows, 1 );
    idx = m_model.index( 0, 0, idx );
    QCOMPARE( m_resource->name(), m_model.data( idx ).toString() );

    idx = m_model.parent( idx );
    QCOMPARE( g->name(), m_model.data( idx ).toString() );
}