From cb774409361f1f18a61a2f73687f84308cb22040 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 5 Aug 2013 12:37:18 -0400 Subject: [PATCH] Make date methods in HttpHeaders public Issue: SPR-10713 --- .../org/springframework/http/HttpHeaders.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index dfb43085b9..136ff11868 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -677,9 +677,14 @@ public class HttpHeaders implements MultiValueMap, Serializable return getFirst(UPGARDE); } - // Utility methods + // Date methods - private long getFirstDate(String headerName) { + /** + * Parse the first header value for the given header name as a date, return -1 if + * there is no value, or raise {@link IllegalArgumentException} if the value cannot be + * parsed as a date. + */ + public long getFirstDate(String headerName) { String headerValue = getFirst(headerName); if (headerValue == null) { return -1; @@ -698,7 +703,12 @@ public class HttpHeaders implements MultiValueMap, Serializable "\" for \"" + headerName + "\" header"); } - private void setDate(String headerName, long date) { + /** + * Set the given date under the given header name after formatting it as a string + * using the pattern {@code "EEE, dd MMM yyyy HH:mm:ss zzz"}. The equivalent of + * {@link #set(String, String)} but for date headers. + */ + public void setDate(String headerName, long date) { SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMATS[0], Locale.US); dateFormat.setTimeZone(GMT); set(headerName, dateFormat.format(new Date(date)));