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