Merge pull request #4703 from ByteHamster/thread-safe-dates

Partially revert "Performance improvements"
This commit is contained in:
ByteHamster 2020-11-22 16:02:20 +01:00 committed by GitHub
commit fe5bf85e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 9 deletions

View File

@ -22,14 +22,7 @@ public class DateUtils {
private DateUtils(){}
private static final String TAG = "DateUtils";
private static final TimeZone defaultTimezone = TimeZone.getTimeZone("GMT");
private static final SimpleDateFormat dateFormatParser = new SimpleDateFormat("", Locale.US);
static {
dateFormatParser.setLenient(false);
dateFormatParser.setTimeZone(defaultTimezone);
}
public static Date parse(final String input) {
if (input == null) {
@ -99,12 +92,16 @@ public class DateUtils {
"EEE d MMM yyyy HH:mm:ss 'GMT'Z (z)"
};
SimpleDateFormat parser = new SimpleDateFormat("", Locale.US);
parser.setLenient(false);
parser.setTimeZone(defaultTimezone);
ParsePosition pos = new ParsePosition(0);
for (String pattern : patterns) {
dateFormatParser.applyPattern(pattern);
parser.applyPattern(pattern);
pos.setIndex(0);
try {
Date result = dateFormatParser.parse(date, pos);
Date result = parser.parse(date, pos);
if (result != null && pos.getIndex() == date.length()) {
return result;
}