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 DTSTART iCalendar component property.
50   *
51   * @author benf
52   */
53  public class DtStart 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       *             where the specified value string is not a valid
68       *             date-time/date representation
69       */
70      public DtStart(final ParameterList aList, final String aValue)
71              throws ParseException {
72          super(DTSTART, aList);
73  
74          
75          if (aList.getParameter(Parameter.VALUE) != null
76                  && Value.DATE.equals(aList.getParameter(Parameter.VALUE).getValue())) {
77  
78              time = DateFormat.getInstance().parse(aValue);
79          }
80          else {
81              time = DateTimeFormat.getInstance().parse(aValue);
82          }
83      }
84  
85      /***
86       * Constructor. Date or Date-Time format is determined based
87       * on the presence of a VALUE parameter.
88       * @param aList
89       *            a list of parameters for this component
90       * @param aDate
91       *            a date
92       */
93      public DtStart(final ParameterList aList, final Date aDate) {
94          super(DTSTART, aList);
95  
96          time = aDate;
97      }
98  
99      /***
100      * @return Returns the time.
101      */
102     public final Date getTime() {
103         return time;
104     }
105 
106     /***
107      * @see net.fortuna.ical4j.model.Property#validate()
108      */
109     public final void validate() throws ValidationException {
110 
111         
112 
113 
114 
115 
116         ParameterValidator.getInstance().validateOneOrLess(Parameter.VALUE,
117                 getParameters());
118 
119         Parameter valueParam = getParameters().getParameter(Parameter.VALUE);
120 
121         if (valueParam != null
122                 && !Value.DATE_TIME.equals(valueParam.getValue())
123                 && !Value.DATE.equals(valueParam.getValue())) {
124             throw new ValidationException(
125                 "Parameter [" + Parameter.VALUE + "] is invalid");
126         }
127 
128         ParameterValidator.getInstance().validateOneOrLess(Parameter.TZID,
129                 getParameters());
130 
131         
132 
133 
134 
135 
136     }
137 
138     
139 
140 
141 	public String getValue() {
142 		if (getParameters().getParameter(Parameter.VALUE) != null
143           && Value.DATE.equals(getParameters().getParameter(Parameter.VALUE).getValue())) {
144             return DateFormat.getInstance().format(getTime());
145 		}
146 
147         
148         return DateTimeFormat.getInstance().format(getTime(), isUtc());
149 	}
150 
151     /***
152      * @return Returns the utc.
153      */
154     public boolean isUtc() {
155         return utc;
156     }
157 
158     /***
159      * @param utc The utc to set.
160      */
161     public void setUtc(boolean utc) {
162         this.utc = utc;
163     }
164 }