001package ezvcard.property;
002
003import java.time.temporal.Temporal;
004
005import ezvcard.util.PartialDate;
006
007/*
008 Copyright (c) 2012-2023, Michael Angstadt
009 All rights reserved.
010
011 Redistribution and use in source and binary forms, with or without
012 modification, are permitted provided that the following conditions are met: 
013
014 1. Redistributions of source code must retain the above copyright notice, this
015 list of conditions and the following disclaimer. 
016 2. Redistributions in binary form must reproduce the above copyright notice,
017 this list of conditions and the following disclaimer in the documentation
018 and/or other materials provided with the distribution. 
019
020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
023 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
024 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
027 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030
031 The views and conclusions contained in the software and documentation are those
032 of the authors and should not be interpreted as representing official policies, 
033 either expressed or implied, of the FreeBSD Project.
034 */
035
036/**
037 * <p>
038 * Defines the person's birthday.
039 * </p>
040 * 
041 * <p>
042 * <b>Code sample (creating)</b>
043 * </p>
044 * 
045 * <pre class="brush:java">
046 * VCard vcard = new VCard();
047 * 
048 * //date
049 * LocalDate date = LocalDate.of(1912, 6, 23);
050 * Birthday bday = new Birthday(date);
051 * vcard.setBirthday(bday);
052 * 
053 * //partial date (e.g. just the month and date, vCard 4.0 only)
054 * bday = new Birthday(PartialDate.date(null, 6, 23)); //June 23
055 * vcard.setBirthday(bday);
056 * 
057 * //plain text value (vCard 4.0 only)
058 * bday = new Birthday("Don't even go there, dude...");
059 * vcard.setBirthday(bday);
060 * </pre>
061 * 
062 * <p>
063 * <b>Code sample (retrieving)</b>
064 * </p>
065 * 
066 * <pre class="brush:java">
067 * VCard vcard = ...
068 * Birthday bday = vcard.getBirthday();
069 * 
070 * Temporal date = bday.getDate();
071 * if (date != null) {
072 *   //property value is a date
073 * }
074 * 
075 * PartialDate partialDate = bday.getPartialDate();
076 * if (partialDate != null) {
077 *   //property value is a partial date
078 *   int year = partialDate.getYear();
079 *   int month = partialDate.getMonth();
080 * }
081 * 
082 * String text = bday.getText();
083 * if (text != null) {
084 *   //property value is plain text
085 * }
086 * </pre>
087 * 
088 * <p>
089 * <b>Property name:</b> {@code BDAY}
090 * </p>
091 * <p>
092 * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
093 * </p>
094 * @author Michael Angstadt
095 * @see <a href="http://tools.ietf.org/html/rfc6350#page-30">RFC 6350 p.30</a>
096 * @see <a href="http://tools.ietf.org/html/rfc2426#page-11">RFC 2426 p.11</a>
097 * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.11</a>
098 */
099public 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}