Here are the examples of the python api django.forms.TimeField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
22 Examples
3
View Complete Implementation : test_timefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield_1(self):
f = TimeField()
self.astertEqual(datetime.time(14, 25), f.clean(datetime.time(14, 25)))
self.astertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
self.astertEqual(datetime.time(14, 25), f.clean('14:25'))
self.astertEqual(datetime.time(14, 25, 59), f.clean('14:25:59'))
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean('hello')
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean('1:24 p.m.')
3
View Complete Implementation : test_timefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield_2(self):
f = TimeField(input_formats=['%I:%M %p'])
self.astertEqual(datetime.time(14, 25), f.clean(datetime.time(14, 25)))
self.astertEqual(datetime.time(14, 25, 59), f.clean(datetime.time(14, 25, 59)))
self.astertEqual(datetime.time(4, 25), f.clean('4:25 AM'))
self.astertEqual(datetime.time(16, 25), f.clean('4:25 PM'))
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean('14:30:45')
3
View Complete Implementation : test_timefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield_3(self):
f = TimeField()
# Test whitespace stripping behavior (#5714)
self.astertEqual(datetime.time(14, 25), f.clean(' 14:25 '))
self.astertEqual(datetime.time(14, 25, 59), f.clean(' 14:25:59 '))
with self.astertRaisesMessage(ValidationError, "'Enter a valid time.'"):
f.clean(' ')
3
View Complete Implementation : test_timefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield_changed(self):
t1 = datetime.time(12, 51, 34, 482548)
t2 = datetime.time(12, 51)
f = TimeField(input_formats=['%H:%M', '%H:%M %p'])
self.astertTrue(f.has_changed(t1, '12:51'))
self.astertFalse(f.has_changed(t2, '12:51'))
self.astertFalse(f.has_changed(t2, '12:51 PM'))
3
View Complete Implementation : test_error_messages.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timefield(self):
e = {
'required': 'REQUIRED',
'invalid': 'INVALID',
}
f = TimeField(error_messages=e)
self.astertFormErrors(['REQUIRED'], f.clean, '')
self.astertFormErrors(['INVALID'], f.clean, 'abc')
3
View Complete Implementation : test_forms.py
Copyright Apache License 2.0
Author : ooknosi
Copyright Apache License 2.0
Author : ooknosi
def test_MaterialForm_materializes_TimeField(self):
"""django.forms.widgets.TimeInput should be converted to
material_widgets.widgets.MaterialTimeInput.
"""
clast TimeInputForm(MaterialForm):
time_input = forms.TimeField()
form = TimeInputForm()
self.astertEqual(
type(form.fields['time_input'].widget),
widgets.MaterialTimeInput,
)
0
View Complete Implementation : fields.py
Copyright Apache License 2.0
Author : BeanWei
Copyright Apache License 2.0
Author : BeanWei
def __init__(self, *args, **kwargs):
fields = (
forms.TimeField(),
forms.TimeField())
super(TimeRangeField, self).__init__(fields, *args, **kwargs)
0
View Complete Implementation : __init__.py
Copyright GNU General Public License v2.0
Author : blackye
Copyright GNU General Public License v2.0
Author : blackye
def formfield(self, **kwargs):
defaults = {'form_clast': forms.TimeField}
defaults.update(kwargs)
return super(TimeField, self).formfield(**defaults)
0
View Complete Implementation : converter.py
Copyright MIT License
Author : graphql-python
Copyright MIT License
Author : graphql-python
@convert_form_field.register(forms.TimeField)
def convert_form_field_to_time(field):
return Time(description=field.help_text, required=field.required)
0
View Complete Implementation : test_converter.py
Copyright MIT License
Author : graphql-python
Copyright MIT License
Author : graphql-python
def test_should_time_convert_time():
astert_conversion(forms.TimeField, Time)
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timeField(self):
"TimeFields can parse dates in the default format"
f = forms.TimeField()
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
# Parse a time in a valid format, get a parsed result
result = f.clean('13:30:05')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip
text = f.widget.format_value(result)
self.astertEqual(text, '13:30:05')
# Parse a time in a valid, but non-default format, get a parsed result
result = f.clean('13:30')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:00")
# ISO formats are accepted, even if not specified in formats.py
result = f.clean('13:30:05.000155')
self.astertEqual(result, time(13, 30, 5, 155))
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_localized_timeField(self):
"Localized TimeFields act as unlocalized widgets"
f = forms.TimeField(localize=True)
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
# Parse a time in a valid format, get a parsed result
result = f.clean('13:30:05')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, '13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13:30')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:00")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timeField_with_inputformat(self):
"TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
with self.astertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30.05')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:05")
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:00")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_localized_timeField_with_inputformat(self):
"Localized TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True)
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
with self.astertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30.05')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:05")
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:00")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timeField(self):
"TimeFields can parse dates in the default format"
f = forms.TimeField()
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('1:30:05 PM')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip
text = f.widget.format_value(result)
self.astertEqual(text, '01:30:05 PM')
# Parse a time in a valid, but non-default format, get a parsed result
result = f.clean('1:30 PM')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "01:30:00 PM")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_localized_timeField(self):
"Localized TimeFields act as unlocalized widgets"
f = forms.TimeField(localize=True)
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('1:30:05 PM')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, '01:30:05 PM')
# Parse a time in a valid format, get a parsed result
result = f.clean('01:30 PM')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "01:30:00 PM")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timeField_with_inputformat(self):
"TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"])
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
with self.astertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30.05')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, "01:30:05 PM")
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "01:30:00 PM")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_localized_timeField_with_inputformat(self):
"Localized TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%H.%M.%S", "%H.%M"], localize=True)
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
with self.astertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30.05')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, "01:30:05 PM")
# Parse a time in a valid format, get a parsed result
result = f.clean('13.30')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "01:30:00 PM")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timeField(self):
"TimeFields can parse dates in the default format"
f = forms.TimeField()
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
# Parse a time in a valid format, get a parsed result
result = f.clean('13:30:05')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:05")
# Parse a time in a valid, but non-default format, get a parsed result
result = f.clean('13:30')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:00")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_localized_timeField(self):
"Localized TimeFields in a non-localized environment act as unlocalized widgets"
f = forms.TimeField()
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('1:30:05 PM')
# Parse a time in a valid format, get a parsed result
result = f.clean('13:30:05')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:05")
# Parse a time in a valid format, get a parsed result
result = f.clean('13:30')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:00")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_timeField_with_inputformat(self):
"TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"])
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('1:30:05 PM')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:05")
# Parse a time in a valid format, get a parsed result
result = f.clean('1:30 PM')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:00")
0
View Complete Implementation : test_input_formats.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_localized_timeField_with_inputformat(self):
"Localized TimeFields with manually specified input formats can accept those formats"
f = forms.TimeField(input_formats=["%I:%M:%S %p", "%I:%M %p"], localize=True)
# Parse a time in an unaccepted format; get an error
with self.astertRaises(forms.ValidationError):
f.clean('13:30:05')
# Parse a time in a valid format, get a parsed result
result = f.clean('1:30:05 PM')
self.astertEqual(result, time(13, 30, 5))
# The parsed result does a round trip to the same format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:05")
# Parse a time in a valid format, get a parsed result
result = f.clean('1:30 PM')
self.astertEqual(result, time(13, 30, 0))
# The parsed result does a round trip to default format
text = f.widget.format_value(result)
self.astertEqual(text, "13:30:00")