MCPcopy
hub / github.com/django/django / parse_date

Function parse_date

django/utils/dateparse.py:68–79  ·  view source on GitHub ↗

Parse a string and return a datetime.date. Raise ValueError if the input is well formatted but not a valid date. Return None if the input isn't well formatted.

(value)

Source from the content-addressed store, hash-verified

66
67
68def parse_date(value):
69 """Parse a string and return a datetime.date.
70
71 Raise ValueError if the input is well formatted but not a valid date.
72 Return None if the input isn't well formatted.
73 """
74 try:
75 return datetime.date.fromisoformat(value)
76 except ValueError:
77 if match := date_re.match(value):
78 kw = {k: int(v) for k, v in match.groupdict().items()}
79 return datetime.date(**kw)
80
81
82def parse_time(value):

Callers 4

to_pythonMethod · 0.90
to_pythonMethod · 0.90
test_parse_dateMethod · 0.90

Calls 2

matchMethod · 0.45
itemsMethod · 0.45

Tested by 1

test_parse_dateMethod · 0.72