Hintergrund#
In Web- und anderen Anwendungen werden oft Termin-Serien benötigt, die täglich, alle paar Tage, wöchentlich, mehrfach wöchentlich, an einem bestimmten Tag im Monat oder jährlich stattfinden.Beispiele#
Täglich#
Series series = new Series(); series.setBegin(DateUtil.TIME_FORMAT.parse("13:30")); series.getPeriod().setBegin(DateUtil.DATE_FORMAT.parse("01.04.2010")); series.getPeriod().setEnd(DateUtil.DATE_FORMAT.parse("03.04.2010")); series.setPattern(Pattern.DAILY); series.getDaily().setDay(1); if (series.validate()) { // Prüfen ob Serie passt for (Date date : series.iterable()) { System.out.println(date); } }
Wöchentlich#
Series series = new Series(); series.setBegin(DateUtil.TIME_FORMAT.parse("13:30")); series.getPeriod().setBegin(DateUtil.DATE_FORMAT.parse("01.04.2010")); series.getPeriod().setEnd(DateUtil.DATE_FORMAT.parse("15.04.2010")); series.setPattern(Pattern.WEEKLY); series.getWeekly().setWeek(1); series.getWeekly().getWeekdays().add(Weekday.TUESDAY); series.getWeekly().getWeekdays().add(Weekday.THURSDAY); if (series.validate()) { // Prüfen ob Serie passt for (Date date : series.iterable()) { System.out.println(date); } }
Monatlich#
Series series = new Series(); series.setBegin(DateUtil.TIME_FORMAT.parse("13:30")); series.getPeriod().setBegin(DateUtil.DATE_FORMAT.parse("01.04.2010")); series.getPeriod().setEnd(DateUtil.DATE_FORMAT.parse("15.12.2010")); series.setPattern(Pattern.MONTHLY); series.getMonthly().setMode(Monthly.Mode.DAY); series.getMonthly().getMonthDay().setDay(3); series.getMonthly().getMonthDay().setMonth(2); if (series.validate()) { // Prüfen ob Serie passt for (Date date : series.iterable()) { System.out.println(date); } }
Wochentag im Monat#
Series series = new Series(); series.setBegin(DateUtil.TIME_FORMAT.parse("13:30")); series.getPeriod().setBegin(DateUtil.DATE_FORMAT.parse("15.04.2010")); series.getPeriod().setEnd(DateUtil.DATE_FORMAT.parse("15.12.2010")); series.setPattern(Pattern.MONTHLY); series.getMonthly().setMode(Monthly.Mode.WEEKDAY); series.getMonthly().getMonthWeekday().setWeekOfMonth(WeekOfMonth.TWO); series.getMonthly().getMonthWeekday().setWeekday(Weekday.WEDNESDAY); series.getMonthly().getMonthWeekday().setMonth(2); if (series.validate()) { // Prüfen ob Serie passt for (Date date : series.iterable()) { System.out.println(date); } }
Jährlich#
Series series = new Series(); series.setBegin(DateUtil.TIME_FORMAT.parse("13:30")); series.getPeriod().setBegin(DateUtil.DATE_FORMAT.parse("15.04.2010")); series.getPeriod().setEnd(DateUtil.DATE_FORMAT.parse("15.12.2012")); series.setPattern(Pattern.YEARLY); series.getYearly().setMode(Yearly.Mode.DAY); series.getYearly().getYearDay().setDay(4); series.getYearly().getYearDay().setMonth(Month.AUGUST); if (series.validate()) { // Prüfen ob Serie passt for (Date date : series.iterable()) { System.out.println(date); } }
Jährlicher Wochentag#
Series series = new Series(); series.setBegin(DateUtil.TIME_FORMAT.parse("13:30")); series.getPeriod().setBegin(DateUtil.DATE_FORMAT.parse("15.04.2010")); series.getPeriod().setEnd(DateUtil.DATE_FORMAT.parse("15.12.2012")); series.setPattern(Pattern.YEARLY); series.getYearly().setMode(Yearly.Mode.WEEKDAY); series.getYearly().getYearWeekday().setWeekday(Weekday.THURSDAY); series.getYearly().getYearWeekday().setWeekOfMonth(WeekOfMonth.THREE); series.getYearly().getYearWeekday().setMonth(Month.AUGUST); if (series.validate()) { // Prüfen ob Serie passt for (Date date : series.iterable()) { System.out.println(date); } }