Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyan99 committed Oct 15, 2020
1 parent 3ff09e6 commit 0f86fee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ def convert_datetime(date_time):
# type: (Union[str, datetime.datetime]) -> datetime.datetime
if isinstance(date_time, datetime.datetime):
return date_time
if isinstance(date_time, str):
if isinstance(date_time, six.string_types):
try:
return datetime.datetime.strptime(date_time, "%Y-%m-%d")
except ValueError:
try:
return datetime.datetime.strptime(date_time, "%Y-%m-%dT%H:%M:%SZ")
except ValueError:
return datetime.datetime.strptime(date_time, "%Y-%m-%d %H:%M:%S")
raise ValueError("Bad datetime value")
raise TypeError("Bad datetime type")
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# --------------------------------------------------------------------------

import datetime
import pytest
from azure.ai.metricsadvisor._helpers import convert_datetime


Expand All @@ -25,3 +26,7 @@ def test_convert_datetime():
input = datetime.datetime(2000, 1, 1)
date_time = convert_datetime(input)
assert date_time == datetime.datetime(2000, 1, 1)

with pytest.raises(TypeError):
input = tuple("2000-01-01 00:00:00", "2000-01-01 00:00:00")
convert_datetime(input)

0 comments on commit 0f86fee

Please sign in to comment.