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

com.bigcommerce.catalog.models.DateTimeAdapter Maven / Gradle / Ivy

The newest version!
package com.bigcommerce.catalog.models;

import javax.xml.bind.annotation.adapters.XmlAdapter;

import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class DateTimeAdapter extends XmlAdapter {

	public static final String RFC_822_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss Z";

	@Override
	public DateTime unmarshal(final String timestamp) throws Exception {
		if (StringUtils.isBlank(timestamp)) {
			return null;
		}
		final DateTimeFormatter formatter = DateTimeFormat.forPattern(RFC_822_DATE_FORMAT);
		return DateTime.parse(timestamp, formatter).toDateTime(DateTimeZone.UTC);
	}

	@Override
	public String marshal(final DateTime dateTime) throws Exception {
		if (dateTime == null) {
			return null;
		}
		final DateTimeFormatter formatter = DateTimeFormat.forPattern(RFC_822_DATE_FORMAT);
		return formatter.print(dateTime);

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy