All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.cnr.iit.jscontact.tools.dto.AnniversaryDate Maven / Gradle / Ivy

Go to download

Java tools for JSContact building, validation, serialization/deserialization and conversion from vCard 4.0 (RFC6350) and its transliterations, namely xCard (RFC6351) and jCard (RFC7095).

There is a newer version: 1.0.1
Show newest version
package it.cnr.iit.jscontact.tools.dto;

import it.cnr.iit.jscontact.tools.constraints.NotNullAnyConstraint;
import it.cnr.iit.jscontact.tools.dto.utils.DateUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * Class mapping the "date" property values of the Anniversary type as defined in section 2.8.1 of [draft-ietf-calext-jscontact].
 *
 * @see draft-ietf-calext-jscontact
 * @author Mario Loffredo
 */
@NotNullAnyConstraint(fieldNames = {"date", "partialDate"}, message = "at least one not null member between date and partialDate is required in AnniversaryDate")
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AnniversaryDate implements Serializable {

    Timestamp date;
    PartialDate partialDate;

    /**
     * Tests if this annivesary date is equal to the given date in text format.
     *
     * @param text the date in text format
     * @return true if this anniversary date is equal to the given date in text format, false otherwise
     * @see draft-ietf-calext-jscontact
     */
    public boolean isEqual(String text) {

        if (this.date != null)
          return (this.date.getUtc().compareTo(DateUtils.toCalendar(text))==0);
        else
          return DateUtils.toJSContactPartialDateText(partialDate).equals(text);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy