1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/net/fortuna/ical4j/model/property/Duration.java Tue Feb 10 18:12:00 2015 +0100 1.3 @@ -0,0 +1,175 @@ 1.4 +/** 1.5 + * Copyright (c) 2012, Ben Fortuna 1.6 + * All rights reserved. 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted provided that the following conditions 1.10 + * are met: 1.11 + * 1.12 + * o Redistributions of source code must retain the above copyright 1.13 + * notice, this list of conditions and the following disclaimer. 1.14 + * 1.15 + * o Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * o Neither the name of Ben Fortuna nor the names of any other contributors 1.20 + * may be used to endorse or promote products derived from this software 1.21 + * without specific prior written permission. 1.22 + * 1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.27 + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.28 + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.29 + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.30 + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.31 + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.32 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.33 + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 + */ 1.35 +package net.fortuna.ical4j.model.property; 1.36 + 1.37 +import java.util.Date; 1.38 + 1.39 +import net.fortuna.ical4j.model.Dur; 1.40 +import net.fortuna.ical4j.model.ParameterList; 1.41 +import net.fortuna.ical4j.model.Property; 1.42 +import net.fortuna.ical4j.model.PropertyFactoryImpl; 1.43 +import net.fortuna.ical4j.model.ValidationException; 1.44 + 1.45 +/** 1.46 + * $Id$ 1.47 + * 1.48 + * Created: [Apr 6, 2004] 1.49 + * 1.50 + * Defines a DURATION iCalendar component property. 1.51 + * 1.52 + * <pre> 1.53 + * 4.3.6 Duration 1.54 + * 1.55 + * Value Name: DURATION 1.56 + * 1.57 + * Purpose: This value type is used to identify properties that contain 1.58 + * a duration of time. 1.59 + * 1.60 + * Formal Definition: The value type is defined by the following 1.61 + * notation: 1.62 + * 1.63 + * dur-value = (["+"] / "-") "P" (dur-date / dur-time / dur-week) 1.64 + * 1.65 + * dur-date = dur-day [dur-time] 1.66 + * dur-time = "T" (dur-hour / dur-minute / dur-second) 1.67 + * dur-week = 1*DIGIT "W" 1.68 + * dur-hour = 1*DIGIT "H" [dur-minute] 1.69 + * dur-minute = 1*DIGIT "M" [dur-second] 1.70 + * dur-second = 1*DIGIT "S" 1.71 + * dur-day = 1*DIGIT "D" 1.72 + * 1.73 + * Description: If the property permits, multiple "duration" values are 1.74 + * specified by a COMMA character (US-ASCII decimal 44) separated list 1.75 + * of values. The format is expressed as the [ISO 8601] basic format for 1.76 + * the duration of time. The format can represent durations in terms of 1.77 + * weeks, days, hours, minutes, and seconds. 1.78 + * 1.79 + * No additional content value encoding (i.e., BACKSLASH character 1.80 + * encoding) are defined for this value type. 1.81 + * 1.82 + * Example: A duration of 15 days, 5 hours and 20 seconds would be: 1.83 + * 1.84 + * P15DT5H0M20S 1.85 + * 1.86 + * A duration of 7 weeks would be: 1.87 + * 1.88 + * P7W 1.89 + * </pre> 1.90 + * 1.91 + * @author Ben Fortuna 1.92 + */ 1.93 +public class Duration extends Property { 1.94 + 1.95 + private static final long serialVersionUID = 9144969653829796798L; 1.96 + 1.97 + private Dur duration; 1.98 + 1.99 + /** 1.100 + * Default constructor. 1.101 + */ 1.102 + public Duration() { 1.103 + super(DURATION, PropertyFactoryImpl.getInstance()); 1.104 + } 1.105 + 1.106 + /** 1.107 + * @param aList a list of parameters for this component 1.108 + * @param aValue a value string for this component 1.109 + */ 1.110 + public Duration(final ParameterList aList, final String aValue) { 1.111 + super(DURATION, aList, PropertyFactoryImpl.getInstance()); 1.112 + setValue(aValue); 1.113 + } 1.114 + 1.115 + /** 1.116 + * @param duration a duration value 1.117 + */ 1.118 + public Duration(final Dur duration) { 1.119 + super(DURATION, PropertyFactoryImpl.getInstance()); 1.120 + this.duration = duration; 1.121 + } 1.122 + 1.123 + /** 1.124 + * @param aList a list of parameters for this component 1.125 + * @param duration a duration value 1.126 + */ 1.127 + public Duration(final ParameterList aList, final Dur duration) { 1.128 + super(DURATION, aList, PropertyFactoryImpl.getInstance()); 1.129 + setDuration(duration); 1.130 + } 1.131 + 1.132 + /** 1.133 + * Constructs a new duration representing the time between the specified start date and end date. 1.134 + * @param start the starting time for the duration 1.135 + * @param end the end time for the duration 1.136 + */ 1.137 + public Duration(final Date start, final Date end) { 1.138 + super(DURATION, PropertyFactoryImpl.getInstance()); 1.139 + setDuration(new Dur(start, end)); 1.140 + } 1.141 + 1.142 + /** 1.143 + * @return Returns the duration. 1.144 + */ 1.145 + public final Dur getDuration() { 1.146 + return duration; 1.147 + } 1.148 + 1.149 + /** 1.150 + * {@inheritDoc} 1.151 + */ 1.152 + public final void setValue(final String aValue) { 1.153 + // duration = DurationFormat.getInstance().parse(aValue); 1.154 + duration = new Dur(aValue); 1.155 + } 1.156 + 1.157 + /** 1.158 + * {@inheritDoc} 1.159 + */ 1.160 + public final String getValue() { 1.161 + // return DurationFormat.getInstance().format(getDuration()); 1.162 + return duration.toString(); 1.163 + } 1.164 + 1.165 + /** 1.166 + * @param duration The duration to set. 1.167 + */ 1.168 + public final void setDuration(final Dur duration) { 1.169 + this.duration = duration; 1.170 + } 1.171 + 1.172 + /** 1.173 + * {@inheritDoc} 1.174 + */ 1.175 + public final void validate() throws ValidationException { 1.176 + // TODO: Auto-generated method stub 1.177 + } 1.178 +}