package be.iminds.jfed.gts_highlevel.util;

import javax.xml.bind.annotation.adapters.XmlAdapter;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

/**
 * User: twalcari
 * Date: 9/18/2015
 * Time: 17:42
 */
public class UnixEpochToZonedDateTimeAdapter extends XmlAdapter<Long, ZonedDateTime> {
    @Override
    public ZonedDateTime unmarshal(Long v) throws Exception {
        if(v == null)
            return null;
        return ZonedDateTime.ofInstant(Instant.ofEpochMilli(v), ZoneId.systemDefault());
    }

    @Override
    public Long marshal(ZonedDateTime v) throws Exception {
        if(v == null)
            return null;
        return v.toEpochSecond() *1000;
    }
}
