Add workarounds for certain display bugs when rendering datetimes

This commit is contained in:
Lance Edgar 2016-04-21 13:42:20 -05:00
parent 74f02ebb0d
commit c7c2fecec0

View file

@ -91,6 +91,16 @@ def raw_datetime(config, value):
local = timezone(config)
value = local.normalize(value.astimezone(local))
return HTML.tag('span',
title=humanize.naturaltime(time_ago),
c=value.strftime('%Y-%m-%d %I:%M:%S %p'))
kwargs = {}
# Avoid strftime error when year falls before epoch.
if value.year >= 1900:
kwargs['c'] = value.strftime('%Y-%m-%d %I:%M:%S %p')
else:
kwargs['c'] = unicode(value)
# Avoid humanize error when calculating huge time diff.
if abs(time_ago.days) < 100000:
kwargs['title'] = humanize.naturaltime(time_ago)
return HTML.tag('span', **kwargs)