示例#1
0
def get_time_as_str(t, timezone=None):
    if timezone is None:
        timezone = config.get("TIMEZONE")
    s = (t - datetime.utcnow()).total_seconds()
    (m, s) = divmod(s, 60)
    (h, m) = divmod(m, 60)
    d = timedelta(hours=h, minutes=m, seconds=s)
    if timezone is not None:
        disappear_time = datetime.now(tz=timezone) + d
    else:
        disappear_time = datetime.now() + d
    # Time remaining in minutes and seconds
    time = "%dm %ds" % (m, s) if h == 0 else "%dh %dm" % (h, m)
    # Disappear time in 12h format, eg "2:30:16 PM"
    time_12h = disappear_time.strftime("%I:%M:%S") \
        + disappear_time.strftime("%p").lower()
    # Disappear time in 24h format including seconds, eg "14:30:16"
    time_24h = disappear_time.strftime("%H:%M:%S")

    # Get the same as above but without seconds
    time_no_sec = "%dm" % m if h == 0 else "%dh %dm" % (h, m)
    time_12h_no_sec = disappear_time.strftime("%I:%M") \
        + disappear_time.strftime("%p").lower()
    time_24h_no_sec = disappear_time.strftime("%H:%M")

    time_raw_hours = int(h)
    time_raw_minutes = int(m)
    time_raw_seconds = int(s)

    return time, time_12h, time_24h, \
        time_no_sec, time_12h_no_sec, time_24h_no_sec, \
        time_raw_hours, time_raw_minutes, time_raw_seconds
示例#2
0
def get_time_as_str(t, timezone=None):
    if timezone is None:
        timezone = config.get("TIMEZONE")
    s = (t - datetime.utcnow()).total_seconds()
    (m, s) = divmod(s, 60)
    (h, m) = divmod(m, 60)
    d = timedelta(hours=h, minutes=m, seconds=s)
    if timezone is not None:
        disappear_time = datetime.now(tz=timezone) + d
    else:
        disappear_time = datetime.now() + d
    # Time remaining in minutes and seconds
    time_left = "%dm %ds" % (m, s) if h == 0 else "%dh %dm" % (h, m)
    # Disappear time in 12h format, eg "2:30:16 PM"
    time_12 = disappear_time.strftime("%I:%M:%S") \
        + disappear_time.strftime("%p").lower()
    # Disappear time in 24h format including seconds, eg "14:30:16"
    time_24 = disappear_time.strftime("%H:%M:%S")
    return time_left, time_12, time_24
示例#3
0
def get_seconds_remaining(t, timezone=None):
    if timezone is None:
        timezone = config.get("TIMEZONE")
    seconds = (t - datetime.utcnow()).total_seconds()
    return seconds