1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package net.fortuna.ical4j.model.property;
35
36 import java.text.ParseException;
37 import java.util.Date;
38
39 import net.fortuna.ical4j.model.Parameter;
40 import net.fortuna.ical4j.model.ParameterList;
41 import net.fortuna.ical4j.model.Property;
42 import net.fortuna.ical4j.model.ValidationException;
43 import net.fortuna.ical4j.model.parameter.Value;
44 import net.fortuna.ical4j.util.DateFormat;
45 import net.fortuna.ical4j.util.DateTimeFormat;
46 import net.fortuna.ical4j.util.ParameterValidator;
47
48 /***
49 * Defines a DTEND iCalendar component property.
50 *
51 * @author benf
52 */
53 public class DtEnd extends Property {
54
55 private Date time;
56
57
58
59 private boolean utc = false;
60
61 /***
62 * @param aList
63 * a list of parameters for this component
64 * @param aValue
65 * a value string for this component
66 * @throws ParseException
67 * when the specified string is not a valid date/date-time
68 * representation
69 */
70 public DtEnd(final ParameterList aList, final String aValue)
71 throws ParseException {
72 super(DTEND, aList);
73
74
75 if (aList.getParameter(Parameter.VALUE) != null
76 && Value.DATE.equals(aList.getParameter(Parameter.VALUE)
77 .getValue())) {
78
79 time = DateFormat.getInstance().parse(aValue);
80 }
81 else {
82 time = DateTimeFormat.getInstance().parse(aValue);
83 }
84 }
85
86 /***
87 * Constructor. Date or Date-Time format is determined based on the presence
88 * of a VALUE parameter.
89 *
90 * @param aList
91 * a list of parameters for this component
92 * @param aDate
93 * a date
94 */
95 public DtEnd(final ParameterList aList, final Date aDate) {
96 super(DTEND, aList);
97
98 time = aDate;
99 }
100
101 /***
102 * @see net.fortuna.ical4j.model.Property#validate()
103 */
104 public final void validate() throws ValidationException {
105
106
107
108
109
110
111 ParameterValidator.getInstance().validateOneOrLess(Parameter.VALUE,
112 getParameters());
113
114 Parameter valueParam = getParameters().getParameter(Parameter.VALUE);
115
116 if (valueParam != null
117 && !Value.DATE_TIME.equals(valueParam.getValue())
118 && !Value.DATE.equals(valueParam.getValue())) { throw new ValidationException(
119 "Parameter [" + Parameter.VALUE + "] is invalid"); }
120
121 ParameterValidator.getInstance().validateOneOrLess(Parameter.TZID,
122 getParameters());
123
124
125
126
127
128
129 }
130
131 /***
132 * @return Returns the time.
133 */
134 public final Date getTime() {
135 return time;
136 }
137
138
139
140
141
142
143 public String getValue() {
144 if (getParameters().getParameter(Parameter.VALUE) != null
145 && Value.DATE.equals(getParameters().getParameter(
146 Parameter.VALUE).getValue())) { return DateFormat
147 .getInstance().format(getTime()); }
148
149
150 return DateTimeFormat.getInstance().format(getTime(), isUtc());
151 }
152
153 /***
154 * @return Returns the utc.
155 */
156 public boolean isUtc() {
157 return utc;
158 }
159
160 /***
161 * @param utc
162 * The utc to set.
163 */
164 public void setUtc(boolean utc) {
165 this.utc = utc;
166 }
167 }