Skip to content

Commit

Permalink
FELIX-5422: more date formats in lite.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1770706 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
bimargulies committed Nov 21, 2016
1 parent 7623a2c commit 3812f7e
Showing 1 changed file with 16 additions and 9 deletions.
Expand Up @@ -61,6 +61,12 @@
**/
public class HttpServletRequestImpl implements HttpServletRequest
{

private static final SimpleDateFormat formatsTemplate[] = {
new SimpleDateFormat(HttpConstants.HTTP_DATE_FORMAT, Locale.US),
new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
};
/**
* HTTP Method
*/
Expand Down Expand Up @@ -819,16 +825,17 @@ public long getDateHeader( final String name )
return -1;
}

try
{
SimpleDateFormat sdf = new SimpleDateFormat(HttpConstants.HTTP_DATE_FORMAT);
sdf.setTimeZone(TimeZone.getTimeZone(HttpConstants.HTTP_TIMEZONE));
return sdf.parse( headerValue ).getTime();
}
catch ( ParseException e )
{
throw new IllegalArgumentException( "Unable to convert to date: " + headerValue );
for (int x = 0; x < formatsTemplate.length; x++) {
SimpleDateFormat sdf = formatsTemplate[x];
try {
sdf.setTimeZone(TimeZone.getTimeZone(HttpConstants.HTTP_TIMEZONE));
return sdf.parse(headerValue).getTime();
} catch (ParseException e) {
//
}
}
// if none of them work.
throw new IllegalArgumentException("Unable to convert to date: " + headerValue);
}


Expand Down

0 comments on commit 3812f7e

Please sign in to comment.