001package ezvcard.property;
002
003import java.util.Date;
004
005import ezvcard.SupportedVersions;
006import ezvcard.VCardVersion;
007import ezvcard.util.PartialDate;
008
009/*
010 Copyright (c) 2012-2018, Michael Angstadt
011 All rights reserved.
012
013 Redistribution and use in source and binary forms, with or without
014 modification, are permitted provided that the following conditions are met: 
015
016 1. Redistributions of source code must retain the above copyright notice, this
017 list of conditions and the following disclaimer. 
018 2. Redistributions in binary form must reproduce the above copyright notice,
019 this list of conditions and the following disclaimer in the documentation
020 and/or other materials provided with the distribution. 
021
022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
023 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
024 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
025 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
026 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
027 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
028 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
029 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
031 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
032
033 The views and conclusions contained in the software and documentation are those
034 of the authors and should not be interpreted as representing official policies, 
035 either expressed or implied, of the FreeBSD Project.
036 */
037
038/**
039 * <p>
040 * Defines the person's anniversary (marital or work-related).
041 * </p>
042 * 
043 * <p>
044 * <b>Code sample (creating)</b>
045 * </p>
046 * 
047 * <pre class="brush:java">
048 * VCard vcard = new VCard();
049 * 
050 * //date
051 * Calendar c = Calendar.getInstance();
052 * c.clear();
053 * c.set(Calendar.YEAR, 1970);
054 * c.set(Calendar.MONTH, Calendar.MARCH);
055 * c.set(Calendar.DAY_OF_MONTH, 21);
056 * Anniversary anniversary = new Anniversary(c.getTime());
057 * vcard.setAnniversary(anniversary);
058 * 
059 * //partial date (e.g. just the month and date)
060 * PartialDate date = PartialDate.date(null, 3, 21);
061 * anniversary = new Anniversary(date); //March 21
062 * vcard.setAnniversary(anniversary);
063 * 
064 * //plain text value
065 * anniversary = new Anniversary("Over 20 years ago!");
066 * vcard.setAnniversary(anniversary);
067 * </pre>
068 * 
069 * <p>
070 * <b>Code sample (retrieving)</b>
071 * </p>
072 * 
073 * <pre class="brush:java">
074 * VCard vcard = ...
075 * Anniversary anniversary = vcard.getAnniversary();
076 * 
077 * Date date = anniversary.getDate();
078 * if (date != null) {
079 *   //property value is a date
080 * }
081 * 
082 * PartialDate partialDate = anniversary.getPartialDate();
083 * if (partialDate != null) {
084 *   //property value is a partial date
085 *   int year = partialDate.getYear();
086 *   int month = partialDate.getMonth();
087 * }
088 * 
089 * String text = anniversary.getText();
090 * if (text != null) {
091 *   //property value is plain text
092 * }
093 * </pre>
094 * 
095 * <p>
096 * <b>Property name:</b> {@code ANNIVERSARY}
097 * </p>
098 * <p>
099 * <b>Supported versions:</b> {@code 4.0}
100 * </p>
101 * @author Michael Angstadt
102 * @see <a href="http://tools.ietf.org/html/rfc6350#page-31">RFC 6350 p.31</a>
103 */
104@SupportedVersions(VCardVersion.V4_0)
105public class Anniversary extends DateOrTimeProperty {
106        /**
107         * Creates an anniversary property.
108         * @param date the anniversary date
109         */
110        public Anniversary(Date date) {
111                super(date);
112        }
113
114        /**
115         * Creates an anniversary property.
116         * @param date the anniversary date
117         * @param hasTime true to include the date's time component, false if it's
118         * strictly a date
119         */
120        public Anniversary(Date date, boolean hasTime) {
121                super(date, hasTime);
122        }
123
124        /**
125         * Creates an anniversary property.
126         * @param partialDate the partial anniversary date (vCard 4.0 only)
127         */
128        public Anniversary(PartialDate partialDate) {
129                super(partialDate);
130        }
131
132        /**
133         * Creates an anniversary property.
134         * @param text the text value (vCard 4.0 only)
135         */
136        public Anniversary(String text) {
137                super(text);
138        }
139
140        /**
141         * Copy constructor.
142         * @param original the property to make a copy of
143         */
144        public Anniversary(Anniversary original) {
145                super(original);
146        }
147
148        @Override
149        public Anniversary copy() {
150                return new Anniversary(this);
151        }
152}