Repository: myusuf3/delorean

Issue:
parse function does not parse date string correctly
The dayfirst parameter is default to True, however, it does not make any sense when parse a full formatted date time string as below:

```
from delorean import parse
parse('2017-05-02T05:38:49.899Z').datetime
datetime.datetime(2017, 2, 5, 5, 38, 49, 899000, tzinfo=<UTC>)
```


Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 7070c17..ed1aec6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
 language: python
 python:
-  - "2.6"
   - "2.7"
   - "3.3"
   - "3.4"
diff --git a/delorean/interface.py b/delorean/interface.py
index 6821645..bd6fb83 100644
--- a/delorean/interface.py
+++ b/delorean/interface.py
@@ -3,7 +3,7 @@ from datetime import datetime
 import pytz
 
 from dateutil.rrule import rrule, DAILY, HOURLY, MONTHLY, YEARLY
-from dateutil.parser import parse as capture
+from dateutil.parser import parse as capture, isoparse as isocapture
 from dateutil.tz import tzlocal
 from dateutil.tz import tzoffset
 from tzlocal import get_localzone
@@ -12,13 +12,14 @@ from .exceptions import DeloreanInvalidDatetime
 from .dates import Delorean, is_datetime_naive, datetime_timezone
 
 
-def parse(datetime_str, timezone=None, dayfirst=True, yearfirst=True):
+def parse(datetime_str, timezone=None, isofirst=True, dayfirst=True, yearfirst=True):
     """
     Parses a datetime string and returns a `Delorean` object.
 
     :param datetime_str: The string to be interpreted into a `Delorean` object.
     :param timezone: Pass this parameter and the returned Delorean object will be normalized to this timezone. Any
         offsets passed as part of datetime_str will be ignored.
+    :param isofirst: try to parse string as date in ISO format before everything else.
     :param dayfirst: Whether to interpret the first value in an ambiguous 3-integer date (ex. 01/05/09) as the day
         (True) or month (False). If yearfirst is set to True, this distinguishes between YDM and YMD.
     :param yearfirst: Whether to interpret the first value in an ambiguous 3-integer date (ex. 01/05/09) as the
@@ -65,7 +66,15 @@ def parse(datetime_str, timezone=None, dayfirst=True, yearfirst=True):
         Delorean(datetime=datetime.datetime(2015, 1, 1, 0, 1, 2), timezone='UTC')
 
     """
-    dt = capture(datetime_str, dayfirst=dayfirst, yearfirst=yearfirst)
+    # parse string to datetime object
+    dt = None
+    if isofirst:
+        try:
+            dt = isocapture(datetime_str)
+        except Exception:
+            pass
+    if dt is None:
+        dt = capture(datetime_str, dayfirst=dayfirst, yearfirst=yearfirst)
 
     if timezone:
         dt = dt.replace(tzinfo=None)
diff --git a/requirements.txt b/requirements.txt
index a0c2bce..8cd55f9 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,12 +1,12 @@
 #
 # This file is autogenerated by pip-compile
-# Make changes in requirements.in, then run this to update:
+# To update, run:
 #
-#    pip-compile requirements.in
+#    pip-compile --output-file requirements.txt requirements.in
 #
-babel==2.1.1
+babel==2.5.3
 humanize==0.5.1
-python-dateutil==2.4.2
-pytz==2015.7
-six==1.10.0               # via python-dateutil
-tzlocal==1.2
+python-dateutil==2.7.5
+pytz==2018.7
+six==1.11.0               # via python-dateutil
+tzlocal==1.5.1
diff --git a/setup.py b/setup.py
index 5bdcd7d..600dbb5 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@ from version import __version__
 dependencies = [
     'babel>=2.1.1',
     'humanize>=0.5.1',
-    'python-dateutil>=2.4.2',
+    'python-dateutil>=2.7.0',
     'pytz>=2015.7',
     'tzlocal>=1.2']
 
@@ -22,12 +22,10 @@ setup(
     url='https://github.com/myusuf3/delorean',
     author='Mahdi Yusuf',
     author_email="yusuf.mahdi@gmail.com",
-    packages=[
-    'delorean',
-    ],
+    packages=['delorean'],
     license='MIT license',
     install_requires=dependencies,
-    test_suite = 'tests.test_data',
+    test_suite='tests.test_data',
     long_description=open('README.rst').read(),
     classifiers=[
         'Development Status :: 4 - Beta',


Test patch:
diff --git a/tests/delorean_tests.py b/tests/delorean_tests.py
index 0d05c40..8da3bef 100644
--- a/tests/delorean_tests.py
+++ b/tests/delorean_tests.py
@@ -262,6 +262,12 @@ class DeloreanTests(unittest.TestCase):
         dt1 = pytz.utc.localize(datetime(2003, 9, 25, 10, 36, 28))
         self.assertEqual(do.datetime, dt1)
 
+    def test_parse_iso(self):
+        # https://github.com/myusuf3/delorean/issues/101
+        do = delorean.parse('2017-05-02T05:38:49Z')
+        dt1 = pytz.utc.localize(datetime(2017, 5, 2, 5, 38, 49))
+        self.assertEqual(do.datetime, dt1)
+
     def test_parse_default(self):
         do = delorean.parse('2016-07-01T11:00:00+02:00', dayfirst=False)
         dt1 = delorean.Delorean(datetime=datetime(2016, 7, 1, 11, 0), timezone=pytz.FixedOffset(120))