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;
35
36 import java.text.ParseException;
37 import java.util.Date;
38
39 import net.fortuna.ical4j.util.DateTimeFormat;
40 import net.fortuna.ical4j.util.DurationFormat;
41
42 /***
43 * Defines a period of time.
44 *
45 * @author benf
46 */
47 public class Period {
48
49 private Date start;
50
51 private Date end;
52
53 private long duration;
54
55 /***
56 * Constructor.
57 * @param aValue a string representation of a period
58 * @throws ParseException where the specified string is
59 * not a valid representation
60 */
61 public Period(final String aValue) throws ParseException {
62
63 start = DateTimeFormat.getInstance().parse(aValue.substring(0,
64 aValue.indexOf('/') - 1));
65
66
67 try {
68
69 end = DateTimeFormat.getInstance()
70 .parse(aValue.substring(aValue.indexOf('/')));
71 }
72 catch (ParseException pe) {
73
74 duration = DurationFormat.getInstance().parse(aValue);
75 }
76 }
77
78 /***
79 * @return Returns the duration.
80 */
81 public final long getDuration() {
82 return duration;
83 }
84
85 /***
86 * @return Returns the end.
87 */
88 public final Date getEnd() {
89 return end;
90 }
91
92 /***
93 * @return Returns the start.
94 */
95 public final Date getStart() {
96 return start;
97 }
98
99 /***
100 * @see java.lang.Object#toString()
101 */
102 public final String toString() {
103 StringBuffer b = new StringBuffer();
104
105 b.append(DateTimeFormat.getInstance().format(start));
106 b.append('/');
107
108 if (end != null) {
109 b.append(DateTimeFormat.getInstance().format(end));
110 }
111 else {
112 b.append(DurationFormat.getInstance().format(duration));
113 }
114
115 return b.toString();
116 }
117 }