From a78b14a4d49054578a2bc84ae1ef18f0860aabca Mon Sep 17 00:00:00 2001 From: j Date: Sun, 27 Apr 2008 19:17:29 +0200 Subject: [PATCH] renaming --- oxutils/__init__.py | 5 ++- oxutils/cache.py | 1 + oxutils/{numbers.py => format.py} | 55 ++++++++++++++++++++++++++++- oxutils/timeformat.py | 58 ------------------------------- 4 files changed, 57 insertions(+), 62 deletions(-) rename oxutils/{numbers.py => format.py} (63%) delete mode 100644 oxutils/timeformat.py diff --git a/oxutils/__init__.py b/oxutils/__init__.py index ed972e5..e12fc38 100644 --- a/oxutils/__init__.py +++ b/oxutils/__init__.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=2:sts=2:ts=2 -# Written 2008 by j@mailb.org +# 2008 from hashes import * from html import * -from numbers import * from text import * -from timeformat import * +from format import * import net import cache diff --git a/oxutils/cache.py b/oxutils/cache.py index a87cf8f..8ca9bf5 100644 --- a/oxutils/cache.py +++ b/oxutils/cache.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=2:sts=2:ts=2 +# 2008 import os import sha import time diff --git a/oxutils/numbers.py b/oxutils/format.py similarity index 63% rename from oxutils/numbers.py rename to oxutils/format.py index 55a6911..6188712 100644 --- a/oxutils/numbers.py +++ b/oxutils/format.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=2:sts=2:ts=2 -# Written 2007 by j@mailb.org import re def to36(q): @@ -97,3 +96,57 @@ def plural(amount, unit, plural='s'): else: unit = plural 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) + diff --git a/oxutils/timeformat.py b/oxutils/timeformat.py deleted file mode 100644 index 3628dab..0000000 --- a/oxutils/timeformat.py +++ /dev/null @@ -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) -