Show More
@@ -15,15 +15,15 b' def addbreaks(text):' | |||||
15 | """ |
|
15 | """ | |
16 | return text.replace('\n', '<br/>\n') |
|
16 | return text.replace('\n', '<br/>\n') | |
17 |
|
17 | |||
18 | agescales = [("year", 3600 * 24 * 365), |
|
18 | agescales = [("year", 3600 * 24 * 365, 'Y'), | |
19 | ("month", 3600 * 24 * 30), |
|
19 | ("month", 3600 * 24 * 30, 'M'), | |
20 | ("week", 3600 * 24 * 7), |
|
20 | ("week", 3600 * 24 * 7, 'W'), | |
21 | ("day", 3600 * 24), |
|
21 | ("day", 3600 * 24, 'd'), | |
22 | ("hour", 3600), |
|
22 | ("hour", 3600, 'h'), | |
23 | ("minute", 60), |
|
23 | ("minute", 60, 'm'), | |
24 | ("second", 1)] |
|
24 | ("second", 1, 's')] | |
25 |
|
25 | |||
26 | def age(date): |
|
26 | def age(date, abbrev=False): | |
27 | """:age: Date. Returns a human-readable date/time difference between the |
|
27 | """:age: Date. Returns a human-readable date/time difference between the | |
28 | given date/time and the current date/time. |
|
28 | given date/time and the current date/time. | |
29 | """ |
|
29 | """ | |
@@ -32,7 +32,9 b' def age(date):' | |||||
32 | if c == 1: |
|
32 | if c == 1: | |
33 | return t |
|
33 | return t | |
34 | return t + "s" |
|
34 | return t + "s" | |
35 | def fmt(t, c): |
|
35 | def fmt(t, c, a): | |
|
36 | if abbrev: | |||
|
37 | return "%d%s" % (c, a) | |||
36 | return "%d %s" % (c, plural(t, c)) |
|
38 | return "%d %s" % (c, plural(t, c)) | |
37 |
|
39 | |||
38 | now = time.time() |
|
40 | now = time.time() | |
@@ -48,12 +50,12 b' def age(date):' | |||||
48 | if delta > agescales[0][1] * 2: |
|
50 | if delta > agescales[0][1] * 2: | |
49 | return util.shortdate(date) |
|
51 | return util.shortdate(date) | |
50 |
|
52 | |||
51 | for t, s in agescales: |
|
53 | for t, s, a in agescales: | |
52 | n = delta // s |
|
54 | n = delta // s | |
53 | if n >= 2 or s == 1: |
|
55 | if n >= 2 or s == 1: | |
54 | if future: |
|
56 | if future: | |
55 | return '%s from now' % fmt(t, n) |
|
57 | return '%s from now' % fmt(t, n, a) | |
56 | return '%s ago' % fmt(t, n) |
|
58 | return '%s ago' % fmt(t, n, a) | |
57 |
|
59 | |||
58 | def basename(path): |
|
60 | def basename(path): | |
59 | """:basename: Any text. Treats the text as a path, and returns the last |
|
61 | """:basename: Any text. Treats the text as a path, and returns the last |
General Comments 0
You need to be logged in to leave comments.
Login now