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