Edgewall Software
Modify

Opened 15 years ago

Closed 13 years ago

#4927 closed defect (fixed)

DD/MM/YY is not a known date format.

Reported by: Mishu Owned by: Christopher Lenz
Priority: low Milestone: 0.11
Component: admin/web Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Emmanuel Blot)

In the module for Adding milestones if you type the due date in the format DD/MM/YY TRAC sends the next message:

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 387, in dispatch_request
    dispatcher.dispatch(req)
  File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 237, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/lib/python2.4/site-packages/TracWebAdmin-0.1.2dev_r4429-py2.4.egg/webadmin/web_ui.py", line 109, in process_request
    path_info)
  File "/usr/lib/python2.4/site-packages/TracWebAdmin-0.1.2dev_r4429-py2.4.egg/webadmin/ticket.py", line 163, in process_admin_request
    mil.due = util.parse_date(req.args.get('duedate'))
  File "/usr/lib/python2.4/site-packages/trac/util/datefmt.py", line 114, in parse_date
    raise ValueError, '%s is not a known date format.' % text
ValueError: 22/03/07 is not a known date format.

Attachments (0)

Change History (8)

comment:1 by Emmanuel Blot, 15 years ago

Description: modified (diff)
Milestone: none

Please specifiy which release of Trac you use. Have you defined any locale?

comment:2 by anonymous, 15 years ago

Hi, I came across the same error today. I'm using 10.3 with webadmin version 0.1.2dev_r4240-py2.4. Regardless of what the format of the date should be, it might be nice to have a nicely formated error message returned rather than the traceback.

Regards, Clint

comment:3 by Emmanuel Blot, 15 years ago

It seems that with several locales, Python refuses to parse years without a century, that is the expected format would be DD/MM/YYYY whereas DD/MM/YY would actually be rejected.

I'm still interested in knowing the locale you used to get DD/MM/YY as the expected format.

comment:4 by Emmanuel Blot, 15 years ago

Quick patch to get rid of the traceback and obtain a hint about the expected date format:

  • trac/util/datefmt.py

     
    2323import time
    2424from datetime import tzinfo, timedelta, datetime
    2525from trac.util.text import to_unicode
     26from trac.core import TracError
    2627
    2728# Date/time utilities
    2829
     
    149150            except ValueError:
    150151                continue
    151152    if tm == None:
    152         raise ValueError('%s is invalid or not a known date format' % text)
     153        hint = get_date_format_hint()
     154        raise TracError('%s is invalid or not a known date format, '
     155                        'try %s' % (text, hint), 'Invalid date')
    153156    return datetime(*(tm[0:6] + (0, tzinfo)))
    154157
    155158def to_timestamp(dt):

comment:5 by Christian Boos, 15 years ago

Milestone: 0.11

Manu, sorry for the late reply, but your change looks good. I had a pending change there (related to this bug and #4530), but I modified it in favor of your change, as raising directly a TracError instead of a ValueError is actually much simpler than wrapping every call of parse_date in an exception handler that will catch ValueError and re-raise a TracError, as we already did in several places.

comment:6 by Christian Boos, 15 years ago

Resolution: fixed
Status: newclosed

Modified patch applied in r5188. This changeset also contains the related simplifications due to the ValueErrorTracError change.

comment:7 by anonymous, 13 years ago

Resolution: fixed
Status: closedreopened

On the demo site (http://www.hosted-projects.com/trac/TracDemo/Demo) this bug still occurs when adding a milestone (http://www.hosted-projects.com/trac/TracDemo/Demo/admin/ticket/milestones).

Enter a date e.g. 02/30/09 (an invalid date). The expected result is that it doesn't give a traceback but rather a user-friendly warning.

Python Traceback

Traceback (most recent call last):

File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 406, in dispatch_request

dispatcher.dispatch(req)

File "/usr/lib/python2.5/site-packages/trac/web/main.py", line 237, in dispatch

resp = chosen_handler.process_request(req)

File "/usr/lib/python2.5/site-packages/TracWebAdmin-0.1.2dev-py2.5.egg/webadmin/web_ui.py", line 119, in process_request

path_info)

File "/usr/lib/python2.5/site-packages/TracWebAdmin-0.1.2dev-py2.5.egg/webadmin/ticket.py", line 163, in process_admin_request

mil.due = util.parse_date(req.args.get('duedate'))

File "/usr/lib/python2.5/site-packages/trac/util/datefmt.py", line 114, in parse_date

raise ValueError, '%s is not a known date format.' % text

ValueError: 02/40/09 is not a known date format.

in reply to:  7 comment:8 by Emmanuel Blot, 13 years ago

Resolution: fixed
Status: reopenedclosed

Replying to anonymous:

Enter a date e.g. 02/30/09 (an invalid date). The expected result is that it doesn't give a traceback but rather a user-friendly warning.

Hint: the demo site is running 0.10.5 while this bug has been fixed for 0.11.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christopher Lenz.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christopher Lenz to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.