2021-05-04 02:03:28 +00:00
|
|
|
import argparse
|
2018-12-18 06:10:00 +00:00
|
|
|
import datetime
|
2020-08-26 17:07:06 +00:00
|
|
|
import re
|
2021-05-04 02:03:28 +00:00
|
|
|
import sys
|
2020-08-26 17:07:06 +00:00
|
|
|
import time
|
2018-12-18 06:10:00 +00:00
|
|
|
|
|
|
|
EPOCH = datetime.datetime(
|
|
|
|
year=1993,
|
|
|
|
month=9,
|
|
|
|
day=1,
|
|
|
|
)
|
|
|
|
|
2020-08-26 17:07:06 +00:00
|
|
|
def strftime(format, tpl=None):
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
diff = now - EPOCH
|
|
|
|
|
2021-01-04 10:40:48 +00:00
|
|
|
day_of_month = str(diff.days + 1)
|
2020-08-26 17:07:06 +00:00
|
|
|
day_of_year = str(244 + diff.days)
|
|
|
|
|
|
|
|
changes = {
|
|
|
|
r'%b': 'Sep',
|
|
|
|
r'%B': 'September',
|
2021-01-04 10:40:48 +00:00
|
|
|
r'%d': day_of_month,
|
|
|
|
r'%-d': day_of_month,
|
2020-08-26 17:07:06 +00:00
|
|
|
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():
|
2021-05-04 02:03:28 +00:00
|
|
|
# This regex prevents us from ruining %%a which should be literal %a.
|
2020-08-26 17:07:06 +00:00
|
|
|
key = r'(?<!%)' + key
|
|
|
|
format = re.sub(key, value, format)
|
|
|
|
|
|
|
|
if tpl is not None:
|
|
|
|
return time.strftime(format, tpl)
|
2018-12-18 06:10:00 +00:00
|
|
|
else:
|
2020-08-26 17:07:06 +00:00
|
|
|
return time.strftime(format)
|
2018-12-18 06:10:00 +00:00
|
|
|
|
2021-05-04 02:03:28 +00:00
|
|
|
def eternalseptember_argparse(args):
|
|
|
|
print(strftime(args.format))
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
|
|
|
|
parser.add_argument('--format', default='%Y-%m-%d %H:%M:%S')
|
|
|
|
parser.set_defaults(func=eternalseptember_argparse)
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
return args.func(args)
|
|
|
|
|
2018-12-18 06:10:00 +00:00
|
|
|
if __name__ == '__main__':
|
2021-05-04 02:03:28 +00:00
|
|
|
raise SystemExit(main(sys.argv[1:]))
|