Ejemplo n.º 1
0
def test_timeuntil():
    now = datetime(2010, 4, 12, 12, 30, 0)
    future = datetime(2010, 5, 15, 1, 50, 0)
    # basic
    assert time_until(future, now) == "1 month and 2 days"
    # count
    assert time_until(future, now, count=3) == "1 month, 2 days and 13 hours"
Ejemplo n.º 2
0
def allowed(uid):
    """ checks if a user is allowed to vote, and keeps track of voters """
    global voters

    # clear expired voters
    for _uid, _timestamp in voters.items():
        if (time.time() - _timestamp) >= TIME_LIMIT:
            del voters[_uid]

    if uid in voters:
        last_voted = voters[uid]
        return False, timeformat.time_until(last_voted, now=time.time() - TIME_LIMIT)
    else:
        voters[uid] = time.time()
        return True, 0