summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--django/core/formfields.py12
2 files changed, 9 insertions, 4 deletions
diff --git a/AUTHORS b/AUTHORS
index 10b41c2e7c..5a9012dffd 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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:
diff --git a/django/core/formfields.py b/django/core/formfields.py
index c761d340a7..530c8b554b 100644
--- a/django/core/formfields.py
+++ b/django/core/formfields.py
@@ -746,7 +746,7 @@ class DateField(TextField):
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 @@ class TimeField(TextField):
"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)