⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appointmenttest.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        AppointmentBlockArray blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,8,1).toGMTDate(), new Day( 2008, 8, 1).toGMTDate(), blocks);
        assertEquals( 4, blocks.size());
        assertEquals( start, new Date(blocks.getStartAt( 0)));
        Calendar cal = DateTools.createGMTCalendar();
        cal.setTime( start );
        int weekday = cal.get( Calendar.DAY_OF_WEEK);
        int dayofweekinmonth = cal.get( Calendar.DAY_OF_WEEK_IN_MONTH);
        assertEquals( Calendar.THURSDAY,weekday );
        assertEquals( 5, dayofweekinmonth );
        assertEquals( Calendar.AUGUST, cal.get( Calendar.MONTH));
        
        cal.set( Calendar.MONTH, Calendar.NOVEMBER );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 1)));
        
        cal.add( Calendar.YEAR,1);
        cal.set( Calendar.MONTH, Calendar.MARCH );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        assertEquals(10, cal.get( Calendar.HOUR_OF_DAY));
        start = cal.getTime();
        
        assertEquals( start, new Date(blocks.getStartAt( 2)));
        cal.set( Calendar.MONTH, Calendar.MAY );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 3)));

        assertEquals( start, repeating1.getEnd() );
        assertEquals( start, a1.getMaxEnd() );
        
        blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,1,1).toGMTDate(), new Day( 2007, 10, 20).toGMTDate(), blocks);
        assertEquals( 4, blocks.size());
        
        blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,10,19).toGMTDate(), new Day( 2006, 11, 31).toGMTDate(), blocks);
        assertEquals( 1, blocks.size());        
    }

    public void testMonthlyNeverending()
    {
        Appointment a1 = createAppointment(new Day(2006,8,31),new Time(10,30),new Time(12,0));
        Date start = a1.getStart();
        a1.setRepeatingEnabled(true);
        Repeating repeating1 = a1.getRepeating();
        repeating1.setType( RepeatingType.MONTHLY);
        repeating1.setEnd( null );
        AppointmentBlockArray blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,8,1).toGMTDate(), new Day( 2008, 8, 1).toGMTDate(), blocks);
        assertEquals( 9, blocks.size());
        assertEquals( start, new Date(blocks.getStartAt( 0)));
        Calendar cal = DateTools.createGMTCalendar();
        cal.setTime( start );
        int weekday = cal.get( Calendar.DAY_OF_WEEK);
        int dayofweekinmonth = cal.get( Calendar.DAY_OF_WEEK_IN_MONTH);
        assertEquals( Calendar.THURSDAY,weekday );
        assertEquals( 5, dayofweekinmonth );
        assertEquals( Calendar.AUGUST, cal.get( Calendar.MONTH));
        
        cal.set( Calendar.MONTH, Calendar.NOVEMBER );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 1)));
        
        cal.add( Calendar.YEAR,1);
        cal.set( Calendar.MONTH, Calendar.MARCH );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        assertEquals(10, cal.get( Calendar.HOUR_OF_DAY));
        start = cal.getTime();
        
        assertEquals( start, new Date(blocks.getStartAt( 2)));
        cal.set( Calendar.MONTH, Calendar.MAY );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 3)));

        
        blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,1,1).toGMTDate(), new Day( 2007, 10, 20).toGMTDate(), blocks);
        assertEquals( 5, blocks.size());
    }

    public void testYearly29February()
    {
        Appointment a1 = createAppointment(new Day(2004,2,29),new Time(10,30),new Time(12,0));
        Date start = a1.getStart();
        a1.setRepeatingEnabled(true);
        Repeating repeating1 = a1.getRepeating();
        repeating1.setType( RepeatingType.YEARLY);
        repeating1.setNumber( 4);
        AppointmentBlockArray blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2004,1,1).toGMTDate(), new Day( 2020, 1, 1).toGMTDate(), blocks);
        assertEquals( 4, blocks.size());
        assertEquals( start, new Date(blocks.getStartAt( 0)));
        Calendar cal = DateTools.createGMTCalendar();
        cal.setTime( start );
        int weekday = cal.get( Calendar.DAY_OF_WEEK);
        int dayofweekinmonth = cal.get( Calendar.DAY_OF_WEEK_IN_MONTH);
        assertEquals( Calendar.SUNDAY,weekday );
        assertEquals( 5, dayofweekinmonth );
        assertEquals( Calendar.FEBRUARY, cal.get( Calendar.MONTH));
        
        cal.add( Calendar.YEAR,4);
        cal.set( Calendar.MONTH, Calendar.FEBRUARY );
        cal.set( Calendar.DAY_OF_MONTH , 29 );
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 1)));
        
        cal.add( Calendar.YEAR,4);
        cal.set( Calendar.MONTH, Calendar.FEBRUARY );
        cal.set( Calendar.DAY_OF_MONTH , 29 );
        assertEquals(10, cal.get( Calendar.HOUR_OF_DAY));
        start = cal.getTime();
        
        assertEquals( start, new Date(blocks.getStartAt( 2)));
        cal.add( Calendar.YEAR,4);
        cal.set( Calendar.MONTH, Calendar.FEBRUARY );
        cal.set( Calendar.DAY_OF_MONTH , 29 );
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 3)));

        assertEquals( start, repeating1.getEnd() );
        assertEquals( start, a1.getMaxEnd() );
        
        blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,1,1).toGMTDate(), new Day( 2012, 10, 20).toGMTDate(), blocks);
        assertEquals( 2, blocks.size());
        
        blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2008,1,1).toGMTDate(), new Day( 2008, 11, 31).toGMTDate(), blocks);
        assertEquals( 1, blocks.size());        
    }

    public void testYearly()
    {
        Appointment a1 = createAppointment(new Day(2006,8,17),new Time(10,30),new Time(12,0));
        Date start = a1.getStart();
        a1.setRepeatingEnabled(true);
        Repeating repeating1 = a1.getRepeating();
        repeating1.setType( RepeatingType.YEARLY );
        repeating1.setNumber( 4);
        Calendar cal = DateTools.createGMTCalendar();
        cal.setTime( start );
        int dayInMonth = cal.get( Calendar.DAY_OF_MONTH);
        int month = cal.get( Calendar.MONTH);
        AppointmentBlockArray blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,8,17).toGMTDate(), new Day( 2010, 3, 30).toGMTDate(), blocks);
        assertEquals( 4, blocks.size());
        assertEquals( start, new Date(blocks.getStartAt( 0)));
        cal.add( Calendar.YEAR, 1 );
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 1)));
        cal.add( Calendar.YEAR, 1 );
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 2)));
        cal.add( Calendar.YEAR, 1 );
        start = cal.getTime();
        assertEquals( dayInMonth,cal.get(Calendar.DAY_OF_MONTH));
        assertEquals( month,cal.get(Calendar.MONTH));
        assertEquals( start, new Date(blocks.getStartAt( 3)));
        assertEquals( start, repeating1.getEnd() );
        assertEquals( start, a1.getMaxEnd() );
    }

    public void testMonthlySetEnd()
    {
        Appointment a1 = createAppointment(new Day(2006,8,17),new Time(10,30),new Time(12,0));
        Date start = a1.getStart();
        a1.setRepeatingEnabled(true);
        Repeating repeating1 = a1.getRepeating();
        repeating1.setType( RepeatingType.MONTHLY);
        repeating1.setEnd( new Day(2006,12,1).toGMTDate());
        AppointmentBlockArray blocks = new AppointmentBlockArray();
        {
            Date s =  new Day(2006,8,17).toGMTDate();
            Date e =  new Day( 2007, 3, 30).toGMTDate();
            a1.createBlocks( s,e , blocks);
        }
        assertEquals( 4, blocks.size());
        assertEquals( start, new Date(blocks.getStartAt( 0)));
        Calendar cal = DateTools.createGMTCalendar();
        cal.setTime( start );
        int weekday = cal.get( Calendar.DAY_OF_WEEK);
        int dayofweekinmonth = cal.get( Calendar.DAY_OF_WEEK_IN_MONTH);
        assertEquals( Calendar.THURSDAY,weekday );
        assertEquals( 3, dayofweekinmonth );
        assertEquals( Calendar.AUGUST, cal.get( Calendar.MONTH));
        cal.add( Calendar.MONTH, 1 );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 1)));
        cal.add( Calendar.MONTH, 1 );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        assertEquals(10, cal.get( Calendar.HOUR_OF_DAY));
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 2)));
        cal.add( Calendar.MONTH, 1 );
        cal.set( Calendar.DAY_OF_WEEK , weekday );
        cal.set( Calendar.DAY_OF_WEEK_IN_MONTH, dayofweekinmonth);
        start = cal.getTime();
        assertEquals( start, new Date(blocks.getStartAt( 3)));

        assertEquals( new Day(2006,12,1).toGMTDate(), repeating1.getEnd() );
        assertEquals( new Day(2006,12,1).toGMTDate(), a1.getMaxEnd() );
        
        blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,1,1).toGMTDate(), new Day( 2007, 10, 20).toGMTDate(), blocks);
        assertEquals( 4, blocks.size());
        
        blocks = new AppointmentBlockArray();
        a1.createBlocks( new Day(2006,10,19).toGMTDate(), new Day( 2006, 10, 20).toGMTDate(), blocks);
        assertEquals( 1, blocks.size());        
    }

}





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -