diff options
author | neodarz <neodarz@neodarz.net> | 2019-05-25 23:35:45 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-05-25 23:35:45 +0200 |
commit | 9335441fe7dc26bc76fe3aea363c76a218ae261b (patch) | |
tree | a75eb05cf55175f007c4fa5524c3c6fcb9c2efcb /utils/utils.py | |
parent | a8e56413815123b4bb10f3ddd597f42d11c8ad46 (diff) | |
download | my_new_personal_website-9335441fe7dc26bc76fe3aea363c76a218ae261b.tar.xz my_new_personal_website-9335441fe7dc26bc76fe3aea363c76a218ae261b.zip |
Move current_datetime function to external file
Diffstat (limited to 'utils/utils.py')
-rw-r--r-- | utils/utils.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/utils/utils.py b/utils/utils.py index a76beb5d..bf3d4fbe 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -3,6 +3,10 @@ from contextlib import contextmanager import colorama +import time +import datetime +import dateutil.tz + @contextmanager def init_colorama(): @@ -21,3 +25,12 @@ def init_colorama(): for color in colorama.Fore.__dict__: exec("global {0}; {0} = ''".format(color)) colorama.deinit() + + +def current_datetime(): + """Return the current datetime, complete with tzinfo. + + Precision is one second. Timezone is the local timezone. + """ + return datetime.datetime.fromtimestamp(round(time.time()), + dateutil.tz.tzlocal()) |