Permalink
Browse files

Fixed #1188 -- Changed TimeField.html2python to handle microseconds. …

…Thanks, Cheng

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1872 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 6af3747 commit 7d0bf5f2dcf34c7a28925e28fce67f44183dd77d @adrianholovaty adrianholovaty committed Jan 9, 2006
Showing with 9 additions and 4 deletions.
  1. +1 −0 AUTHORS
  2. +8 −4 django/core/formfields.py
View
@@ -95,6 +95,7 @@ answer newbie questions, and generally made Django that much better:
Rachel Willmer <http://www.willmer.com/kb/>
wojtek
ye7cakf02@sneakemail.com
+ Cheng Zhang
A big THANK YOU goes to:
View
@@ -746,7 +746,7 @@ def html2python(data):
class TimeField(TextField):
"""A FormField that automatically converts its data to a datetime.time object.
- The data should be in the format HH:MM:SS."""
+ The data should be in the format HH:MM:SS or HH:MM:SS.mmmmmm."""
def __init__(self, field_name, is_required=False, validator_list=[]):
validator_list = [self.isValidTime] + validator_list
TextField.__init__(self, field_name, length=8, maxlength=8,
@@ -762,11 +762,15 @@ def html2python(data):
"Converts the field into a datetime.time object"
import time, datetime
try:
+ part_list = data.split('.')
try:
- time_tuple = time.strptime(data, '%H:%M:%S')
+ time_tuple = time.strptime(part_list[0], '%H:%M:%S')
except ValueError: # seconds weren't provided
- time_tuple = time.strptime(data, '%H:%M')
- return datetime.time(*time_tuple[3:6])
+ time_tuple = time.strptime(part_list[0], '%H:%M')
+ t = datetime.time(*time_tuple[3:6])
+ if (len(part_list) == 2):
+ t = t.replace(microsecond=int(part_list[1]))
+ return t
except (ValueError, TypeError):
return None
html2python = staticmethod(html2python)

0 comments on commit 7d0bf5f

Please sign in to comment.