From b5686b44c4e6871a75859cee33ce54f6f145a21f Mon Sep 17 00:00:00 2001 From: maustin Date: Sat, 14 Apr 2018 20:29:28 +0100 Subject: [PATCH] Dates for formats --- .../src/main/java/forge/game/GameFormat.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/forge-game/src/main/java/forge/game/GameFormat.java b/forge-game/src/main/java/forge/game/GameFormat.java index fda6ebd317f..8fbacd0d8fe 100644 --- a/forge-game/src/main/java/forge/game/GameFormat.java +++ b/forge-game/src/main/java/forge/game/GameFormat.java @@ -39,6 +39,8 @@ import forge.util.storage.StorageReaderFolder; import java.io.File; import java.io.FilenameFilter; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.Map.Entry; @@ -53,6 +55,8 @@ public class GameFormat implements Comparable { protected final List allowedRarities; protected final List bannedCardNames; protected final List restrictedCardNames; + private Date date; + private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); protected final transient List allowedSetCodes_ro; protected final transient List bannedCardNames_ro; @@ -115,6 +119,18 @@ public class GameFormat implements Comparable { return this.name; } + private static Date parseDate(String date) { + if( date.length() <= 7 ) + date = date + "-01"; + try { + return formatter.parse(date); + } catch (ParseException e) { + return new Date(); + } + } + + public Date getDate() { return date; } + public FormatType getFormatType() { return this.formatType; } @@ -232,6 +248,7 @@ public class GameFormat implements Comparable { formatType = FormatType.Custom; } Integer idx = section.getInt("order"); + Date date = parseDate(section.get("date")); String strSets = section.get("sets"); if ( null != strSets ) { sets = Arrays.asList(strSets.split(", "));