com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.ParseDateHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wiremock-jre8-standalone Show documentation
Show all versions of wiremock-jre8-standalone Show documentation
A web service test double for all occasions - standalone edition
package com.github.tomakehurst.wiremock.extension.responsetemplating.helpers;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import com.fasterxml.jackson.databind.util.ISO8601Utils;
import com.github.jknack.handlebars.Options;
import com.github.tomakehurst.wiremock.common.Exceptions;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ParseDateHelper extends HandlebarsHelper {
@Override
public Object apply(String context, Options options) throws IOException {
String format = options.hash("format", null);
try {
return format == null ?
new ISO8601DateFormat().parse(context) :
new SimpleDateFormat(format).parse(context);
} catch (ParseException e) {
return Exceptions.throwUnchecked(e, Object.class);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy