Skip to content

Commit

Permalink
Fix bug on py 3.5 and 3.6 which would otherwise convert dates as date…
Browse files Browse the repository at this point in the history
…times

Do not use dupers on py > 3.5 and add extra timezone conversions
  • Loading branch information
alberto.calderari committed Jan 13, 2018
1 parent d41cae0 commit a4c01ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ language: python

python:
- "2.7"
- "3.2.5"
- "3.2"
- "3.3"
- "3.5"

install:
- pip install -q coveralls
Expand Down
19 changes: 12 additions & 7 deletions strconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from datetime import datetime
import re

import sys

__version__ = '0.4.1'
# strconv.py
# Copyright (c) 2013 Byron Ruth
Expand Down Expand Up @@ -220,7 +222,9 @@ def infer_matrix(self, matrix, n=None, size=10):
'%H:%M:%S',
'%H:%M',
'%I:%M:%S %p',
'%I:%M:%S %z',
'%I:%M %p',
'%I:%M %z',
'%I:%M',
)

Expand All @@ -247,13 +251,14 @@ def convert_bool(s):


def convert_datetime(s, date_formats=DATE_FORMATS, time_formats=TIME_FORMATS):
if duparse:
try:
dt = duparse(s)
if dt.time():
return duparse(s)
except TypeError: # parse may throw this in py3
raise ValueError
if sys.version < '3.5':
if duparse:
try:
dt = duparse(s)
if dt.time():
return duparse(s)
except TypeError: # parse may throw this in py3
raise ValueError

for df in date_formats:
for tf in time_formats:
Expand Down

0 comments on commit a4c01ad

Please sign in to comment.