diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2006-01-09 00:54:35 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2006-01-09 00:54:35 +0000 |
| commit | 7d0bf5f2dcf34c7a28925e28fce67f44183dd77d (patch) | |
| tree | 141ae489ad2f347e83eccea17e91e3763b4c7170 | |
| parent | 6af37477bd8c3e6ac545d1461c5d2b5d63c2ffbd (diff) | |
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
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/core/formfields.py | 12 |
2 files changed, 9 insertions, 4 deletions
@@ -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) |
