Skip to content

Commit

Permalink
Parse date values
Browse files Browse the repository at this point in the history
  • Loading branch information
amtep committed Jun 15, 2022
1 parent 3255ed4 commit 7db8b4d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
27 changes: 27 additions & 0 deletions ck3/date.py
Original file line number Diff line number Diff line change
@@ -0,0 1,27 @@
class Date:
def __init__(self, s):
year, month, day = s.split('.')
self.d = (int(year), int(month), int(day))

def __gt__(self, odate):
if not isinstance(odate, Date):
return NotImplemented
return self.d > odate.d

def __lt__(self, odate):
if not isinstance(odate, Date):
return NotImplemented
return self.d < odate.d

def __ge__(self, odate):
if not isinstance(odate, Date):
return NotImplemented
return self.d >= odate.d

def __le__(self, odate):
if not isinstance(odate, Date):
return NotImplemented
return self.d <= odate.d

def __str__(self):
return '.'.join(self.d)
4 changes: 4 additions & 0 deletions ck3/savefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 6,8 @@
from enum import Enum, auto
from zipfile import ZipFile, BadZipFile

from ck3.date import Date

# TODO add paths for other systems
CK3_SAVEFILE_DIRS = [
'~/.local/share/Paradox Interactive/Crusader Kings III/save games/',
Expand Down Expand Up @@ -57,6 59,8 @@ def tokenize(f):
if m.lastgroup == 'QuotedString':
# strip the quotes
value = line[m.start() 1:m.end()-1]
elif m.lastgroup == 'Date':
value = Date(line[m.start():m.end()])
else:
value = line[m.start():m.end()]
ttype = TokenType[m.lastgroup]
Expand Down

0 comments on commit 7db8b4d

Please sign in to comment.