|
1 /** |
|
2 * Copyright (c) 2012, Ben Fortuna |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * o Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * o Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * o Neither the name of Ben Fortuna nor the names of any other contributors |
|
17 * may be used to endorse or promote products derived from this software |
|
18 * without specific prior written permission. |
|
19 * |
|
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
31 */ |
|
32 package net.fortuna.ical4j.model.property; |
|
33 |
|
34 import java.util.Date; |
|
35 |
|
36 import net.fortuna.ical4j.model.Dur; |
|
37 import net.fortuna.ical4j.model.ParameterList; |
|
38 import net.fortuna.ical4j.model.Property; |
|
39 import net.fortuna.ical4j.model.PropertyFactoryImpl; |
|
40 import net.fortuna.ical4j.model.ValidationException; |
|
41 |
|
42 /** |
|
43 * $Id$ |
|
44 * |
|
45 * Created: [Apr 6, 2004] |
|
46 * |
|
47 * Defines a DURATION iCalendar component property. |
|
48 * |
|
49 * <pre> |
|
50 * 4.3.6 Duration |
|
51 * |
|
52 * Value Name: DURATION |
|
53 * |
|
54 * Purpose: This value type is used to identify properties that contain |
|
55 * a duration of time. |
|
56 * |
|
57 * Formal Definition: The value type is defined by the following |
|
58 * notation: |
|
59 * |
|
60 * dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week) |
|
61 * |
|
62 * dur-date = dur-day [dur-time] |
|
63 * dur-time = "T" (dur-hour / dur-minute / dur-second) |
|
64 * dur-week = 1*DIGIT "W" |
|
65 * dur-hour = 1*DIGIT "H" [dur-minute] |
|
66 * dur-minute = 1*DIGIT "M" [dur-second] |
|
67 * dur-second = 1*DIGIT "S" |
|
68 * dur-day = 1*DIGIT "D" |
|
69 * |
|
70 * Description: If the property permits, multiple "duration" values are |
|
71 * specified by a COMMA character (US-ASCII decimal 44) separated list |
|
72 * of values. The format is expressed as the [ISO 8601] basic format for |
|
73 * the duration of time. The format can represent durations in terms of |
|
74 * weeks, days, hours, minutes, and seconds. |
|
75 * |
|
76 * No additional content value encoding (i.e., BACKSLASH character |
|
77 * encoding) are defined for this value type. |
|
78 * |
|
79 * Example: A duration of 15 days, 5 hours and 20 seconds would be: |
|
80 * |
|
81 * P15DT5H0M20S |
|
82 * |
|
83 * A duration of 7 weeks would be: |
|
84 * |
|
85 * P7W |
|
86 * </pre> |
|
87 * |
|
88 * @author Ben Fortuna |
|
89 */ |
|
90 public class Duration extends Property { |
|
91 |
|
92 private static final long serialVersionUID = 9144969653829796798L; |
|
93 |
|
94 private Dur duration; |
|
95 |
|
96 /** |
|
97 * Default constructor. |
|
98 */ |
|
99 public Duration() { |
|
100 super(DURATION, PropertyFactoryImpl.getInstance()); |
|
101 } |
|
102 |
|
103 /** |
|
104 * @param aList a list of parameters for this component |
|
105 * @param aValue a value string for this component |
|
106 */ |
|
107 public Duration(final ParameterList aList, final String aValue) { |
|
108 super(DURATION, aList, PropertyFactoryImpl.getInstance()); |
|
109 setValue(aValue); |
|
110 } |
|
111 |
|
112 /** |
|
113 * @param duration a duration value |
|
114 */ |
|
115 public Duration(final Dur duration) { |
|
116 super(DURATION, PropertyFactoryImpl.getInstance()); |
|
117 this.duration = duration; |
|
118 } |
|
119 |
|
120 /** |
|
121 * @param aList a list of parameters for this component |
|
122 * @param duration a duration value |
|
123 */ |
|
124 public Duration(final ParameterList aList, final Dur duration) { |
|
125 super(DURATION, aList, PropertyFactoryImpl.getInstance()); |
|
126 setDuration(duration); |
|
127 } |
|
128 |
|
129 /** |
|
130 * Constructs a new duration representing the time between the specified start date and end date. |
|
131 * @param start the starting time for the duration |
|
132 * @param end the end time for the duration |
|
133 */ |
|
134 public Duration(final Date start, final Date end) { |
|
135 super(DURATION, PropertyFactoryImpl.getInstance()); |
|
136 setDuration(new Dur(start, end)); |
|
137 } |
|
138 |
|
139 /** |
|
140 * @return Returns the duration. |
|
141 */ |
|
142 public final Dur getDuration() { |
|
143 return duration; |
|
144 } |
|
145 |
|
146 /** |
|
147 * {@inheritDoc} |
|
148 */ |
|
149 public final void setValue(final String aValue) { |
|
150 // duration = DurationFormat.getInstance().parse(aValue); |
|
151 duration = new Dur(aValue); |
|
152 } |
|
153 |
|
154 /** |
|
155 * {@inheritDoc} |
|
156 */ |
|
157 public final String getValue() { |
|
158 // return DurationFormat.getInstance().format(getDuration()); |
|
159 return duration.toString(); |
|
160 } |
|
161 |
|
162 /** |
|
163 * @param duration The duration to set. |
|
164 */ |
|
165 public final void setDuration(final Dur duration) { |
|
166 this.duration = duration; |
|
167 } |
|
168 |
|
169 /** |
|
170 * {@inheritDoc} |
|
171 */ |
|
172 public final void validate() throws ValidationException { |
|
173 // TODO: Auto-generated method stub |
|
174 } |
|
175 } |