| 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 anniversary (marital or work-related). |
| 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(1970, 3, 21); |
| 52 | * Anniversary anniversary = new Anniversary(date); |
| 53 | * vcard.setAnniversary(anniversary); |
| 54 | * |
| 55 | * //partial date (e.g. just the month and date) |
| 56 | * PartialDate date = PartialDate.date(null, 3, 21); |
| 57 | * anniversary = new Anniversary(date); //March 21 |
| 58 | * vcard.setAnniversary(anniversary); |
| 59 | * |
| 60 | * //plain text value |
| 61 | * anniversary = new Anniversary("Over 20 years ago!"); |
| 62 | * vcard.setAnniversary(anniversary); |
| 63 | * </pre> |
| 64 | * |
| 65 | * <p> |
| 66 | * <b>Code sample (retrieving)</b> |
| 67 | * </p> |
| 68 | * |
| 69 | * <pre class="brush:java"> |
| 70 | * VCard vcard = ... |
| 71 | * Anniversary anniversary = vcard.getAnniversary(); |
| 72 | * |
| 73 | * Temporal date = anniversary.getDate(); |
| 74 | * if (date != null) { |
| 75 | * //property value is a date |
| 76 | * } |
| 77 | * |
| 78 | * PartialDate partialDate = anniversary.getPartialDate(); |
| 79 | * if (partialDate != null) { |
| 80 | * //property value is a partial date |
| 81 | * int year = partialDate.getYear(); |
| 82 | * int month = partialDate.getMonth(); |
| 83 | * } |
| 84 | * |
| 85 | * String text = anniversary.getText(); |
| 86 | * if (text != null) { |
| 87 | * //property value is plain text |
| 88 | * } |
| 89 | * </pre> |
| 90 | * |
| 91 | * <p> |
| 92 | * <b>Property name:</b> {@code ANNIVERSARY} |
| 93 | * </p> |
| 94 | * <p> |
| 95 | * <b>Supported versions:</b> {@code 4.0} |
| 96 | * </p> |
| 97 | * @author Michael Angstadt |
| 98 | * @see <a href="http://tools.ietf.org/html/rfc6350#page-31">RFC 6350 p.31</a> |
| 99 | */ |
| 100 | @SupportedVersions(VCardVersion.V4_0) |
| 101 | public class Anniversary extends DateOrTimeProperty { |
| 102 | /** |
| 103 | * Creates an anniversary property. |
| 104 | * @param date the anniversary date |
| 105 | */ |
| 106 | public Anniversary(Temporal date) { |
| 107 | super(date); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Creates an anniversary property. |
| 112 | * @param partialDate the partial anniversary date (vCard 4.0 only) |
| 113 | */ |
| 114 | public Anniversary(PartialDate partialDate) { |
| 115 | super(partialDate); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Creates an anniversary property. |
| 120 | * @param text the text value (vCard 4.0 only) |
| 121 | */ |
| 122 | public Anniversary(String text) { |
| 123 | super(text); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Copy constructor. |
| 128 | * @param original the property to make a copy of |
| 129 | */ |
| 130 | public Anniversary(Anniversary original) { |
| 131 | super(original); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public Anniversary copy() { |
| 136 | return new Anniversary(this); |
| 137 | } |
| 138 | } |