utils.datetime.datetime_utcnow() -> utils.datetime.utcnow()
This commit is contained in:
parent
6a6e789ec9
commit
93aea08818
4 changed files with 9 additions and 9 deletions
|
@ -9,7 +9,7 @@ HUMAN_FORMAT_HELP = "year-month-day (e.g. 2018-12-29)"
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def _parse_date(self, dt: str):
|
def _parse_date(self, dt: str):
|
||||||
if dt.lower() == "today":
|
if dt.lower() == "today":
|
||||||
return utils.datetime.datetime_utcnow()
|
return utils.datetime.utcnow()
|
||||||
else:
|
else:
|
||||||
match = RE_HUMAN_FORMAT.match(dt)
|
match = RE_HUMAN_FORMAT.match(dt)
|
||||||
if not match:
|
if not match:
|
||||||
|
@ -52,7 +52,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
badge_lower = badge.lower()
|
badge_lower = badge.lower()
|
||||||
badges = self._get_badges(event["user"])
|
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)
|
found_badge = self._find_badge(badges, badge)
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if event["args"]:
|
if event["args"]:
|
||||||
user = event["server"].get_user(event["args_split"][0])
|
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 = []
|
badges = []
|
||||||
for badge, date in self._get_badges(user).items():
|
for badge, date in self._get_badges(user).items():
|
||||||
days_since = self._days_since(now,
|
days_since = self._days_since(now,
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
np = True
|
np = True
|
||||||
else:
|
else:
|
||||||
played = int(now_playing["date"]["uts"])
|
played = int(now_playing["date"]["uts"])
|
||||||
dt = utils.datetime.datetime_utcnow()
|
dt = utils.datetime.utcnow()
|
||||||
np = bool((dt.timestamp()-played) < 120)
|
np = bool((dt.timestamp()-played) < 120)
|
||||||
|
|
||||||
time_language = "is listening to" if np else "last listened to"
|
time_language = "is listening to" if np else "last listened to"
|
||||||
|
|
|
@ -9,7 +9,7 @@ class LockFile(PollHook.PollHook):
|
||||||
self._next_lock = None
|
self._next_lock = None
|
||||||
|
|
||||||
def available(self):
|
def available(self):
|
||||||
now = utils.datetime.datetime_utcnow()
|
now = utils.datetime.utcnow()
|
||||||
if os.path.exists(self._filename):
|
if os.path.exists(self._filename):
|
||||||
with open(self._filename, "r") as lock_file:
|
with open(self._filename, "r") as lock_file:
|
||||||
timestamp_str = lock_file.read().strip().split(" ", 1)[0]
|
timestamp_str = lock_file.read().strip().split(" ", 1)[0]
|
||||||
|
@ -23,14 +23,14 @@ class LockFile(PollHook.PollHook):
|
||||||
|
|
||||||
def lock(self):
|
def lock(self):
|
||||||
with open(self._filename, "w") as lock_file:
|
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))
|
lock_file.write("%s" % utils.datetime.iso8601_format(last_lock))
|
||||||
self._next_lock = last_lock+datetime.timedelta(
|
self._next_lock = last_lock+datetime.timedelta(
|
||||||
seconds=EXPIRATION/2)
|
seconds=EXPIRATION/2)
|
||||||
|
|
||||||
def next(self):
|
def next(self):
|
||||||
return max(0,
|
return max(0,
|
||||||
(self._next_lock-utils.datetime.datetime_utcnow()).total_seconds())
|
(self._next_lock-utils.datetime.utcnow()).total_seconds())
|
||||||
def call(self):
|
def call(self):
|
||||||
self.lock()
|
self.lock()
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ ISO8601_FORMAT_TZ = "%z"
|
||||||
DATETIME_HUMAN = "%Y/%m/%d %H:%M:%S"
|
DATETIME_HUMAN = "%Y/%m/%d %H:%M:%S"
|
||||||
DATE_HUMAN = "%Y-%m-%d"
|
DATE_HUMAN = "%Y-%m-%d"
|
||||||
|
|
||||||
def datetime_utcnow() -> _datetime.datetime:
|
def utcnow() -> _datetime.datetime:
|
||||||
return _datetime.datetime.utcnow().replace(tzinfo=_datetime.timezone.utc)
|
return _datetime.datetime.utcnow().replace(tzinfo=_datetime.timezone.utc)
|
||||||
def datetime_timestamp(seconds: float) -> _datetime.datetime:
|
def datetime_timestamp(seconds: float) -> _datetime.datetime:
|
||||||
return _datetime.datetime.fromtimestamp(seconds).replace(
|
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)
|
return "%s%s%s" % (dt_format, ms_format, tz_format)
|
||||||
def iso8601_format_now(milliseconds: bool=False) -> str:
|
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:
|
def iso8601_parse(s: str, microseconds: bool=False) -> _datetime.datetime:
|
||||||
fmt = ISO8601_PARSE_MICROSECONDS if microseconds else ISO8601_PARSE
|
fmt = ISO8601_PARSE_MICROSECONDS if microseconds else ISO8601_PARSE
|
||||||
return _datetime.datetime.strptime(s, fmt)
|
return _datetime.datetime.strptime(s, fmt)
|
||||||
|
|
Loading…
Reference in a new issue