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