We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Date annotation is parsed inconsistently depending on input data.
#  Bug
I've tried  compare two date fields of pydantic model's instances.
But I got: `TypeError: can't compare datetime.datetime to datetime.date`

I figured out that its a bug when parsing field annotated as  date providing a datetime value.

Since one of my instances is created from data stored in persistence (which is  typed as "datetime") and the other instance is created from a CSV, the first is treated as a datetime and the other is treated as date.

For bugs/questions:
* OS: **Linux 64-bit **
* Python version `import sys; print(sys.version)`: **3.7.1 (default, Oct 22 2018, 10:41:28)  [GCC 8.2.1 20180831]**
* Pydantic version `import pydantic; print(pydantic.VERSION)`: **0.14**

```py
from datetime import date, datetime

from pydantic import BaseModel


class DateRange(BaseModel):
    dt_start: date
    dt_finish: date



data = DateRange(dt_start=datetime(2017,11, 7, 12, 14), dt_finish=datetime(2017,11, 26, 12, 14))
data_ = DateRange(dt_start='2017-01-01', dt_finish='2018-01-01')

print(type(data.dt_finish), type(data.dt_start))
print(type(data_.dt_finish), type(data_.dt_start))
...
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pydantic/datetime_parse.py`
Content:
```
1 """
2 Functions to parse datetime objects.
3 
4 We're using regular expressions rather than time.strptime because:
5 - They provide both validation and parsing.
6 - They're more flexible for datetimes.
7 - The date/datetime/time constructors produce friendlier error messages.
8 
9 Stolen from https://raw.githubusercontent.com/django/django/master/django/utils/dateparse.py at
10 9718fa2e8abe430c3526a9278dd976443d4ae3c6
11 
12 Changed to:
13 * use standard python datetime types not django.utils.timezone
14 * raise ValueError when regex doesn't match rather than returning None
15 * support parsing unix timestamps for dates and datetimes
16 """
17 import re
18 from datetime import date, datetime, time, timedelta, timezone
19 from typing import Union
20 
21 from . import errors
22 from .utils import change_exception
23 
24 date_re = re.compile(r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$')
25 
26 time_re = re.compile(
27     r'(?P<hour>\d{1,2}):(?P<minute>\d{1,2})' r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'
28 )
29 
30 datetime_re = re.compile(
31     r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})'
32     r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})'
33     r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'
34     r'(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$'
35 )
36 
37 standard_duration_re = re.compile(
38     r'^'
39     r'(?:(?P<days>-?\d+) (days?, )?)?'
40     r'((?:(?P<hours>-?\d+):)(?=\d+:\d+))?'
41     r'(?:(?P<minutes>-?\d+):)?'
42     r'(?P<seconds>-?\d+)'
43     r'(?:\.(?P<microseconds>\d{1,6})\d{0,6})?'
44     r'$'
45 )
46 
47 # Support the sections of ISO 8601 date representation that are accepted by timedelta
48 iso8601_duration_re = re.compile(
49     r'^(?P<sign>[-+]?)'
50     r'P'
51     r'(?:(?P<days>\d+(.\d+)?)D)?'
52     r'(?:T'
53     r'(?:(?P<hours>\d+(.\d+)?)H)?'
54     r'(?:(?P<minutes>\d+(.\d+)?)M)?'
55     r'(?:(?P<seconds>\d+(.\d+)?)S)?'
56     r')?'
57     r'$'
58 )
59 
60 EPOCH = datetime(1970, 1, 1)
61 MS_WATERSHED = int(1e11)  # if greater than this, the number is in ms (in seconds this is 3rd March 5138)
62 StrIntFloat = Union[str, int, float]
63 
64 
65 def get_numeric(value: StrIntFloat):
66     if isinstance(value, (int, float)):
67         return value
68     try:
69         return int(value)
70     except ValueError:
71         pass
72     try:
73         return float(value)
74     except ValueError:
75         pass
76 
77 
78 def from_unix_seconds(seconds: int) -> datetime:
79     while seconds > MS_WATERSHED:
80         seconds /= 1000
81     dt = EPOCH + timedelta(seconds=seconds)
82     return dt.replace(tzinfo=timezone.utc)
83 
84 
85 def parse_date(value: Union[date, StrIntFloat]) -> date:
86     """
87     Parse a date/int/float/string and return a datetime.date.
88 
89     Raise ValueError if the input is well formatted but not a valid date.
90     Raise ValueError if the input isn't well formatted.
91     """
92     if isinstance(value, date):
93         return value
94 
95     number = get_numeric(value)
96     if number is not None:
97         return from_unix_seconds(number).date()
98 
99     match = date_re.match(value)
100     if not match:
101         raise errors.DateError()
102 
103     kw = {k: int(v) for k, v in match.groupdict().items()}
104 
105     with change_exception(errors.DateError, ValueError):
106         return date(**kw)
107 
108 
109 def parse_time(value: Union[time, str]) -> time:
110     """
111     Parse a time/string and return a datetime.time.
112 
113     This function doesn't support time zone offsets.
114 
115     Raise ValueError if the input is well formatted but not a valid time.
116     Raise ValueError if the input isn't well formatted, in particular if it contains an offset.
117     """
118     if isinstance(value, time):
119         return value
120 
121     match = time_re.match(value)
122     if not match:
123         raise errors.TimeError()
124 
125     kw = match.groupdict()
126     if kw['microsecond']:
127         kw['microsecond'] = kw['microsecond'].ljust(6, '0')
128 
129     kw = {k: int(v) for k, v in kw.items() if v is not None}
130 
131     with change_exception(errors.TimeError, ValueError):
132         return time(**kw)
133 
134 
135 def parse_datetime(value: Union[datetime, StrIntFloat]) -> datetime:
136     """
137     Parse a datetime/int/float/string and return a datetime.datetime.
138 
139     This function supports time zone offsets. When the input contains one,
140     the output uses a timezone with a fixed offset from UTC.
141 
142     Raise ValueError if the input is well formatted but not a valid datetime.
143     Raise ValueError if the input isn't well formatted.
144     """
145     if isinstance(value, datetime):
146         return value
147 
148     number = get_numeric(value)
149     if number is not None:
150         return from_unix_seconds(number)
151 
152     match = datetime_re.match(value)
153     if not match:
154         raise errors.DateTimeError()
155 
156     kw = match.groupdict()
157     if kw['microsecond']:
158         kw['microsecond'] = kw['microsecond'].ljust(6, '0')
159 
160     tzinfo = kw.pop('tzinfo')
161     if tzinfo == 'Z':
162         tzinfo = timezone.utc
163     elif tzinfo is not None:
164         offset_mins = int(tzinfo[-2:]) if len(tzinfo) > 3 else 0
165         offset = 60 * int(tzinfo[1:3]) + offset_mins
166         if tzinfo[0] == '-':
167             offset = -offset
168         tzinfo = timezone(timedelta(minutes=offset))
169 
170     kw = {k: int(v) for k, v in kw.items() if v is not None}
171     kw['tzinfo'] = tzinfo
172 
173     with change_exception(errors.DateTimeError, ValueError):
174         return datetime(**kw)
175 
176 
177 def parse_duration(value: StrIntFloat) -> timedelta:
178     """
179     Parse a duration int/float/string and return a datetime.timedelta.
180 
181     The preferred format for durations in Django is '%d %H:%M:%S.%f'.
182 
183     Also supports ISO 8601 representation.
184     """
185     if isinstance(value, timedelta):
186         return value
187 
188     if isinstance(value, (int, float)):
189         # bellow code requires a string
190         value = str(value)
191 
192     match = standard_duration_re.match(value) or iso8601_duration_re.match(value)
193     if not match:
194         raise errors.DurationError()
195 
196     kw = match.groupdict()
197     sign = -1 if kw.pop('sign', '+') == '-' else 1
198     if kw.get('microseconds'):
199         kw['microseconds'] = kw['microseconds'].ljust(6, '0')
200 
201     if kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-'):
202         kw['microseconds'] = '-' + kw['microseconds']
203 
204     kw = {k: float(v) for k, v in kw.items() if v is not None}
205 
206     return sign * timedelta(**kw)
207
```

