Add a new date format code 'iso'. Permits formatting dates to see the complete time.

This commit is contained in:
Charles Haley 2011-04-14 12:18:41 +01:00
parent cecb8b5f41
commit 0cc37216b4
4 changed files with 18 additions and 12 deletions

View File

@ -364,11 +364,11 @@ class FieldMetadata(dict):
self._tb_cats[k]['display'] = {}
self._tb_cats[k]['is_editable'] = True
self._add_search_terms_to_map(k, v['search_terms'])
for x in ('timestamp', 'last_modified'):
self._tb_cats[x]['display'] = {
self._tb_cats['timestamp']['display'] = {
'date_format': tweaks['gui_timestamp_display_format']}
self._tb_cats['pubdate']['display'] = {
'date_format': tweaks['gui_pubdate_display_format']}
self._tb_cats['last_modified']['display'] = {'date_format': 'iso'}
self.custom_field_prefix = '#'
self.get = self._tb_cats.get

View File

@ -236,15 +236,16 @@ The following functions are available in addition to those described in single-f
* ``format_date(x, date_format)`` -- format_date(val, format_string) -- format the value, which must be a date field, using the format_string, returning a string. The formatting codes are::
d : the day as number without a leading zero (1 to 31)
dd : the day as number with a leading zero (01 to 31) '
ddd : the abbreviated localized day name (e.g. "Mon" to "Sun"). '
dddd : the long localized day name (e.g. "Monday" to "Sunday"). '
M : the month as number without a leading zero (1 to 12). '
MM : the month as number with a leading zero (01 to 12) '
MMM : the abbreviated localized month name (e.g. "Jan" to "Dec"). '
MMMM : the long localized month name (e.g. "January" to "December"). '
yy : the year as two digit number (00 to 99). '
yyyy : the year as four digit number.'
dd : the day as number with a leading zero (01 to 31)
ddd : the abbreviated localized day name (e.g. "Mon" to "Sun").
dddd : the long localized day name (e.g. "Monday" to "Sunday").
M : the month as number without a leading zero (1 to 12).
MM : the month as number with a leading zero (01 to 12)
MMM : the abbreviated localized month name (e.g. "Jan" to "Dec").
MMMM : the long localized month name (e.g. "January" to "December").
yy : the year as two digit number (00 to 99).
yyyy : the year as four digit number.
iso : the date with time and timezone. Must be the only format present.
* ``eval(string)`` -- evaluates the string as a program, passing the local variables (those ``assign`` ed to). This permits using the template processor to construct complex results from local variables.
* ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers.

View File

@ -142,6 +142,10 @@ def format_date(dt, format, assume_utc=False, as_utc=False):
dt = dt.replace(tzinfo=_utc_tz if assume_utc else
_local_tz)
dt = dt.astimezone(_utc_tz if as_utc else _local_tz)
if format == 'iso':
return isoformat(dt, assume_utc=assume_utc, as_utc=as_utc)
strf = partial(strftime, t=dt.timetuple())
def format_day(mo):

View File

@ -504,7 +504,8 @@ class BuiltinFormat_date(BuiltinFormatterFunction):
'MMM : the abbreviated localized month name (e.g. "Jan" to "Dec"). '
'MMMM : the long localized month name (e.g. "January" to "December"). '
'yy : the year as two digit number (00 to 99). '
'yyyy : the year as four digit number.')
'yyyy : the year as four digit number. '
'iso : the date with time and timezone. Must be the only format present')
def evaluate(self, formatter, kwargs, mi, locals, val, format_string):
if not val: