From 8e7eeb9c3f839af90a9bab88a6ed598c4bcd4041 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 26 Aug 2020 10:07:06 -0700 Subject: [PATCH] Use code from cmd's sdate.py which is better. --- voussoirkit/eternalseptember.py | 70 ++++++++++++++------------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/voussoirkit/eternalseptember.py b/voussoirkit/eternalseptember.py index bdcdf48..df14857 100644 --- a/voussoirkit/eternalseptember.py +++ b/voussoirkit/eternalseptember.py @@ -1,52 +1,40 @@ import datetime +import re +import time EPOCH = datetime.datetime( year=1993, month=9, day=1, - tzinfo=datetime.timezone.utc, ) -def normalize_date(date): - if isinstance(date, datetime.datetime): - pass - elif isinstance(date, (int, float)): - date = datetime.datetime.utcfromtimestamp(date) - date = date.replace(tzinfo=datetime.timezone.utc) +def strftime(format, tpl=None): + now = datetime.datetime.now() + diff = now - EPOCH + + day = str(diff.days + 1) + day_of_year = str(244 + diff.days) + + changes = { + r'%b': 'Sep', + r'%B': 'September', + r'%d': day, + r'%-d': day, + r'%j': day_of_year, + r'%-j': day_of_year, + r'%m': '09', + r'%-m': '9', + r'%Y': '1993', + r'%y': '93', + } + for (key, value) in changes.items(): + key = r'(?