api: make sure all inputs related to insertion_dates are tzaware

We decide to go lenient there as some values
come from an Excel client and it can be annnoying
to deal with it upstream.
3 files changed, 27 insertions(+), 0 deletions(-)

M test/test_api.py
M tshistory/api.py
M tshistory/util.py
M test/test_api.py +10 -0
@@ 101,6 101,16 @@ 2020-01-02 00:00:00+00:00    2.0
 2020-01-03 00:00:00+00:00    3.0
 """, out)
 
+    out2 = httpapi.get(
+        'api-test',
+        revision_date=utcdt(2019, 1, 1)
+    )
+    assert_df("""
+2020-01-01 00:00:00+00:00    1.0
+2020-01-02 00:00:00+00:00    2.0
+2020-01-03 00:00:00+00:00    3.0
+""", out2)
+
     hist = httpapi.history(
         'api-test'
     )

          
M tshistory/api.py +9 -0
@@ 13,6 13,7 @@ from collections import defaultdict
 from sqlalchemy import create_engine
 import pandas as pd
 
+from tshistory.util import ensuretz
 from tshistory.tsio import timeseries as tshclass
 
 

          
@@ 100,6 101,7 @@ class dbtimeseries:
         higher than the previous `insertion_date`.
 
         """
+        insertion_date = ensuretz(insertion_date)
 
         # check local existence
         if not self.tsh.exists(self.engine, name):

          
@@ 139,6 141,7 @@ class dbtimeseries:
         higher than the previous `insertion_date`.
 
         """
+        insertion_date = ensuretz(insertion_date)
 
         # check local existence
         if not self.tsh.exists(self.engine, name):

          
@@ 187,6 190,7 @@ class dbtimeseries:
         If the series does not exists, a None is returned.
 
         """
+        revision_date = ensuretz(revision_date)
 
         ts = self.tsh.get(
             self.engine,

          
@@ 214,6 218,9 @@ class dbtimeseries:
         """Get the list of all insertion dates.
 
         """
+        from_insertion_date = ensuretz(from_insertion_date)
+        to_insertion_date = ensuretz(to_insertion_date)
+
         if self.tsh.exists(self.engine, name):
             return self.tsh.insertion_dates(
                 self.engine,

          
@@ 253,6 260,8 @@ class dbtimeseries:
         `diffmode` set to False.
 
         """
+        from_insertion_date = ensuretz(from_insertion_date)
+        to_insertion_date = ensuretz(to_insertion_date)
 
         hist = self.tsh.history(
             self.engine,

          
M tshistory/util.py +8 -0
@@ 96,6 96,14 @@ def find_dburi(something: str) -> str:
 
 # tsio helpers
 
+def ensuretz(adate):
+    if adate is None:
+        return
+    if adate.tzinfo is None:
+        return pd.Timestamp(adate, tz='UTC')
+    return adate
+
+
 def tzaware_serie(ts):
     return is_datetime64tz_dtype(ts.index)