001 package ezvcard.property;
002
003 import java.util.Date;
004
005 import ezvcard.util.PartialDate;
006
007 /*
008 Copyright (c) 2013, 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 * Defines the person's birthday.
038 *
039 * <p>
040 * <b>Setting the birthday</b>
041 * </p>
042 *
043 * <pre class="brush:java">
044 * VCard vcard = new VCard();
045 *
046 * //complete date
047 * Calendar c = Calendar.getInstance();
048 * c.set(Calendar.YEAR, 1986);
049 * c.set(Calendar.MONTH, Calendar.MARCH);
050 * c.set(Calendar.DAY_OF_MONTH, 21);
051 * Birthday bday = new Birthday();
052 * bday.setDate(c.getTime(), false);
053 * vcard.setBirthday(bday);
054 *
055 * //reduced accuracy date (vCard 4.0 only, see RFC 6350 p.12-14 for examples)
056 * bday = new Birthday();
057 * bday.setPartialDate(PartialDate.date(null, 3, 21)); //March 21
058 * vcard.setBirthday(bday);
059 *
060 * //plain text value (vCard 4.0 only)
061 * bday = new Birthday();
062 * bday.setText("a long time ago");
063 * vcard.setBirthday(bday);
064 * </pre>
065 *
066 * <p>
067 * <b>Getting the birthday</b>
068 * </p>
069 *
070 * <pre class="brush:java">
071 * VCard vcard = ...
072 * Birthday bday = vcard.getBirthday();
073 * if (bday != null){
074 * if (bday.getDate() != null){
075 * System.out.println(bday.getDate());
076 * } else if (bday.getPartialDate() != null){
077 * System.out.println("Year: " + bday.getPartialDate().getYear());
078 * System.out.println("Month: " + bday.getPartialDate().getMonth());
079 * //...
080 * } else if (bday.getText() != null){
081 * System.out.println(bday.getText());
082 * }
083 * }
084 * </pre>
085 *
086 * <p>
087 * <b>Property name:</b> {@code BDAY}
088 * </p>
089 * <p>
090 * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
091 * </p>
092 * @author Michael Angstadt
093 */
094 public class Birthday extends DateOrTimeProperty {
095 /**
096 * Creates a birthday property.
097 * @param date the birthday
098 */
099 public Birthday(Date date) {
100 super(date);
101 }
102
103 /**
104 * Creates a birthday property.
105 * @param date the birthday
106 * @param hasTime true to include the date's time component, false if it's
107 * strictly a date
108 */
109 public Birthday(Date date, boolean hasTime) {
110 super(date, hasTime);
111 }
112
113 /**
114 * Creates a birthday property.
115 * @param partialDate the birthday (vCard 4.0 only)
116 */
117 public Birthday(PartialDate partialDate) {
118 super(partialDate);
119 }
120
121 /**
122 * Creates a birthday property.
123 * @param text the text value (vCard 4.0 only)
124 */
125 public Birthday(String text) {
126 super(text);
127 }
128 }