Repository: opendatacube/datacube-core

Issue:
Time range Query created with Datacube is incorrect
When creating a query using the datacube query API, requesting 2 element time range from `a` to `b` is resulting in a query with a time range from `a` to `a`
See: https://github.com/opendatacube/datacube-core/blob/ef03ad272ce247d71a439cdc58934be6cca82e8b/datacube/api/query.py#L277

### Expected behaviour
```
In [19]: dt0 = datetime.datetime(2018, 6, 1)

In [20]: dt1 = datetime.datetime(2018, 6, 10)

In [21]: datacube.api.query.Query(time=(dt0, dt1))
Out[21]: 
Datacube Query:
        type = None
        search = {'time': Range(begin=datetime.datetime(2018, 6, 1, 0, 0, tzinfo=<UTC>), end=datetime.datetime(2018, 6, 10, 0, 0, 0, 999999, tzinfo=tzutc()))}
        geopolygon = None
```

### Actual behaviour

```
In [5]: dt0 = datetime.datetime(2018, 6, 1)

In [6]: dt1 = datetime.datetime(2018, 6, 10)

In [7]: datacube.api.query.Query(time=(dt0, dt1))
Out[7]: 
Datacube Query:
        type = None
        search = {'time': Range(begin=datetime.datetime(2018, 6, 1, 0, 0, tzinfo=<UTC>), end=datetime.datetime(2018, 6, 1, 0, 0, 0, 999999, tzinfo=tzutc()))}
        geopolygon = None
```

Time range Query created with Datacube is incorrect
When creating a query using the datacube query API, requesting 2 element time range from `a` to `b` is resulting in a query with a time range from `a` to `a`
See: https://github.com/opendatacube/datacube-core/blob/ef03ad272ce247d71a439cdc58934be6cca82e8b/datacube/api/query.py#L277

### Expected behaviour
```
In [19]: dt0 = datetime.datetime(2018, 6, 1)

In [20]: dt1 = datetime.datetime(2018, 6, 10)

In [21]: datacube.api.query.Query(time=(dt0, dt1))
Out[21]: 
Datacube Query:
        type = None
        search = {'time': Range(begin=datetime.datetime(2018, 6, 1, 0, 0, tzinfo=<UTC>), end=datetime.datetime(2018, 6, 10, 0, 0, 0, 999999, tzinfo=tzutc()))}
        geopolygon = None
```

### Actual behaviour

```
In [5]: dt0 = datetime.datetime(2018, 6, 1)

In [6]: dt1 = datetime.datetime(2018, 6, 10)

In [7]: datacube.api.query.Query(time=(dt0, dt1))
Out[7]: 
Datacube Query:
        type = None
        search = {'time': Range(begin=datetime.datetime(2018, 6, 1, 0, 0, tzinfo=<UTC>), end=datetime.datetime(2018, 6, 1, 0, 0, 0, 999999, tzinfo=tzutc()))}
        geopolygon = None
```



Discussion:
Is this against the latest `develop` or another branch?
`HEAD` of develop
@walsh-andrew Hi Andrew, are you able to have a look at this bug?
Is this against the latest `develop` or another branch?
`HEAD` of develop
@walsh-andrew Hi Andrew, are you able to have a look at this bug?

Resolving patch:
diff --git a/datacube/api/query.py b/datacube/api/query.py
--- a/datacube/api/query.py
+++ b/datacube/api/query.py
@@ -274,8 +274,7 @@ def _time_to_search_dims(time_range):
         if hasattr(time_range, '__iter__') and len(time_range) == 2:
             if all(isinstance(n, datetime.datetime) for n in time_range):
                 timelist = list(time_range)
-                timelist[0], timelist[1] = timelist[0].isoformat(), timelist[0].isoformat()
-                time_range = tuple(timelist)
+                time_range = timelist[0].isoformat(), timelist[1].isoformat()
             time_range = Range(_to_datetime(time_range[0]),
                                _to_datetime(pandas.Period(time_range[1]).end_time.to_pydatetime()))
             if time_range[0] == time_range[1]:
@@ -291,8 +290,7 @@ def _time_to_search_dims(time_range):
             return time_range
         else:
             timelist = list(time_range)
-            timelist[0], timelist[1] = timelist[0].isoformat(), timelist[0].isoformat()
-            time_range = tuple(timelist)
+            time_range = timelist[0].isoformat(), timelist[1].isoformat()
             time_range = Range(_to_datetime(time_range[0]),
                                _to_datetime(pandas.Period(time_range[1]).end_time.to_pydatetime()))
             return time_range


Test patch:
diff --git a/tests/api/test_query.py b/tests/api/test_query.py
--- a/tests/api/test_query.py
+++ b/tests/api/test_query.py
@@ -96,6 +96,12 @@ def format_test(start_out, end_out):
 
 
 testdata = [
+    ((datetime.datetime(2008, 1, 1), datetime.datetime(2008, 1, 10)),
+     format_test('2008-01-01T00:00:00', '2008-01-10T00:00:00.999999')),
+    ((datetime.datetime(2008, 1, 1), datetime.datetime(2008, 1, 10, 23, 0, 0)),
+     format_test('2008-01-01T00:00:00', '2008-01-10T23:00:00.999999')),
+    ((datetime.datetime(2008, 1, 1), datetime.datetime(2008, 1, 10, 23, 59, 40)),
+     format_test('2008-01-01T00:00:00', '2008-01-10T23:59:40.999999')),
     (('2008'),
      format_test('2008-01-01T00:00:00', '2008-12-31T23:59:59.999999')),
     (('2008', '2008'),