2
Copyright (c) 2003-2007, Paul Varga and other contributors
5
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
* Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
16
# Converts a number of seconds into a short displayable string.
17
def succinct(seconds):
18
seconds = int(seconds)
20
hours = seconds / (60 * 60)
21
seconds -= hours * (60 * 60)
23
minutes = seconds / 60
24
seconds -= minutes * 60
26
return '%0.2d:%0.2d:%0.2d' % (hours, minutes, seconds)
28
# Converts a number of seconds into a precise, but verbose displayable string.
29
def lengthy_precise(seconds):
30
seconds = int(seconds)
32
days = seconds / (60 * 60 * 24)
33
seconds -= days * (60 * 60 * 24)
35
hours = seconds / (60 * 60)
36
seconds -= hours * (60 * 60)
38
minutes = seconds / 60
39
seconds -= minutes * 60
41
def create_listing(items):
42
def append_listing(listing, singular, plural, count, index, length):
45
if listing or count != 0 or index+1 == length:
46
listing += gettext.ngettext(singular, plural, count) % (count,)
55
for index, item in zip(range(0,len(items)), items):
56
listing = append_listing(listing, item[0][0], item[0][1], item[1], index, len(items))
60
return create_listing((
61
(('%i day', '%i days'), days),
62
(('%i hour', '%i hours'), hours),
63
(('%i minute', '%i minutes'), minutes),
64
(('%i second', '%i seconds'), seconds)
67
# Converts a number of seconds into a rough estimate
68
def lengthy_estimate(seconds):
69
seconds = int(seconds)
71
days = seconds / (60 * 60 * 24)
72
seconds -= days * (60 * 60 * 24)
74
hours = seconds / (60 * 60)
75
seconds -= hours * (60 * 60)
77
minutes = seconds / 60
78
seconds -= minutes * 60
81
return gettext.ngettext('About %i day', 'About %i days', days) % days
83
return gettext.ngettext('About %i hour', 'About %i hours', hours) % hours
85
return gettext.ngettext('About %i minute', 'About %i minutes', minutes) % minutes
87
return gettext.ngettext('About %i second', 'About %i seconds', seconds) % seconds
89
lengthy = lengthy_estimate