utils.datetime.datetime_utcnow() -> utils.datetime.utcnow()

This commit is contained in:
jesopo 2019-11-25 18:18:09 +00:00
parent 6a6e789ec9
commit 93aea08818
4 changed files with 9 additions and 9 deletions

View file

@ -9,7 +9,7 @@ HUMAN_FORMAT_HELP = "year-month-day (e.g. 2018-12-29)"
class Module(ModuleManager.BaseModule):
def _parse_date(self, dt: str):
if dt.lower() == "today":
return utils.datetime.datetime_utcnow()
return utils.datetime.utcnow()
else:
match = RE_HUMAN_FORMAT.match(dt)
if not match:
@ -52,7 +52,7 @@ class Module(ModuleManager.BaseModule):
badge_lower = badge.lower()
badges = self._get_badges(event["user"])
now = self._round_up_day(utils.datetime.datetime_utcnow())
now = self._round_up_day(utils.datetime.utcnow())
found_badge = self._find_badge(badges, badge)
@ -74,7 +74,7 @@ class Module(ModuleManager.BaseModule):
if event["args"]:
user = event["server"].get_user(event["args_split"][0])
now = self._round_up_day(utils.datetime.datetime_utcnow())
now = self._round_up_day(utils.datetime.utcnow())
badges = []
for badge, date in self._get_badges(user).items():
days_since = self._days_since(now,

View file

@ -54,7 +54,7 @@ class Module(ModuleManager.BaseModule):
np = True
else:
played = int(now_playing["date"]["uts"])
dt = utils.datetime.datetime_utcnow()
dt = utils.datetime.utcnow()
np = bool((dt.timestamp()-played) < 120)
time_language = "is listening to" if np else "last listened to"

View file

@ -9,7 +9,7 @@ class LockFile(PollHook.PollHook):
self._next_lock = None
def available(self):
now = utils.datetime.datetime_utcnow()
now = utils.datetime.utcnow()
if os.path.exists(self._filename):
with open(self._filename, "r") as lock_file:
timestamp_str = lock_file.read().strip().split(" ", 1)[0]
@ -23,14 +23,14 @@ class LockFile(PollHook.PollHook):
def lock(self):
with open(self._filename, "w") as lock_file:
last_lock = utils.datetime.datetime_utcnow()
last_lock = utils.datetime.utcnow()
lock_file.write("%s" % utils.datetime.iso8601_format(last_lock))
self._next_lock = last_lock+datetime.timedelta(
seconds=EXPIRATION/2)
def next(self):
return max(0,
(self._next_lock-utils.datetime.datetime_utcnow()).total_seconds())
(self._next_lock-utils.datetime.utcnow()).total_seconds())
def call(self):
self.lock()

View file

@ -10,7 +10,7 @@ ISO8601_FORMAT_TZ = "%z"
DATETIME_HUMAN = "%Y/%m/%d %H:%M:%S"
DATE_HUMAN = "%Y-%m-%d"
def datetime_utcnow() -> _datetime.datetime:
def utcnow() -> _datetime.datetime:
return _datetime.datetime.utcnow().replace(tzinfo=_datetime.timezone.utc)
def datetime_timestamp(seconds: float) -> _datetime.datetime:
return _datetime.datetime.fromtimestamp(seconds).replace(
@ -26,7 +26,7 @@ def iso8601_format(dt: _datetime.datetime, milliseconds: bool=False) -> str:
return "%s%s%s" % (dt_format, ms_format, tz_format)
def iso8601_format_now(milliseconds: bool=False) -> str:
return iso8601_format(datetime_utcnow(), milliseconds=milliseconds)
return iso8601_format(utcnow(), milliseconds=milliseconds)
def iso8601_parse(s: str, microseconds: bool=False) -> _datetime.datetime:
fmt = ISO8601_PARSE_MICROSECONDS if microseconds else ISO8601_PARSE
return _datetime.datetime.strptime(s, fmt)