aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2019-10-30 10:25:07 +0000
committerGravatar jesopo2019-10-30 10:25:07 +0000
commit3634b72622e0108202482c7de57a7cdb1be35029 (patch)
tree76af44c235f42b704b5fd83914dd33b085f7e623
parentupdate CHANGELOG.md (diff)
add utils.date_human() - use it in badges.py
-rw-r--r--modules/badges.py3
-rw-r--r--src/utils/__init__.py3
2 files changed, 4 insertions, 2 deletions
diff --git a/modules/badges.py b/modules/badges.py
index 7370dab8..4eb3d626 100644
--- a/modules/badges.py
+++ b/modules/badges.py
@@ -6,7 +6,6 @@ from src import ModuleManager, utils
RE_HUMAN_FORMAT = re.compile(r"(\d\d\d\d)-(\d?\d)-(\d?\d)")
HUMAN_FORMAT_HELP = "year-month-day (e.g. 2018-12-29)"
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
-DATE_FORMAT = "%Y-%m-%d"
class Module(ModuleManager.BaseModule):
def _parse_date(self, dt: str):
@@ -24,7 +23,7 @@ class Module(ModuleManager.BaseModule):
).replace(tzinfo=datetime.timezone.utc)
def _date_str(self, dt: datetime.datetime):
- return datetime.datetime.strftime(dt, DATE_FORMAT)
+ return utils.date_human(dt)
def _round_up_day(self, dt: datetime.datetime):
return dt.date()+datetime.timedelta(days=1)
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index 309186c4..bbf11e73 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -14,6 +14,7 @@ ISO8601_FORMAT_TZ = "%z"
DATETIME_HUMAN = "%Y/%m/%d %H:%M:%S"
+DATE_HUMAN = "%Y-%m-%d"
def datetime_utcnow() -> datetime.datetime:
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
@@ -35,6 +36,8 @@ def iso8601_parse(s: str, microseconds: bool=False) -> datetime.datetime:
def datetime_human(dt: datetime.datetime):
return datetime.datetime.strftime(dt, DATETIME_HUMAN)
+def date_human(dt: datetime.datetime):
+ return datetime.datetime.strftime(dt, DATE_HUMAN)
TIME_SECOND = 1
TIME_MINUTE = TIME_SECOND*60