Skip to content

Commit

Permalink
Merge pull request #33 from thombashi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
thombashi authored Jul 4, 2016
2 parents 8b287b2 + 3d5c9fb commit 5234cbc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
24 changes: 23 additions & 1 deletion dataproperty/converter/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from __future__ import absolute_import
import abc
import re

from .._error import TypeConversionError

Expand Down Expand Up @@ -82,6 +83,8 @@ class DateTimeConverter(ValueConverter):
7200: "Africa/Tripoli", # 0200
}

__RE_VERSION_STR = re.compile("\d+\.\d+\.\d")

def __init__(self, value):
super(DateTimeConverter, self).__init__(value)

Expand All @@ -96,10 +99,13 @@ def convert(self):
self.__datetime = self._value
return self.__datetime

self.__validate_datetime_string()

try:
self.__datetime = dateutil.parser.parse(self._value)
except (AttributeError, ValueError, OverflowError):
raise TypeConversionError
raise TypeConversionError(
"failed to parse as datetime: " + str(self._value))

try:
dst_timezone_name = self.__get_dst_timezone_name(
Expand Down Expand Up @@ -127,3 +133,19 @@ def __get_timedelta_sec(self):

def __get_dst_timezone_name(self, offset):
return self.__COMMON_DST_TIMEZONE_TABLE[offset]

def __validate_datetime_string(self):
"""
This validation is required for version string (such as "3.3.5").
A version string is converted to a datetime value if this
validation is not executed.
"""

try:
if self.__RE_VERSION_STR.search(self._value) is not None:
raise TypeConversionError(
"invalid datetime string: version string found " +
self._value)
except TypeError:
raise TypeConversionError(
"invalid datetime string: " + str(self._value))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

setuptools.setup(
name=project_name,
version="0.5.3",
version="0.5.4",
url="https://github.com/thombashi/" + project_name,
bugtrack_url="https://github.com/thombashi/%s/issues" % (project_name),

Expand Down
3 changes: 3 additions & 0 deletions test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class Test_DataPeroperty_data_typecode:
["a", True, "a", Typecode.STRING],
["a", False, "a", Typecode.STRING],
["3.3.5", True, "3.3.5", Typecode.STRING],
["51.0.2704.106", True, "51.0.2704.106", Typecode.STRING],
[True, True, True, Typecode.BOOL],
[False, False, False, Typecode.BOOL],
Expand Down

0 comments on commit 5234cbc

Please sign in to comment.