| 1 | package ezvcard.property; |
| 2 | |
| 3 | import java.time.temporal.Temporal; |
| 4 | |
| 5 | import ezvcard.SupportedVersions; |
| 6 | import ezvcard.VCardVersion; |
| 7 | import ezvcard.util.PartialDate; |
| 8 | |
| 9 | /* |
| 10 | Copyright (c) 2012-2023, Michael Angstadt |
| 11 | All rights reserved. |
| 12 | |
| 13 | Redistribution and use in source and binary forms, with or without |
| 14 | modification, are permitted provided that the following conditions are met: |
| 15 | |
| 16 | 1. Redistributions of source code must retain the above copyright notice, this |
| 17 | list of conditions and the following disclaimer. |
| 18 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 19 | this list of conditions and the following disclaimer in the documentation |
| 20 | and/or other materials provided with the distribution. |
| 21 | |
| 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 29 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | |
| 33 | The views and conclusions contained in the software and documentation are those |
| 34 | of the authors and should not be interpreted as representing official policies, |
| 35 | either expressed or implied, of the FreeBSD Project. |
| 36 | */ |
| 37 | |
| 38 | /** |
| 39 | * <p> |
| 40 | * Defines the person's time of death. |
| 41 | * </p> |
| 42 | * |
| 43 | * <p> |
| 44 | * <b>Code sample (creating)</b> |
| 45 | * </p> |
| 46 | * |
| 47 | * <pre class="brush:java"> |
| 48 | * VCard vcard = new VCard(); |
| 49 | * |
| 50 | * //date |
| 51 | * LocalDate date = LocalDate.of(1954, 6, 7); |
| 52 | * Deathdate deathdate = new Deathdate(date); |
| 53 | * vcard.setDeathdate(deathdate); |
| 54 | * |
| 55 | * //partial date (e.g. just the month and date) |
| 56 | * deathdate = new Deathdate(PartialDate.date(null, 6, 7)); //June 7 |
| 57 | * vcard.setDeathdate(deathdate); |
| 58 | * |
| 59 | * //plain text value |
| 60 | * deathdate = new Deathdate("In the 1950s"); |
| 61 | * vcard.setDeathdate(deathdate); |
| 62 | * </pre> |
| 63 | * |
| 64 | * <p> |
| 65 | * <b>Code sample (retrieving)</b> |
| 66 | * </p> |
| 67 | * |
| 68 | * <pre class="brush:java"> |
| 69 | * VCard vcard = ... |
| 70 | * Deathdate deathdate = vcard.getDeathdate(); |
| 71 | * |
| 72 | * Temporal date = deathdate.getDate(); |
| 73 | * if (date != null) { |
| 74 | * //property value is a date |
| 75 | * } |
| 76 | * |
| 77 | * PartialDate partialDate = deathdate.getPartialDate(); |
| 78 | * if (partialDate != null) { |
| 79 | * //property value is a partial date |
| 80 | * int year = partialDate.getYear(); |
| 81 | * int month = partialDate.getMonth(); |
| 82 | * } |
| 83 | * |
| 84 | * String text = deathdate.getText(); |
| 85 | * if (text != null) { |
| 86 | * //property value is plain text |
| 87 | * } |
| 88 | * </pre> |
| 89 | * |
| 90 | * <p> |
| 91 | * <b>Property name:</b> {@code DEATHDATE} |
| 92 | * </p> |
| 93 | * <p> |
| 94 | * <b>Supported versions:</b> {@code 4.0} |
| 95 | * </p> |
| 96 | * @author Michael Angstadt |
| 97 | * @see <a href="http://tools.ietf.org/html/rfc6474#page-4">RFC 6474 p.4</a> |
| 98 | */ |
| 99 | @SupportedVersions(VCardVersion.V4_0) |
| 100 | public class Deathdate extends DateOrTimeProperty { |
| 101 | /** |
| 102 | * Creates a deathdate property. |
| 103 | * @param date the deathdate |
| 104 | */ |
| 105 | public Deathdate(Temporal date) { |
| 106 | super(date); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Creates a deathdate property. |
| 111 | * @param partialDate the deathdate (vCard 4.0 only) |
| 112 | */ |
| 113 | public Deathdate(PartialDate partialDate) { |
| 114 | super(partialDate); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Creates a deathdate property. |
| 119 | * @param text the text value (vCard 4.0 only) |
| 120 | */ |
| 121 | public Deathdate(String text) { |
| 122 | super(text); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Copy constructor. |
| 127 | * @param original the property to make a copy of |
| 128 | */ |
| 129 | public Deathdate(Deathdate original) { |
| 130 | super(original); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public Deathdate copy() { |
| 135 | return new Deathdate(this); |
| 136 | } |
| 137 | } |