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 end date of an event or free/busy component. 035 * </p> 036 * 037 * <p> 038 * <b>Code sample (creating):</b> 039 * 040 * <pre class="brush:java"> 041 * VEvent event = new VEvent(); 042 * 043 * //date and time 044 * Date datetime = ... 045 * DateEnd dtend = new DateEnd(datetime); 046 * event.setDateEnd(dtend); 047 * 048 * //date (without time component) 049 * Date date = ... 050 * dtend = new DateEnd(date, false); 051 * event.setDateEnd(dtend); 052 * 053 * //date and time with timezone (Date object converted to the specified timezone when writing the iCalendar object) 054 * Date datetime = ... 055 * dtend = new DateEnd(datetime); 056 * dtend.setTimezoneId("America/New_York"); 057 * event.setDateEnd(dtend); 058 * 059 * //raw date/time components 060 * DateTimeComponents components = new DateTimeComponents(1999, 4, 4, 2, 0, 0, false); 061 * dtend = new DateEnd(components); 062 * event.setDateEnd(dtend); 063 * </pre> 064 * 065 * </p> 066 * 067 * <b>Code sample (retrieving):</b> 068 * 069 * <pre class="brush:java"> 070 * ICalendar ical = ... 071 * for (VEvent event : ical.getEvents()){ 072 * DateEnd dtend = event.getDateEnd(); 073 * 074 * //get the raw date/time components from the date string 075 * DateTimeComponents components = dtend.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 = dtend.getValue(); 082 * 083 * if (dtend.hasTime()){ 084 * //the value includes a time component 085 * 086 * if (dtend.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-95">RFC 5545 p.95-6</a> 103 */ 104public class DateEnd extends DateOrDateTimeProperty { 105 /** 106 * Creates an end date property. 107 * @param endDate the end date 108 */ 109 public DateEnd(Date endDate) { 110 this(endDate, true); 111 } 112 113 /** 114 * Creates an end date property. 115 * @param endDate the end date 116 * @param hasTime true to include the time component of the date, false not 117 * to 118 */ 119 public DateEnd(Date endDate, boolean hasTime) { 120 super(endDate, hasTime); 121 } 122 123 /** 124 * Creates an end date property. 125 * @param components the raw components of the date-time value 126 */ 127 public DateEnd(DateTimeComponents components) { 128 super(components); 129 } 130}