1
2
3
4
5
6
7
8
9
10
11 package de.jaret.util.date.iterator;
12
13 import de.jaret.util.date.JaretDate;
14
15 /***
16 * Implementation of the DateIterator for days.
17 *
18 * @author kliem
19 * @version $Id: DayIterator.java 845 2009-02-22 18:28:44Z kliem $
20 */
21 public class DayIterator extends AbstractDateIterator implements DateIterator {
22 /*** day step. */
23 protected int _days = 1;
24
25
26 /*** default formatter. */
27 protected IIteratorFormatter _defaultFormatter = new IIteratorFormatter() {
28
29 /***
30 * {@inheritDoc}
31 */
32 public String getLabel(JaretDate date, Format format) {
33 if (format.equals(Format.SHORT)) {
34 return Integer.toString(date.getDay()) + ".";
35 } else if (format.equals(Format.MEDIUM)) {
36 return Integer.toString(date.getDay()) + ".(" + date.getShortDayOfWeekString() + ")";
37 } else {
38 return Integer.toString(date.getDay()) + ".(" + date.getDayOfWeekString() + ")";
39 }
40 }
41 };
42
43 /***
44 * Constructs the iterator with a 1 day step.
45 */
46 public DayIterator() {
47
48 }
49 /***
50 * Constructs the iterator with a n day step.
51 * @param days number of days per step
52 */
53 public DayIterator(int days) {
54 _days = days;
55 }
56
57 /***
58 * {@inheritDoc}
59 */
60 protected void advanceDate(JaretDate date) {
61 date.advanceDays(_days);
62 }
63
64 /***
65 * {@inheritDoc}
66 */
67 public long getApproxStepMilliSeconds() {
68 return (long)_days* 24L * 60L * 60L * 1000L;
69 }
70
71 /***
72 * {@inheritDoc}
73 */
74 protected JaretDate correctStartDate(JaretDate date) {
75 date.setTime(0, 0, 0);
76 return date;
77 }
78
79 /***
80 * {@inheritDoc}
81 */
82 protected IIteratorFormatter getDefaultFormatter() {
83 return _defaultFormatter;
84 }
85
86 }