001package ezvcard.property; 002 003import java.time.temporal.Temporal; 004 005import ezvcard.SupportedVersions; 006import ezvcard.VCardVersion; 007import ezvcard.util.PartialDate; 008 009/* 010 Copyright (c) 2012-2023, 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 * LocalDate date = LocalDate.of(1970, 3, 21); 052 * Anniversary anniversary = new Anniversary(date); 053 * vcard.setAnniversary(anniversary); 054 * 055 * //partial date (e.g. just the month and date) 056 * PartialDate date = PartialDate.date(null, 3, 21); 057 * anniversary = new Anniversary(date); //March 21 058 * vcard.setAnniversary(anniversary); 059 * 060 * //plain text value 061 * anniversary = new Anniversary("Over 20 years ago!"); 062 * vcard.setAnniversary(anniversary); 063 * </pre> 064 * 065 * <p> 066 * <b>Code sample (retrieving)</b> 067 * </p> 068 * 069 * <pre class="brush:java"> 070 * VCard vcard = ... 071 * Anniversary anniversary = vcard.getAnniversary(); 072 * 073 * Temporal date = anniversary.getDate(); 074 * if (date != null) { 075 * //property value is a date 076 * } 077 * 078 * PartialDate partialDate = anniversary.getPartialDate(); 079 * if (partialDate != null) { 080 * //property value is a partial date 081 * int year = partialDate.getYear(); 082 * int month = partialDate.getMonth(); 083 * } 084 * 085 * String text = anniversary.getText(); 086 * if (text != null) { 087 * //property value is plain text 088 * } 089 * </pre> 090 * 091 * <p> 092 * <b>Property name:</b> {@code ANNIVERSARY} 093 * </p> 094 * <p> 095 * <b>Supported versions:</b> {@code 4.0} 096 * </p> 097 * @author Michael Angstadt 098 * @see <a href="http://tools.ietf.org/html/rfc6350#page-31">RFC 6350 p.31</a> 099 */ 100@SupportedVersions(VCardVersion.V4_0) 101public class Anniversary extends DateOrTimeProperty { 102 /** 103 * Creates an anniversary property. 104 * @param date the anniversary date 105 */ 106 public Anniversary(Temporal date) { 107 super(date); 108 } 109 110 /** 111 * Creates an anniversary property. 112 * @param partialDate the partial anniversary date (vCard 4.0 only) 113 */ 114 public Anniversary(PartialDate partialDate) { 115 super(partialDate); 116 } 117 118 /** 119 * Creates an anniversary property. 120 * @param text the text value (vCard 4.0 only) 121 */ 122 public Anniversary(String text) { 123 super(text); 124 } 125 126 /** 127 * Copy constructor. 128 * @param original the property to make a copy of 129 */ 130 public Anniversary(Anniversary original) { 131 super(original); 132 } 133 134 @Override 135 public Anniversary copy() { 136 return new Anniversary(this); 137 } 138}