
com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.RenderableDate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wiremock Show documentation
Show all versions of wiremock Show documentation
A web service test double for all occasions
package com.github.tomakehurst.wiremock.extension.responsetemplating.helpers;
import com.fasterxml.jackson.databind.util.ISO8601Utils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
public class RenderableDate {
private final Date date;
private final String format;
private final String timezoneName;
public RenderableDate(Date date, String format, String timezone) {
this.date = date;
this.format = format;
this.timezoneName = timezone;
}
@Override
public String toString() {
if (format != null) {
return format.equals("epoch") ?
String.valueOf(date.getTime()) :
formatCustom();
}
return timezoneName != null ?
ISO8601Utils.format(date, false, TimeZone.getTimeZone(timezoneName)) :
ISO8601Utils.format(date, false);
}
private String formatCustom() {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
if (timezoneName != null) {
TimeZone zone = TimeZone.getTimeZone(timezoneName);
dateFormat.setTimeZone(zone);
}
return dateFormat.format(date);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy