001package biweekly.property;
002
003import java.util.Date;
004
005import biweekly.util.DateTimeComponents;
006
007/*
008 Copyright (c) 2013, Michael Angstadt
009 All rights reserved.
010
011 Redistribution and use in source and binary forms, with or without
012 modification, are permitted provided that the following conditions are met: 
013
014 1. Redistributions of source code must retain the above copyright notice, this
015 list of conditions and the following disclaimer. 
016 2. Redistributions in binary form must reproduce the above copyright notice,
017 this list of conditions and the following disclaimer in the documentation
018 and/or other materials provided with the distribution. 
019
020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
023 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
024 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
027 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030 */
031
032/**
033 * <p>
034 * Defines the due date of a to-do task.
035 * </p>
036 * 
037 * <p>
038 * <b>Code sample (creating):</b>
039 * 
040 * <pre class="brush:java">
041 * VTodo todo = new VTodo();
042 * 
043 * //date and time
044 * Date datetime = ...
045 * DateDue due = new DateDue(datetime);
046 * todo.setDateDue(due);
047 * 
048 * //date (without time component)
049 * Date date = ...
050 * due = new DateDue(date, false);
051 * todo.setDateDue(due);
052 * 
053 * //date and time with timezone (Date object converted to the specified timezone when writing the iCalendar object)
054 * Date datetime = ... 
055 * due = new DateDue(datetime); 
056 * due.setTimezoneId("America/New_York");
057 * todo.setDateDue(due);
058 * 
059 * //raw date/time components 
060 * DateTimeComponents components = new DateTimeComponents(1999, 4, 4, 2, 0, 0, false);
061 * due = new DateDue(components);
062 * todo.setDateDue(due);
063 * </pre>
064 * 
065 * </p>
066 * 
067 * <b>Code sample (retrieving):</b>
068 * 
069 * <pre class="brush:java">
070 * ICalendar ical = ...
071 * for (VTodo todo : ical.getTodos()){
072 *   DateDue due = todo.getDateDue();
073 *   
074 *   //get the raw date/time components from the date string
075 *   DateTimeComponents components = due.getRawComponents();
076 *   int year = components.getYear();
077 *   int month = components.getMonth();
078 *   //etc.
079 *   
080 *   //get the Java Date object that was generated based on the provided timezone
081 *   Date value = due.getValue();
082 *   
083 *   if (due.hasTime()){
084 *     //the value includes a time component
085 *     
086 *     if (due.isLocalTime()){
087 *       //timezone information was not provided
088 *       //Java Date object was parsed under the local computer's default timezone
089 *     } else {
090 *       //timezone information was provided
091 *       //Java Date object was parsed under the provided timezone (if recognized)
092 *     }
093 *   } else {
094 *     //the value is just a date
095 *     //Java Date object's time is set to "00:00:00" under the local computer's default timezone
096 *   }
097 * }
098 * </pre>
099 * 
100 * </p>
101 * @author Michael Angstadt
102 * @see <a href="http://tools.ietf.org/html/rfc5545#page-96">RFC 5545 p.96-7</a>
103 */
104public class DateDue extends DateOrDateTimeProperty {
105        /**
106         * Creates a due date property.
107         * @param dueDate the due date
108         */
109        public DateDue(Date dueDate) {
110                this(dueDate, true);
111        }
112
113        /**
114         * Creates a due date property.
115         * @param dueDate the due date
116         * @param hasTime true to include the time component of the date, false not
117         * to
118         */
119        public DateDue(Date dueDate, boolean hasTime) {
120                super(dueDate, hasTime);
121        }
122
123        /**
124         * Creates an due date property.
125         * @param components the raw components of the date-time value
126         */
127        public DateDue(DateTimeComponents components) {
128                super(components);
129        }
130}