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 start date of an event, free/busy component, or timezone 035 * component. 036 * </p> 037 * 038 * <p> 039 * <b>Code sample (creating):</b> 040 * 041 * <pre class="brush:java"> 042 * VEvent event = new VEvent(); 043 * 044 * //date and time 045 * Date datetime = ... 046 * DateStart dtstart = new DateStart(datetime); 047 * event.setDateStart(dtstart); 048 * 049 * //date (without time component) 050 * Date date = ... 051 * dtstart = new DateStart(date, false); 052 * event.setDateStart(dtstart); 053 * 054 * //date and time with timezone (Date object converted to the specified timezone when writing the iCalendar object) 055 * Date datetime = ... 056 * dtstart = new DateStart(datetime); 057 * dtstart.setTimezoneId("America/New_York"); 058 * event.setDateStart(dtstart); 059 * 060 * //raw date/time components 061 * DateTimeComponents components = new DateTimeComponents(1999, 4, 4, 2, 0, 0, false); 062 * dtstart = new DateStart(components); 063 * event.setDateStart(dtstart); 064 * </pre> 065 * 066 * </p> 067 * 068 * <b>Code sample (retrieving):</b> 069 * 070 * <pre class="brush:java"> 071 * ICalendar ical = ... 072 * for (VEvent event : ical.getEvents()){ 073 * DateStart dtstart = event.getDateStart(); 074 * 075 * //get the raw date/time components from the date string 076 * DateTimeComponents components = dtstart.getRawComponents(); 077 * int year = components.getYear(); 078 * int month = components.getMonth(); 079 * //etc. 080 * 081 * //get the Java Date object that was generated based on the provided timezone 082 * Date value = dtstart.getValue(); 083 * 084 * if (dtstart.hasTime()){ 085 * //the value includes a time component 086 * 087 * if (dtstart.isLocalTime()){ 088 * //timezone information was not provided 089 * //Java Date object was parsed under the local computer's default timezone 090 * } else { 091 * //timezone information was provided 092 * //Java Date object was parsed under the provided timezone (if recognized) 093 * } 094 * } else { 095 * //the value is just a date 096 * //Java Date object's time is set to "00:00:00" under the local computer's default timezone 097 * } 098 * } 099 * </pre> 100 * 101 * </p> 102 * @author Michael Angstadt 103 * @see <a href="http://tools.ietf.org/html/rfc5545#page-97">RFC 5545 p.97-8</a> 104 */ 105public class DateStart extends DateOrDateTimeProperty { 106 /** 107 * Creates a start date property. 108 * @param startDate the start date 109 */ 110 public DateStart(Date startDate) { 111 this(startDate, true); 112 } 113 114 /** 115 * Creates a start date property. 116 * @param startDate the start date 117 * @param hasTime true to include the time component of the date, false not 118 * to 119 */ 120 public DateStart(Date startDate, boolean hasTime) { 121 super(startDate, hasTime); 122 } 123 124 /** 125 * Creates a start date property. 126 * @param components the raw components of the date-time value 127 */ 128 public DateStart(DateTimeComponents components) { 129 super(components); 130 } 131}