This commit is contained in:
j 2008-04-27 19:17:29 +02:00
parent ffb890c962
commit a78b14a4d4
4 changed files with 57 additions and 62 deletions

View file

@ -1,12 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=2:sts=2:ts=2 # vi:si:et:sw=2:sts=2:ts=2
# Written 2008 by j@mailb.org # 2008
from hashes import * from hashes import *
from html import * from html import *
from numbers import *
from text import * from text import *
from timeformat import * from format import *
import net import net
import cache import cache

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=2:sts=2:ts=2 # vi:si:et:sw=2:sts=2:ts=2
# 2008
import os import os
import sha import sha
import time import time

View file

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=2:sts=2:ts=2 # vi:si:et:sw=2:sts=2:ts=2
# Written 2007 by j@mailb.org
import re import re
def to36(q): def to36(q):
@ -97,3 +96,57 @@ def plural(amount, unit, plural='s'):
else: unit = plural else: unit = plural
return "%s %s" % (formatNumber(amount), unit) return "%s %s" % (formatNumber(amount), unit)
def ms2runtime(ms):
seconds = int(ms / 1000)
years = 0
days = 0
hours = 0
minutes = 0
if seconds >= 60:
minutes = int(seconds / 60)
seconds = seconds % 60
if minutes >= 60:
hours = int(minutes / 60)
minutes = minutes % 60
if hours >= 24:
days = int(hours / 24)
hours = hours % 24
if days >= 365:
years = int(days / 365)
days = days % 365
runtimeString = (plural(years, 'year'), plural(days, 'day'),
plural(hours,'hour'), plural(minutes, 'minute'), plural(seconds, 'second'))
runtimeString = filter(lambda x: not x.startswith('0'), runtimeString)
return " ".join(runtimeString).strip()
def ms2playtime(ms):
it = int(ms / 1000)
ms = ms - it*1000
ss = it % 60
mm = ((it-ss)/60) % 60
hh = ((it-(mm*60)-ss)/3600) % 60
if hh:
playtime= "%02d:%02d:%02d" % (hh, mm, ss)
else:
playtime= "%02d:%02d" % (mm, ss)
return playtime
def ms2time(ms):
it = int(ms / 1000)
ms = ms - it*1000
ss = it % 60
mm = ((it-ss)/60) % 60
hh = ((it-(mm*60)-ss)/3600) % 60
return "%d:%02d:%02d.%03d" % (hh, mm, ss, ms)
def time2ms(timeString):
ms = 0.0
p = timeString.split(':')
for i in range(len(p)):
ms = ms * 60 + float(p[i])
return int(ms * 1000)
def shiftTime(offset, timeString):
newTime = time2ms(timeString) + offset
return ms2time(newTime)

View file

@ -1,58 +0,0 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=2:sts=2:ts=2
from numbers import plural
def ms2runtime(ms):
seconds = int(ms / 1000)
years = 0
days = 0
hours = 0
minutes = 0
if seconds >= 60:
minutes = int(seconds / 60)
seconds = seconds % 60
if minutes >= 60:
hours = int(minutes / 60)
minutes = minutes % 60
if hours >= 24:
days = int(hours / 24)
hours = hours % 24
if days >= 365:
years = int(days / 365)
days = days % 365
runtimeString = (plural(years, 'year'), plural(days, 'day'),
plural(hours,'hour'), plural(minutes, 'minute'), plural(seconds, 'second'))
runtimeString = filter(lambda x: not x.startswith('0'), runtimeString)
return " ".join(runtimeString).strip()
def ms2playtime(ms):
it = int(ms / 1000)
ms = ms - it*1000
ss = it % 60
mm = ((it-ss)/60) % 60
hh = ((it-(mm*60)-ss)/3600) % 60
if hh:
playtime= "%02d:%02d:%02d" % (hh, mm, ss)
else:
playtime= "%02d:%02d" % (mm, ss)
return playtime
def ms2time(ms):
it = int(ms / 1000)
ms = ms - it*1000
ss = it % 60
mm = ((it-ss)/60) % 60
hh = ((it-(mm*60)-ss)/3600) % 60
return "%d:%02d:%02d.%03d" % (hh, mm, ss, ms)
def time2ms(timeString):
ms = 0.0
p = timeString.split(':')
for i in range(len(p)):
ms = ms * 60 + float(p[i])
return int(ms * 1000)
def shiftTime(offset, timeString):
newTime = time2ms(timeString) + offset
return ms2time(newTime)