Skip to content

Commit

Permalink
fix: date parsing throws IllegalArgumentException. (#414)
Browse files Browse the repository at this point in the history
When minio-java is used in system running with different locale than
"US", date parsing fails with IllegalArgumentException.  This patch
fixes the issue by setting the locale to "US" for all date formats.

Thanks to @RBoelter for reporting/debugging/providing the solution.

Fixes #411
  • Loading branch information
balamurugana authored and harshavardhana committed Jun 28, 2016
1 parent cd84287 commit ff1d0ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ task javadocJar (type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}

task localeTest (type: Test) {
description = "Runs tests with locale"
System.setProperty('user.language', 'de')
System.setProperty('user.country', 'DE')
systemProperties = System.properties
dependsOn test
}

check.dependsOn localeTest

javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/8/docs/api/'
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/io/minio/DateFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.minio;

import java.util.Locale;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

Expand All @@ -25,17 +27,18 @@
*/
public class DateFormat {
public static final DateTimeFormatter AMZ_DATE_FORMAT =
DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss'Z'").withZoneUTC();
DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss'Z'").withZoneUTC().withLocale(Locale.US);

public static final DateTimeFormatter EXPIRATION_DATE_FORMAT =
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH':'mm':'ss'.'SSS'Z'").withZoneUTC();
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH':'mm':'ss'.'SSS'Z'").withZoneUTC().withLocale(Locale.US);

public static final DateTimeFormatter RESPONSE_DATE_FORMAT = EXPIRATION_DATE_FORMAT;

public static final DateTimeFormatter SIGNER_DATE_FORMAT = DateTimeFormat.forPattern("yyyyMMdd").withZoneUTC();
public static final DateTimeFormatter SIGNER_DATE_FORMAT =
DateTimeFormat.forPattern("yyyyMMdd").withZoneUTC().withLocale(Locale.US);

public static final DateTimeFormatter HTTP_HEADER_DATE_FORMAT =
DateTimeFormat.forPattern("EEE',' dd MMM yyyy HH':'mm':'ss zzz").withZoneUTC();
DateTimeFormat.forPattern("EEE',' dd MMM yyyy HH':'mm':'ss zzz").withZoneUTC().withLocale(Locale.US);

private DateFormat() {}
}

0 comments on commit ff1d0ae

Please sign in to comment.