001package ezvcard.property; 002 003import java.util.Date; 004 005import ezvcard.util.PartialDate; 006 007/* 008 Copyright (c) 2012-2018, 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 * Calendar c = Calendar.getInstance(); 050 * c.clear(); 051 * c.set(Calendar.YEAR, 1912); 052 * c.set(Calendar.MONTH, Calendar.JUNE); 053 * c.set(Calendar.DAY_OF_MONTH, 23); 054 * Birthday bday = new Birthday(c.getTime()); 055 * vcard.setBirthday(bday); 056 * 057 * //partial date (e.g. just the month and date, vCard 4.0 only) 058 * bday = new Birthday(PartialDate.date(null, 6, 23)); //June 23 059 * vcard.setBirthday(bday); 060 * 061 * //plain text value (vCard 4.0 only) 062 * bday = new Birthday("Don't even go there, dude..."); 063 * vcard.setBirthday(bday); 064 * </pre> 065 * 066 * <p> 067 * <b>Code sample (retrieving)</b> 068 * </p> 069 * 070 * <pre class="brush:java"> 071 * VCard vcard = ... 072 * Birthday bday = vcard.getBirthday(); 073 * 074 * Date date = bday.getDate(); 075 * if (date != null) { 076 * //property value is a date 077 * } 078 * 079 * PartialDate partialDate = bday.getPartialDate(); 080 * if (partialDate != null) { 081 * //property value is a partial date 082 * int year = partialDate.getYear(); 083 * int month = partialDate.getMonth(); 084 * } 085 * 086 * String text = bday.getText(); 087 * if (text != null) { 088 * //property value is plain text 089 * } 090 * </pre> 091 * 092 * <p> 093 * <b>Property name:</b> {@code BDAY} 094 * </p> 095 * <p> 096 * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0} 097 * </p> 098 * @author Michael Angstadt 099 * @see <a href="http://tools.ietf.org/html/rfc6350#page-30">RFC 6350 p.30</a> 100 * @see <a href="http://tools.ietf.org/html/rfc2426#page-11">RFC 2426 p.11</a> 101 * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.11</a> 102 */ 103public class Birthday extends DateOrTimeProperty { 104 /** 105 * Creates a birthday property. 106 * @param date the birthday 107 */ 108 public Birthday(Date date) { 109 super(date); 110 } 111 112 /** 113 * Creates a birthday property. 114 * @param date the birthday 115 * @param hasTime true to include the date's time component, false if it's 116 * strictly a date 117 */ 118 public Birthday(Date date, boolean hasTime) { 119 super(date, hasTime); 120 } 121 122 /** 123 * Creates a birthday property. 124 * @param partialDate the birthday (vCard 4.0 only) 125 */ 126 public Birthday(PartialDate partialDate) { 127 super(partialDate); 128 } 129 130 /** 131 * Creates a birthday property. 132 * @param text the text value (vCard 4.0 only) 133 */ 134 public Birthday(String text) { 135 super(text); 136 } 137 138 /** 139 * Copy constructor. 140 * @param original the property to make a copy of 141 */ 142 public Birthday(Birthday original) { 143 super(original); 144 } 145 146 @Override 147 public Birthday copy() { 148 return new Birthday(this); 149 } 150}