Path: `pydantic/version.py`
Content:
```
1 from distutils.version import StrictVersion
2 
3 __all__ = ['VERSION']
4 
5 VERSION = StrictVersion('0.14')
6
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pydantic/datetime_parse.py b/pydantic/datetime_parse.py
--- a/pydantic/datetime_parse.py
+++ b/pydantic/datetime_parse.py
@@ -90,7 +90,10 @@
     Raise ValueError if the input isn't well formatted.
     """
     if isinstance(value, date):
-        return value
+        if isinstance(value, datetime):
+            return value.date()
+        else:
+            return value
 
     number = get_numeric(value)
     if number is not None:
diff --git a/pydantic/version.py b/pydantic/version.py
--- a/pydantic/version.py
+++ b/pydantic/version.py
@@ -2,4 +2,4 @@
 
 __all__ = ['VERSION']
 
-VERSION = StrictVersion('0.14')
+VERSION = StrictVersion('0.15a1')

{"golden_diff": "diff --git a/pydantic/datetime_parse.py b/pydantic/datetime_parse.py\n--- a/pydantic/datetime_parse.py\n+++ b/pydantic/datetime_parse.py\n@@ -90,7 +90,10 @@\n     Raise ValueError if the input isn't well formatted.\n     \"\"\"\n     if isinstance(value, date):\n-        return value\n+        if isinstance(value, datetime):\n+            return value.date()\n+        else:\n+            return value\n \n     number = get_numeric(value)\n     if number is not None:\ndiff --git a/pydantic/version.py b/pydantic/version.py\n--- a/pydantic/version.py\n+++ b/pydantic/version.py\n@@ -2,4 +2,4 @@\n \n __all__ = ['VERSION']\n \n-VERSION = StrictVersion('0.14')\n+VERSION = StrictVersion('0.15a1')\n", "issue": "Date annotation is parsed inconsistently depending on input data.\n#  Bug\r\nI've tried  compare two date fields of pydantic model's instances.\r\nBut I got: `TypeError: can't compare datetime.datetime to datetime.date`\r\n\r\nI figured out that its a bug when parsing field annotated as  date providing a datetime value.\r\n\r\nSince one of my instances is created from data stored in persistence (which is  typed as \"datetime\") and the other instance is created from a CSV, the first is treated as a datetime and the other is treated as date.\r\n\r\nFor bugs/questions:\r\n* OS: **Linux 64-bit **\r\n* Python version `import sys; print(sys.version)`: **3.7.1 (default, Oct 22 2018, 10:41:28)  [GCC 8.2.1 20180831]**\r\n* Pydantic version `import pydantic; print(pydantic.VERSION)`: **0.14**\r\n\r\n```py\r\nfrom datetime import date, datetime\r\n\r\nfrom pydantic import BaseModel\r\n\r\n\r\nclass DateRange(BaseModel):\r\n    dt_start: date\r\n    dt_finish: date\r\n\r\n\r\n\r\ndata = DateRange(dt_start=datetime(2017,11, 7, 12, 14), dt_finish=datetime(2017,11, 26, 12, 14))\r\ndata_ = DateRange(dt_start='2017-01-01', dt_finish='2018-01-01')\r\n\r\nprint(type(data.dt_finish), type(data.dt_start))\r\nprint(type(data_.dt_finish), type(data_.dt_start))\r\n...\r\n```\r\n\n", "before_files": [{"content": "\"\"\"\nFunctions to parse datetime objects.\n\nWe're using regular expressions rather than time.strptime because:\n- They provide both validation and parsing.\n- They're more flexible for datetimes.\n- The date/datetime/time constructors produce friendlier error messages.\n\nStolen from https://raw.githubusercontent.com/django/django/master/django/utils/dateparse.py at\n9718fa2e8abe430c3526a9278dd976443d4ae3c6\n\nChanged to:\n* use standard python datetime types not django.utils.timezone\n* raise ValueError when regex doesn't match rather than returning None\n* support parsing unix timestamps for dates and datetimes\n\"\"\"\nimport re\nfrom datetime import date, datetime, time, timedelta, timezone\nfrom typing import Union\n\nfrom . import errors\nfrom .utils import change_exception\n\ndate_re = re.compile(r'(?P<year>\\d{4})-(?P<month>\\d{1,2})-(?P<day>\\d{1,2})$')\n\ntime_re = re.compile(\n    r'(?P<hour>\\d{1,2}):(?P<minute>\\d{1,2})' r'(?::(?P<second>\\d{1,2})(?:\\.(?P<microsecond>\\d{1,6})\\d{0,6})?)?'\n)\n\ndatetime_re = re.compile(\n    r'(?P<year>\\d{4})-(?P<month>\\d{1,2})-(?P<day>\\d{1,2})'\n    r'[T ](?P<hour>\\d{1,2}):(?P<minute>\\d{1,2})'\n    r'(?::(?P<second>\\d{1,2})(?:\\.(?P<microsecond>\\d{1,6})\\d{0,6})?)?'\n    r'(?P<tzinfo>Z|[+-]\\d{2}(?::?\\d{2})?)?$'\n)\n\nstandard_duration_re = re.compile(\n    r'^'\n    r'(?:(?P<days>-?\\d+) (days?, )?)?'\n    r'((?:(?P<hours>-?\\d+):)(?=\\d+:\\d+))?'\n    r'(?:(?P<minutes>-?\\d+):)?'\n    r'(?P<seconds>-?\\d+)'\n    r'(?:\\.(?P<microseconds>\\d{1,6})\\d{0,6})?'\n    r'$'\n)\n\n# Support the sections of ISO 8601 date representation that are accepted by timedelta\niso8601_duration_re = re.compile(\n    r'^(?P<sign>[-+]?)'\n    r'P'\n    r'(?:(?P<days>\\d+(.\\d+)?)D)?'\n    r'(?:T'\n    r'(?:(?P<hours>\\d+(.\\d+)?)H)?'\n    r'(?:(?P<minutes>\\d+(.\\d+)?)M)?'\n    r'(?:(?P<seconds>\\d+(.\\d+)?)S)?'\n    r')?'\n    r'$'\n)\n\nEPOCH = datetime(1970, 1, 1)\nMS_WATERSHED = int(1e11)  # if greater than this, the number is in ms (in seconds this is 3rd March 5138)\nStrIntFloat = Union[str, int, float]\n\n\ndef get_numeric(value: StrIntFloat):\n    if isinstance(value, (int, float)):\n        return value\n    try:\n        return int(value)\n    except ValueError:\n        pass\n    try:\n        return float(value)\n    except ValueError:\n        pass\n\n\ndef from_unix_seconds(seconds: int) -> datetime:\n    while seconds > MS_WATERSHED:\n        seconds /= 1000\n    dt = EPOCH + timedelta(seconds=seconds)\n    return dt.replace(tzinfo=timezone.utc)\n\n\ndef parse_date(value: Union[date, StrIntFloat]) -> date:\n    \"\"\"\n    Parse a date/int/float/string and return a datetime.date.\n\n    Raise ValueError if the input is well formatted but not a valid date.\n    Raise ValueError if the input isn't well formatted.\n    \"\"\"\n    if isinstance(value, date):\n        return value\n\n    number = get_numeric(value)\n    if number is not None:\n        return from_unix_seconds(number).date()\n\n    match = date_re.match(value)\n    if not match:\n        raise errors.DateError()\n\n    kw = {k: int(v) for k, v in match.groupdict().items()}\n\n    with change_exception(errors.DateError, ValueError):\n        return date(**kw)\n\n\ndef parse_time(value: Union[time, str]) -> time:\n    \"\"\"\n    Parse a time/string and return a datetime.time.\n\n    This function doesn't support time zone offsets.\n\n    Raise ValueError if the input is well formatted but not a valid time.\n    Raise ValueError if the input isn't well formatted, in particular if it contains an offset.\n    \"\"\"\n    if isinstance(value, time):\n        return value\n\n    match = time_re.match(value)\n    if not match:\n        raise errors.TimeError()\n\n    kw = match.groupdict()\n    if kw['microsecond']:\n        kw['microsecond'] = kw['microsecond'].ljust(6, '0')\n\n    kw = {k: int(v) for k, v in kw.items() if v is not None}\n\n    with change_exception(errors.TimeError, ValueError):\n        return time(**kw)\n\n\ndef parse_datetime(value: Union[datetime, StrIntFloat]) -> datetime:\n    \"\"\"\n    Parse a datetime/int/float/string and return a datetime.datetime.\n\n    This function supports time zone offsets. When the input contains one,\n    the output uses a timezone with a fixed offset from UTC.\n\n    Raise ValueError if the input is well formatted but not a valid datetime.\n    Raise ValueError if the input isn't well formatted.\n    \"\"\"\n    if isinstance(value, datetime):\n        return value\n\n    number = get_numeric(value)\n    if number is not None:\n        return from_unix_seconds(number)\n\n    match = datetime_re.match(value)\n    if not match:\n        raise errors.DateTimeError()\n\n    kw = match.groupdict()\n    if kw['microsecond']:\n        kw['microsecond'] = kw['microsecond'].ljust(6, '0')\n\n    tzinfo = kw.pop('tzinfo')\n    if tzinfo == 'Z':\n        tzinfo = timezone.utc\n    elif tzinfo is not None:\n        offset_mins = int(tzinfo[-2:]) if len(tzinfo) > 3 else 0\n        offset = 60 * int(tzinfo[1:3]) + offset_mins\n        if tzinfo[0] == '-':\n            offset = -offset\n        tzinfo = timezone(timedelta(minutes=offset))\n\n    kw = {k: int(v) for k, v in kw.items() if v is not None}\n    kw['tzinfo'] = tzinfo\n\n    with change_exception(errors.DateTimeError, ValueError):\n        return datetime(**kw)\n\n\ndef parse_duration(value: StrIntFloat) -> timedelta:\n    \"\"\"\n    Parse a duration int/float/string and return a datetime.timedelta.\n\n    The preferred format for durations in Django is '%d %H:%M:%S.%f'.\n\n    Also supports ISO 8601 representation.\n    \"\"\"\n    if isinstance(value, timedelta):\n        return value\n\n    if isinstance(value, (int, float)):\n        # bellow code requires a string\n        value = str(value)\n\n    match = standard_duration_re.match(value) or iso8601_duration_re.match(value)\n    if not match:\n        raise errors.DurationError()\n\n    kw = match.groupdict()\n    sign = -1 if kw.pop('sign', '+') == '-' else 1\n    if kw.get('microseconds'):\n        kw['microseconds'] = kw['microseconds'].ljust(6, '0')\n\n    if kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-'):\n        kw['microseconds'] = '-' + kw['microseconds']\n\n    kw = {k: float(v) for k, v in kw.items() if v is not None}\n\n    return sign * timedelta(**kw)\n", "path": "pydantic/datetime_parse.py"}, {"content": "from distutils.version import StrictVersion\n\n__all__ = ['VERSION']\n\nVERSION = StrictVersion('0.14')\n", "path": "pydantic/version.py"}], "after_files": [{"content": "\"\"\"\nFunctions to parse datetime objects.\n\nWe're using regular expressions rather than time.strptime because:\n- They provide both validation and parsing.\n- They're more flexible for datetimes.\n- The date/datetime/time constructors produce friendlier error messages.\n\nStolen from https://raw.githubusercontent.com/django/django/master/django/utils/dateparse.py at\n9718fa2e8abe430c3526a9278dd976443d4ae3c6\n\nChanged to:\n* use standard python datetime types not django.utils.timezone\n* raise ValueError when regex doesn't match rather than returning None\n* support parsing unix timestamps for dates and datetimes\n\"\"\"\nimport re\nfrom datetime import date, datetime, time, timedelta, timezone\nfrom typing import Union\n\nfrom . import errors\nfrom .utils import change_exception\n\ndate_re = re.compile(r'(?P<year>\\d{4})-(?P<month>\\d{1,2})-(?P<day>\\d{1,2})$')\n\ntime_re = re.compile(\n    r'(?P<hour>\\d{1,2}):(?P<minute>\\d{1,2})' r'(?::(?P<second>\\d{1,2})(?:\\.(?P<microsecond>\\d{1,6})\\d{0,6})?)?'\n)\n\ndatetime_re = re.compile(\n    r'(?P<year>\\d{4})-(?P<month>\\d{1,2})-(?P<day>\\d{1,2})'\n    r'[T ](?P<hour>\\d{1,2}):(?P<minute>\\d{1,2})'\n    r'(?::(?P<second>\\d{1,2})(?:\\.(?P<microsecond>\\d{1,6})\\d{0,6})?)?'\n    r'(?P<tzinfo>Z|[+-]\\d{2}(?::?\\d{2})?)?$'\n)\n\nstandard_duration_re = re.compile(\n    r'^'\n    r'(?:(?P<days>-?\\d+) (days?, )?)?'\n    r'((?:(?P<hours>-?\\d+):)(?=\\d+:\\d+))?'\n    r'(?:(?P<minutes>-?\\d+):)?'\n    r'(?P<seconds>-?\\d+)'\n    r'(?:\\.(?P<microseconds>\\d{1,6})\\d{0,6})?'\n    r'$'\n)\n\n# Support the sections of ISO 8601 date representation that are accepted by timedelta\niso8601_duration_re = re.compile(\n    r'^(?P<sign>[-+]?)'\n    r'P'\n    r'(?:(?P<days>\\d+(.\\d+)?)D)?'\n    r'(?:T'\n    r'(?:(?P<hours>\\d+(.\\d+)?)H)?'\n    r'(?:(?P<minutes>\\d+(.\\d+)?)M)?'\n    r'(?:(?P<seconds>\\d+(.\\d+)?)S)?'\n    r')?'\n    r'$'\n)\n\nEPOCH = datetime(1970, 1, 1)\nMS_WATERSHED = int(1e11)  # if greater than this, the number is in ms (in seconds this is 3rd March 5138)\nStrIntFloat = Union[str, int, float]\n\n\ndef get_numeric(value: StrIntFloat):\n    if isinstance(value, (int, float)):\n        return value\n    try:\n        return int(value)\n    except ValueError:\n        pass\n    try:\n        return float(value)\n    except ValueError:\n        pass\n\n\ndef from_unix_seconds(seconds: int) -> datetime:\n    while seconds > MS_WATERSHED:\n        seconds /= 1000\n    dt = EPOCH + timedelta(seconds=seconds)\n    return dt.replace(tzinfo=timezone.utc)\n\n\ndef parse_date(value: Union[date, StrIntFloat]) -> date:\n    \"\"\"\n    Parse a date/int/float/string and return a datetime.date.\n\n    Raise ValueError if the input is well formatted but not a valid date.\n    Raise ValueError if the input isn't well formatted.\n    \"\"\"\n    if isinstance(value, date):\n        if isinstance(value, datetime):\n            return value.date()\n        else:\n            return value\n\n    number = get_numeric(value)\n    if number is not None:\n        return from_unix_seconds(number).date()\n\n    match = date_re.match(value)\n    if not match:\n        raise errors.DateError()\n\n    kw = {k: int(v) for k, v in match.groupdict().items()}\n\n    with change_exception(errors.DateError, ValueError):\n        return date(**kw)\n\n\ndef parse_time(value: Union[time, str]) -> time:\n    \"\"\"\n    Parse a time/string and return a datetime.time.\n\n    This function doesn't support time zone offsets.\n\n    Raise ValueError if the input is well formatted but not a valid time.\n    Raise ValueError if the input isn't well formatted, in particular if it contains an offset.\n    \"\"\"\n    if isinstance(value, time):\n        return value\n\n    match = time_re.match(value)\n    if not match:\n        raise errors.TimeError()\n\n    kw = match.groupdict()\n    if kw['microsecond']:\n        kw['microsecond'] = kw['microsecond'].ljust(6, '0')\n\n    kw = {k: int(v) for k, v in kw.items() if v is not None}\n\n    with change_exception(errors.TimeError, ValueError):\n        return time(**kw)\n\n\ndef parse_datetime(value: Union[datetime, StrIntFloat]) -> datetime:\n    \"\"\"\n    Parse a datetime/int/float/string and return a datetime.datetime.\n\n    This function supports time zone offsets. When the input contains one,\n    the output uses a timezone with a fixed offset from UTC.\n\n    Raise ValueError if the input is well formatted but not a valid datetime.\n    Raise ValueError if the input isn't well formatted.\n    \"\"\"\n    if isinstance(value, datetime):\n        return value\n\n    number = get_numeric(value)\n    if number is not None:\n        return from_unix_seconds(number)\n\n    match = datetime_re.match(value)\n    if not match:\n        raise errors.DateTimeError()\n\n    kw = match.groupdict()\n    if kw['microsecond']:\n        kw['microsecond'] = kw['microsecond'].ljust(6, '0')\n\n    tzinfo = kw.pop('tzinfo')\n    if tzinfo == 'Z':\n        tzinfo = timezone.utc\n    elif tzinfo is not None:\n        offset_mins = int(tzinfo[-2:]) if len(tzinfo) > 3 else 0\n        offset = 60 * int(tzinfo[1:3]) + offset_mins\n        if tzinfo[0] == '-':\n            offset = -offset\n        tzinfo = timezone(timedelta(minutes=offset))\n\n    kw = {k: int(v) for k, v in kw.items() if v is not None}\n    kw['tzinfo'] = tzinfo\n\n    with change_exception(errors.DateTimeError, ValueError):\n        return datetime(**kw)\n\n\ndef parse_duration(value: StrIntFloat) -> timedelta:\n    \"\"\"\n    Parse a duration int/float/string and return a datetime.timedelta.\n\n    The preferred format for durations in Django is '%d %H:%M:%S.%f'.\n\n    Also supports ISO 8601 representation.\n    \"\"\"\n    if isinstance(value, timedelta):\n        return value\n\n    if isinstance(value, (int, float)):\n        # bellow code requires a string\n        value = str(value)\n\n    match = standard_duration_re.match(value) or iso8601_duration_re.match(value)\n    if not match:\n        raise errors.DurationError()\n\n    kw = match.groupdict()\n    sign = -1 if kw.pop('sign', '+') == '-' else 1\n    if kw.get('microseconds'):\n        kw['microseconds'] = kw['microseconds'].ljust(6, '0')\n\n    if kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-'):\n        kw['microseconds'] = '-' + kw['microseconds']\n\n    kw = {k: float(v) for k, v in kw.items() if v is not None}\n\n    return sign * timedelta(**kw)\n", "path": "pydantic/datetime_parse.py"}, {"content": "from distutils.version import StrictVersion\n\n__all__ = ['VERSION']\n\nVERSION = StrictVersion('0.15a1')\n", "path": "pydantic/version.py"}]}