Skip to content

Commit

Permalink
Merge pull request #2104 from Windchild292/dev_Windchild_MHQ1894
Browse files Browse the repository at this point in the history
MekHQ 1894: Adding additional legacy date format
  • Loading branch information
Windchild292 authored Aug 3, 2020
2 parents 9712cdf + d241de1 commit a57db2a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions megamek/src/megamek/utils/MegaMekXmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.InputStream;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -176,12 +177,15 @@ public static String indentStr(int level) {
*/
public static LocalDate parseDate(String value) throws DateTimeParseException {
// Accept (truncates): yyyy-MM-dd HH:mm:ss
// Accept (legacy): YYYYMMDD
// Accept: yyyy-MM-dd
int firstSpace = value.indexOf(' ');
if (firstSpace < 0) {
return LocalDate.parse(value);
} else {
if (firstSpace >= 0) {
return LocalDate.parse(value.substring(0, firstSpace));
} else if (value.indexOf('-') < 0) {
return LocalDate.parse(value, DateTimeFormatter.ofPattern("yyyyMMdd"));
} else { // default parsing
return LocalDate.parse(value);
}
}

Expand Down

0 comments on commit a57db2a

Please sign in to comment.