001package ezvcard.property;
002
003import java.util.Date;
004
005import ezvcard.SupportedVersions;
006import ezvcard.VCardVersion;
007import ezvcard.util.PartialDate;
008
009/*
010 Copyright (c) 2012-2018, Michael Angstadt
011 All rights reserved.
012
013 Redistribution and use in source and binary forms, with or without
014 modification, are permitted provided that the following conditions are met: 
015
016 1. Redistributions of source code must retain the above copyright notice, this
017 list of conditions and the following disclaimer. 
018 2. Redistributions in binary form must reproduce the above copyright notice,
019 this list of conditions and the following disclaimer in the documentation
020 and/or other materials provided with the distribution. 
021
022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
023 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
024 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
025 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
026 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
027 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
028 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
029 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
031 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032
033 The views and conclusions contained in the software and documentation are those
034 of the authors and should not be interpreted as representing official policies, 
035 either expressed or implied, of the FreeBSD Project.
036 */
037
038/**
039 * <p>
040 * Defines the person's time of death.
041 * </p>
042 * 
043 * <p>
044 * <b>Code sample (creating)</b>
045 * </p>
046 * 
047 * <pre class="brush:java">
048 * VCard vcard = new VCard();
049 * 
050 * //date
051 * Calendar c = Calendar.getInstance();
052 * c.clear();
053 * c.set(Calendar.YEAR, 1954);
054 * c.set(Calendar.MONTH, Calendar.JUNE);
055 * c.set(Calendar.DAY_OF_MONTH, 7);
056 * Deathdate deathdate = new Deathdate(c.getTime());
057 * vcard.setDeathdate(deathdate);
058 * 
059 * //partial date (e.g. just the month and date)
060 * deathdate = new Deathdate(PartialDate.date(null, 6, 7)); //June 7
061 * vcard.setDeathdate(deathdate);
062 * 
063 * //plain text value
064 * deathdate = new Deathdate("In the 1950s");
065 * vcard.setDeathdate(deathdate);
066 * </pre>
067 * 
068 * <p>
069 * <b>Code sample (retrieving)</b>
070 * </p>
071 * 
072 * <pre class="brush:java">
073 * VCard vcard = ...
074 * Deathdate deathdate = vcard.getDeathdate();
075 * 
076 * Date date = deathdate.getDate();
077 * if (date != null) {
078 *   //property value is a date
079 * }
080 * 
081 * PartialDate partialDate = deathdate.getPartialDate();
082 * if (partialDate != null) {
083 *   //property value is a partial date
084 *   int year = partialDate.getYear();
085 *   int month = partialDate.getMonth();
086 * }
087 * 
088 * String text = deathdate.getText();
089 * if (text != null) {
090 *   //property value is plain text
091 * }
092 * </pre>
093 * 
094 * <p>
095 * <b>Property name:</b> {@code DEATHDATE}
096 * </p>
097 * <p>
098 * <b>Supported versions:</b> {@code 4.0}
099 * </p>
100 * @author Michael Angstadt
101 * @see <a href="http://tools.ietf.org/html/rfc6474#page-4">RFC 6474 p.4</a>
102 */
103@SupportedVersions(VCardVersion.V4_0)
104public class Deathdate extends DateOrTimeProperty {
105        /**
106         * Creates a deathdate property.
107         * @param date the deathdate
108         */
109        public Deathdate(Date date) {
110                super(date);
111        }
112
113        /**
114         * Creates a deathdate property.
115         * @param date the deathdate
116         * @param hasTime true to include the date's time component, false if it's
117         * strictly a date
118         */
119        public Deathdate(Date date, boolean hasTime) {
120                super(date, hasTime);
121        }
122
123        /**
124         * Creates a deathdate property.
125         * @param partialDate the deathdate (vCard 4.0 only)
126         */
127        public Deathdate(PartialDate partialDate) {
128                super(partialDate);
129        }
130
131        /**
132         * Creates a deathdate property.
133         * @param text the text value (vCard 4.0 only)
134         */
135        public Deathdate(String text) {
136                super(text);
137        }
138
139        /**
140         * Copy constructor.
141         * @param original the property to make a copy of
142         */
143        public Deathdate(Deathdate original) {
144                super(original);
145        }
146
147        @Override
148        public Deathdate copy() {
149                return new Deathdate(this);
150        }
151}