2021-04-10 09:53:52 +00:00
|
|
|
class Date:
|
2021-03-13 10:54:01 +00:00
|
|
|
def __init__(self, day="00", month="00", year="XXXX"):
|
2021-01-31 16:59:15 +00:00
|
|
|
self.year = year
|
|
|
|
self.month = month
|
|
|
|
self.day = day
|
|
|
|
self.fixDayMonth()
|
|
|
|
|
|
|
|
# Fix incorrect day month when detectable
|
|
|
|
def fixDayMonth(self):
|
|
|
|
if int(self.month) > 12:
|
|
|
|
monthTemp = self.month
|
|
|
|
self.month = self.day
|
|
|
|
self.day = monthTemp
|
|
|
|
|
|
|
|
def format(self, template):
|
|
|
|
elements = {
|
|
|
|
'year': ['YYYY', 'YY', 'Y'],
|
|
|
|
'month': ['MM', 'M'],
|
|
|
|
'day': ['DD', 'D']
|
|
|
|
}
|
|
|
|
for element, placeholders in elements.items():
|
|
|
|
for placeholder in placeholders:
|
|
|
|
if placeholder in template:
|
|
|
|
template = template.replace(placeholder, str(getattr(self, element)))
|
|
|
|
return template
|