package org.example;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateMapper {

	public static Date map(XMLGregorianCalendar calendar) {
		try {
			return calendar.toGregorianCalendar().getTime();
		} catch (Exception ex) {
			return null;
		}
	}

	public static XMLGregorianCalendar map(Date date) {
		try {
			GregorianCalendar calendar = new GregorianCalendar();
			calendar.setTime(date);
			return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
		} catch (Exception ex) {
			return null;
		}
	}
}
