Internal timezone is now UTC
This commit is contained in:
parent
32cb79344b
commit
c5a69f1bd0
10 changed files with 54 additions and 58 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import re
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from hooks import hook
|
||||
|
||||
|
|
@ -41,9 +41,7 @@ def get_variable(name, msg=None):
|
|||
elif name == "chan" or name == "channel":
|
||||
return msg.channel
|
||||
elif name == "date":
|
||||
now = datetime.now()
|
||||
return ("%d/%d/%d %d:%d:%d"%(now.day, now.month, now.year, now.hour,
|
||||
now.minute, now.second))
|
||||
return datetime.now(timezone.utc).strftime("%c")
|
||||
elif name in DATAS.getNode("variables").index:
|
||||
return DATAS.getNode("variables").index[name]["value"]
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"""Wishes Happy New Year when the time comes"""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from hooks import hook
|
||||
from tools.countdown import countdown_format
|
||||
|
|
@ -11,15 +11,15 @@ nemubotversion = 3.4
|
|||
|
||||
from more import Response
|
||||
|
||||
yr = datetime.today().year
|
||||
yrn = datetime.today().year + 1
|
||||
yr = datetime.now(timezone.utc).year
|
||||
yrn = datetime.now(timezone.utc).year + 1
|
||||
|
||||
def load(context):
|
||||
d = datetime(yrn, 1, 1, 0, 0, 0) - datetime.now()
|
||||
d = datetime(yrn, 1, 1, 0, 0, 0) - datetime.now(timezone.utc)
|
||||
add_event(ModuleEvent(interval=0, offset=d.total_seconds(), call=bonneannee))
|
||||
|
||||
def bonneannee():
|
||||
txt = "Bonne année %d !" % datetime.today().year
|
||||
txt = "Bonne année %d !" % yrn
|
||||
print (txt)
|
||||
send_response("localhost:2771", Response(txt, "#epitagueule"))
|
||||
send_response("localhost:2771", Response(txt, "#yaka"))
|
||||
|
|
@ -31,7 +31,7 @@ def bonneannee():
|
|||
@hook("cmd_hook", "newyear")
|
||||
@hook("cmd_hook", str(yrn), yrn)
|
||||
def cmd_newyear(msg, yr):
|
||||
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1),
|
||||
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1, 0, timezone.utc),
|
||||
"Il reste %s avant la nouvelle année.",
|
||||
"Nous faisons déjà la fête depuis %s !"),
|
||||
channel=msg.channel)
|
||||
|
|
@ -43,7 +43,7 @@ def cmd_timetoyear(msg, cur):
|
|||
if yr == cur:
|
||||
return None
|
||||
|
||||
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1),
|
||||
return Response(countdown_format(datetime(yr, 1, 1, 0, 0, 1, 0, timezone.utc),
|
||||
"Il reste %s avant %d." % ("%s", yr),
|
||||
"Le premier janvier %d est passé depuis %s !" % (yr, "%s")),
|
||||
channel=msg.channel)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@
|
|||
import imp
|
||||
import re
|
||||
import sys
|
||||
from datetime import timedelta
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import time
|
||||
import threading
|
||||
import traceback
|
||||
|
|
@ -32,7 +31,7 @@ def load(context):
|
|||
if DATAS.index[evt].hasAttribute("end"):
|
||||
event = ModuleEvent(call=fini, call_data=dict(strend=DATAS.index[evt]))
|
||||
event._end = DATAS.index[evt].getDate("end")
|
||||
idt = context.add_event(event)
|
||||
idt = add_event(event)
|
||||
if idt is not None:
|
||||
DATAS.index[evt]["id"] = idt
|
||||
|
||||
|
|
@ -44,8 +43,8 @@ def fini(d, strend):
|
|||
|
||||
@hook("cmd_hook", "goûter")
|
||||
def cmd_gouter(msg):
|
||||
ndate = datetime.today()
|
||||
ndate = datetime(ndate.year, ndate.month, ndate.day, 16, 42)
|
||||
ndate = datetime.now(timezone.utc)
|
||||
ndate = datetime(ndate.year, ndate.month, ndate.day, 16, 42, 0, 0, timezone.utc)
|
||||
return Response(countdown_format(ndate,
|
||||
"Le goûter aura lieu dans %s, préparez vos biscuits !",
|
||||
"Nous avons %s de retard pour le goûter :("),
|
||||
|
|
@ -53,8 +52,8 @@ def cmd_gouter(msg):
|
|||
|
||||
@hook("cmd_hook", "week-end")
|
||||
def cmd_we(msg):
|
||||
ndate = datetime.today() + timedelta(5 - datetime.today().weekday())
|
||||
ndate = datetime(ndate.year, ndate.month, ndate.day, 0, 0, 1)
|
||||
ndate = datetime.now(timezone.utc) + timedelta(5 - datetime.today().weekday())
|
||||
ndate = datetime(ndate.year, ndate.month, ndate.day, 0, 0, 1, 0, timezone.utc)
|
||||
return Response(countdown_format(ndate,
|
||||
"Il reste %s avant le week-end, courage ;)",
|
||||
"Youhou, on est en week-end depuis %s."),
|
||||
|
|
@ -95,14 +94,14 @@ def start_countdown(msg):
|
|||
if result2 is None or result2.group(4) is None: yea = now.year
|
||||
else: yea = int(result2.group(4))
|
||||
if result2 is not None and result3 is not None:
|
||||
strnd["end"] = datetime(yea, int(result2.group(3)), int(result2.group(2)), hou, minu, sec)
|
||||
strnd["end"] = datetime(yea, int(result2.group(3)), int(result2.group(2)), hou, minu, sec, timezone.utc)
|
||||
elif result2 is not None:
|
||||
strnd["end"] = datetime(int(result2.group(4)), int(result2.group(3)), int(result2.group(2)))
|
||||
strnd["end"] = datetime(int(result2.group(4)), int(result2.group(3)), int(result2.group(2)), 0, 0, 0, timezone.utc)
|
||||
elif result3 is not None:
|
||||
if hou * 3600 + minu * 60 + sec > now.hour * 3600 + now.minute * 60 + now.second:
|
||||
strnd["end"] = datetime(now.year, now.month, now.day, hou, minu, sec)
|
||||
strnd["end"] = datetime(now.year, now.month, now.day, hou, minu, sec, timezone.utc)
|
||||
else:
|
||||
strnd["end"] = datetime(now.year, now.month, now.day + 1, hou, minu, sec)
|
||||
strnd["end"] = datetime(now.year, now.month, now.day + 1, hou, minu, sec, timezone.utc)
|
||||
evt._end = strnd.getDate("end")
|
||||
strnd["id"] = add_event(evt)
|
||||
except:
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
import re
|
||||
import imp
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from hooks import hook
|
||||
|
||||
|
|
@ -22,9 +21,9 @@ def cmd_sleep(msg):
|
|||
msg.cmds[1]) is not None:
|
||||
# First, parse the hour
|
||||
p = re.match("([0-9]{1,2})[h':.,-]([0-9]{1,2})?[m':.,-]?", msg.cmds[1])
|
||||
f = [datetime(datetime.today().year,
|
||||
datetime.today().month,
|
||||
datetime.today().day,
|
||||
f = [datetime(datetime.now(timezone.utc).year,
|
||||
datetime.now(timezone.utc).month,
|
||||
datetime.now(timezone.utc).day,
|
||||
hour=int(p.group(1)))]
|
||||
if p.group(2) is not None:
|
||||
f[0] += timedelta(minutes=int(p.group(2)))
|
||||
|
|
@ -37,7 +36,7 @@ def cmd_sleep(msg):
|
|||
|
||||
# Just get awake times
|
||||
else:
|
||||
f = [datetime.now() + timedelta(minutes=15)]
|
||||
f = [datetime.now(timezone.utc) + timedelta(minutes=15)]
|
||||
g = list()
|
||||
for i in range(0,6):
|
||||
f.append(f[i] + timedelta(hours=1,minutes=30))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
"""The 2014 football worldcup module"""
|
||||
|
||||
import datetime
|
||||
from datetime import datetime, timezone
|
||||
import json
|
||||
import re
|
||||
from urllib.parse import quote
|
||||
|
|
@ -32,7 +32,7 @@ def start_watch(msg):
|
|||
w["channel"] = msg.channel
|
||||
w["proprio"] = msg.nick
|
||||
w["sender"] = msg.sender
|
||||
w["start"] = datetime.datetime.now()
|
||||
w["start"] = datetime.now(timezone.utc)
|
||||
DATAS.addChild(w)
|
||||
save()
|
||||
raise IRCException("This channel is now watching world cup events!")
|
||||
|
|
@ -125,7 +125,7 @@ def txt_event(e):
|
|||
return "%se minutes : %s %s (%s)" % (e["time"], detail_event(e["type_of_event"]), e["player"], e["team"]["code"])
|
||||
|
||||
def prettify(match):
|
||||
matchdate_local = datetime.datetime.strptime(match["datetime"].replace(':', ''), "%Y-%m-%dT%H%M%S.%f%z")
|
||||
matchdate_local = datetime.strptime(match["datetime"].replace(':', ''), "%Y-%m-%dT%H%M%S.%f%z")
|
||||
matchdate = matchdate_local - (matchdate_local.utcoffset() - datetime.timedelta(hours=2))
|
||||
if match["status"] == "future":
|
||||
return ["Match à venir (%s) le %s : %s vs. %s" % (match["match_number"], matchdate.strftime("%A %d à %H:%M"), match["home_team"]["country"], match["away_team"]["country"])]
|
||||
|
|
@ -135,7 +135,7 @@ def prettify(match):
|
|||
if match["status"] == "completed":
|
||||
msg += "Match (%s) du %s terminé : " % (match["match_number"], matchdate.strftime("%A %d à %H:%M"))
|
||||
else:
|
||||
msg += "Match en cours (%s) depuis %d minutes : " % (match["match_number"], (datetime.datetime.now(matchdate.tzinfo) - matchdate_local).seconds / 60)
|
||||
msg += "Match en cours (%s) depuis %d minutes : " % (match["match_number"], (datetime.now(matchdate.tzinfo) - matchdate_local).seconds / 60)
|
||||
|
||||
msg += "%s %d - %d %s" % (match["home_team"]["country"], match["home_team"]["goals"], match["away_team"]["goals"], match["away_team"]["country"])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue