Package io.milton.http
Class DateUtils
java.lang.Object
io.milton.http.DateUtils
A utility class for parsing and formatting HTTP dates as used in cookies and
other headers. This class handles dates as defined by RFC 2616 section 3.3.1
as well as some other common non-standard formats.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TimeZonestatic final StringDate format pattern used to parse HTTP date headers in ANSI Casctime()format.static final StringAnother Date format pattern used to parse HTTP date headers in ANSI Casctime()format.static final StringUsed for response headers, and for modified date in propfindstatic final StringDate format pattern used to parse HTTP date headers in RFC 1036 format.static final StringDate format pattern used to parse HTTP date headers in RFC 1123 format.static final StringLike PATTERN_RFC1123 but with hyphens between the date componentsstatic final StringDate format pattern used to parse HTTP date headers in RFC 1123 format.static final String -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatDate(Calendar cal) static StringformatDate(Date date) static StringformatDate(Date date, String pattern) Formats the given date according to the specified pattern.static StringformatForCookieExpiry(Date date) static StringformatForHeader(Date date) static StringUse the long date form required for MS windows explorerstatic Stringpad2(int i) static DateParses a date value.static DateparseDate(String dateValue, Collection<String> dateFormats) Parses the date value using the given date formats.static DateparseDate(String dateValue, Collection<String> dateFormats, Date startDate) Parses the date value using the given date formats.static Date20140104T050000Z 20131222T000000Zstatic Datestatic DateParse date in format: 2010-09-03T09:29:43Z
-
Field Details
-
PATTERN_WEBDAV
- See Also:
-
PATTERN_RESPONSE_HEADER
Used for response headers, and for modified date in propfind- See Also:
-
PATTERN_RFC1123
Date format pattern used to parse HTTP date headers in RFC 1123 format.- See Also:
-
PATTERN_RFC1123_HYPHENS
Like PATTERN_RFC1123 but with hyphens between the date components- See Also:
-
PATTERN_RFC1123_NOSECS
Date format pattern used to parse HTTP date headers in RFC 1123 format.- See Also:
-
PATTERN_RFC1036
Date format pattern used to parse HTTP date headers in RFC 1036 format.- See Also:
-
PATTERN_ASCTIME
Date format pattern used to parse HTTP date headers in ANSI Casctime()format.- See Also:
-
PATTERN_ASCTIME2
Another Date format pattern used to parse HTTP date headers in ANSI Casctime()format.- See Also:
-
GMT
-
-
Method Details
-
parseWebDavDate
Parse date in format: 2010-09-03T09:29:43Z- Parameters:
s-- Returns:
- Throws:
DateUtils.DateParseException
-
parseIcalDateTime
20140104T050000Z 20131222T000000Z- Parameters:
s-- Returns:
- Throws:
DateUtils.DateParseException
-
parseIcalDateTime_old
- Throws:
DateUtils.DateParseException
-
parseDate
Parses a date value. The formats used for parsing the date value are retrieved from the default http params.- Parameters:
dateValue- the date value to parse- Returns:
- the parsed date
- Throws:
DateUtils.DateParseException- if the value could not be parsed using any of the supported date formats
-
parseDate
public static Date parseDate(String dateValue, Collection<String> dateFormats) throws DateUtils.DateParseException Parses the date value using the given date formats.- Parameters:
dateValue- the date value to parsedateFormats- the date formats to use- Returns:
- the parsed date
- Throws:
DateUtils.DateParseException- if none of the dataFormats could parse the dateValue
-
parseDate
public static Date parseDate(String dateValue, Collection<String> dateFormats, Date startDate) throws DateUtils.DateParseException Parses the date value using the given date formats.- Parameters:
dateValue- the date value to parsedateFormats- the date formats to usestartDate- During parsing, two digit years will be placed in the rangestartDatetostartDate + 100 years. This value may benull. Whennullis given as a parameter, year2000will be used.- Returns:
- the parsed date
- Throws:
DateUtils.DateParseException- if none of the dataFormats could parse the dateValue
-
formatDate
-
formatDate
- Parameters:
cal-- Returns:
- See Also:
-
formatForHeader
-
pad2
-
formatDate
Formats the given date according to the specified pattern. The pattern must conform to that used by thesimple date formatclass.- Parameters:
date- The date to format.pattern- The pattern to use for formatting the date.- Returns:
- A formatted date string.
- Throws:
IllegalArgumentException- If the given date pattern is invalid.- See Also:
-
formatForWebDavModifiedDate
Use the long date form required for MS windows explorer- Parameters:
date-- Returns:
-
formatForCookieExpiry
-