Edgewall Software

Opened 11 years ago

Last modified 11 years ago

#11012 closed defect

regression in format_date, etc. — at Version 3

Reported by: Christian Boos Owned by: Jun Omae
Priority: normal Milestone: 1.0.1
Component: general Version: 1.0-stable
Severity: major Keywords: datetime
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christian Boos)

Looks like in r11445 the support for format='iso8601' in format_date and format_time is gone. We probably didn't have unit tests for that feature, but it was documented (format_datetime).

I suppose something like this would do:

  • datefmt.py

     
    196196
    197197def _format_datetime(t, format, tzinfo, locale, hint):
    198198    t = to_datetime(t, tzinfo or localtz)
    199199
     200    if format == 'iso8601':
     201        return _format_datetime_without_babel(t, format + hint)
     202
    200203    if locale == 'iso8601':
    201204        format = _ISO8601_FORMATS[hint].get(format, format)

(+ some tests, of course)

Change History (3)

comment:1 by Jun Omae, 11 years ago

Owner: set to Jun Omae
Status: newassigned

Oh…. The unit tests for format_datetime with format=iso8601 are in branches/1.0-stable/trac/util/tests/datefmt.py#L526, but the tests for format_date and format_time are missing.

I'll commit the patch with tests later. Thanks!

$ PYTHONPATH=$PWD ~/venv/py25/bin/python
Python 2.5.6 (r256:88840, Feb 29 2012, 04:03:24)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from trac.util.datefmt import to_datetime, format_datetime, format_date, format_time
>>> dt = to_datetime(None)
>>> format_datetime(dt, format='iso8601')      # ok
u'2013-01-10T01:12:23+09:00'
>>> format_datetime(dt, format='iso8601date')  # ok
u'2013-01-10'
>>> format_datetime(dt, format='iso8601time')  # ok
u'01:12:23+09:00'
>>> format_date(dt, format='iso8601')          # expected '2013-01-10'
u'2013-01-10T01:12:23+09:00'
>>> format_time(dt, format='iso8601')          # expected '01:12:23+09:00'
u'2013-01-10T01:12:23+09:00'
>>>

comment:2 by Christian Boos, 11 years ago

Great! Thank you Jun.

comment:3 by Christian Boos, 11 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.