do not depend on types.StringTypes anymore
[sfa.git] / sfa / util / sfatime.py
index 75a2e4a..7435667 100644 (file)
@@ -20,7 +20,8 @@
 # OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
 # IN THE WORK.
 #----------------------------------------------------------------------
-from types import StringTypes
+from __future__ import print_function
+
 import time
 import datetime
 import dateutil.parser
@@ -28,6 +29,7 @@ import calendar
 import re
 
 from sfa.util.sfalogging import logger
+from sfa.util.py23 import StringType
 
 SFATIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
 
@@ -53,7 +55,7 @@ For safety this can also handle inputs that are either timestamps, or datetimes
 
     # prepare the input for the checks below by
     # casting strings ('1327098335') to ints
-    if isinstance(input, StringTypes):
+    if isinstance(input, StringType):
         try:
             input = int(input)
         except ValueError:
@@ -68,7 +70,7 @@ For safety this can also handle inputs that are either timestamps, or datetimes
     if isinstance (input, datetime.datetime):
         #logger.info ("argument to utcparse already a datetime - doing nothing")
         return input
-    elif isinstance (input, StringTypes):
+    elif isinstance (input, StringType):
         t = dateutil.parser.parse(input)
         if t.utcoffset() is not None:
             t = t.utcoffset() + t.replace(tzinfo=None)
@@ -98,9 +100,9 @@ def add_datetime(input, days=0, hours=0, minutes=0, seconds=0):
 
 if __name__ == '__main__':
         # checking consistency
-    print 20*'X'
-    print ("Should be close to zero: %s"%(datetime_to_epoch(datetime.datetime.utcnow())-time.time()))
-    print 20*'X'
+    print(20*'X')
+    print(("Should be close to zero: %s"%(datetime_to_epoch(datetime.datetime.utcnow())-time.time())))
+    print(20*'X')
     for input in [
             '+2d',
             '+3w',
@@ -112,4 +114,4 @@ if __name__ == '__main__':
             '2014-05-28T15:18',
             '2014-05-28T15:18:30',
     ]:
-        print "input=%20s -> parsed %s"%(input,datetime_to_string(utcparse(input)))
+        print("input=%20s -> parsed %s"%(input,datetime_to_string(utcparse(input))))