Преглед изворни кода

Give an error if the timestamp is in the future.

pull/15/head
Ben Kurtovic пре 11 година
родитељ
комит
f323117ba5
1 измењених фајлова са 3 додато и 1 уклоњено
  1. +3
    -1
      tasks/drn_clerkbot.py

+ 3
- 1
tasks/drn_clerkbot.py Прегледај датотеку

@@ -725,9 +725,11 @@ class DRNClerkBot(Task):
return row + "|sm={{{small|}}}}}\n" return row + "|sm={{{small|}}}}}\n"


def format_time(self, dt): def format_time(self, dt):
"""Return a string telling the time since datetime occurred."""
"""Return a string telling the time since *dt* occurred."""
parts = [("year", 31536000), ("day", 86400), ("hour", 3600)] parts = [("year", 31536000), ("day", 86400), ("hour", 3600)]
seconds = int((datetime.utcnow() - dt).total_seconds()) seconds = int((datetime.utcnow() - dt).total_seconds())
if seconds < 0:
return "Invalid future time"
msg = [] msg = []
for name, size in parts: for name, size in parts:
num = seconds // size num = seconds // size


Loading…
Откажи
Сачувај