Partially revert "Performance improvements"

Some problems with wrong dates might be caused by the
static date parser no longer being thread safe.

This partially reverts commit 77ef239336.
This commit is contained in:
ByteHamster 2020-11-21 23:02:35 +01:00
parent 4e12615a2d
commit 9bd0babed5
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;
}