equal
deleted
inserted
replaced
26 (60, lambda n: ungettext('minute', 'minutes', n)) |
26 (60, lambda n: ungettext('minute', 'minutes', n)) |
27 ) |
27 ) |
28 # Convert datetime.date to datetime.datetime for comparison |
28 # Convert datetime.date to datetime.datetime for comparison |
29 if d.__class__ is not datetime.datetime: |
29 if d.__class__ is not datetime.datetime: |
30 d = datetime.datetime(d.year, d.month, d.day) |
30 d = datetime.datetime(d.year, d.month, d.day) |
31 if now: |
31 |
32 t = now.timetuple() |
32 if not now: |
33 else: |
33 if d.tzinfo: |
34 t = time.localtime() |
34 now = datetime.datetime.now(LocalTimezone(d)) |
35 if d.tzinfo: |
35 else: |
36 tz = LocalTimezone(d) |
36 now = datetime.datetime.now() |
37 else: |
|
38 tz = None |
|
39 now = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz) |
|
40 |
37 |
41 # ignore microsecond part of 'd' since we removed it from 'now' |
38 # ignore microsecond part of 'd' since we removed it from 'now' |
42 delta = now - (d - datetime.timedelta(0, 0, d.microsecond)) |
39 delta = now - (d - datetime.timedelta(0, 0, d.microsecond)) |
43 since = delta.days * 24 * 60 * 60 + delta.seconds |
40 since = delta.days * 24 * 60 * 60 + delta.seconds |
44 if since <= 0: |
41 if since <= 0: |
60 def timeuntil(d, now=None): |
57 def timeuntil(d, now=None): |
61 """ |
58 """ |
62 Like timesince, but returns a string measuring the time until |
59 Like timesince, but returns a string measuring the time until |
63 the given time. |
60 the given time. |
64 """ |
61 """ |
65 if now == None: |
62 if not now: |
66 now = datetime.datetime.now() |
63 if getattr(d, 'tzinfo', None): |
|
64 now = datetime.datetime.now(LocalTimezone(d)) |
|
65 else: |
|
66 now = datetime.datetime.now() |
67 return timesince(now, d) |
67 return timesince(now, d) |