Skip to content

Commit ec79836

Browse files
committed
bug fix #6
1 parent 9318155 commit ec79836

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

pyexcel_ods3/__init__.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,26 @@ def float_value(value):
3030

3131

3232
def date_value(value):
33-
tokens = value.split('-')
34-
year = int(tokens[0])
35-
month = int(tokens[1])
36-
day = int(tokens[2])
37-
ret = datetime.date(year, month, day)
33+
ret = "invalid"
34+
try:
35+
# catch strptime exceptions only
36+
if len(value) == 10:
37+
ret = datetime.datetime.strptime(
38+
value,
39+
"%Y-%m-%d")
40+
ret = ret.date()
41+
elif len(value) == 19:
42+
ret = datetime.datetime.strptime(
43+
value,
44+
"%Y-%m-%dT%H:%M:%S")
45+
elif len(value) > 19:
46+
ret = datetime.datetime.strptime(
47+
value[0:26],
48+
"%Y-%m-%dT%H:%M:%S.%f")
49+
except:
50+
pass
51+
if ret == "invalid":
52+
raise Exception("Bad date value %s" % value)
3853
return ret
3954

4055

@@ -63,6 +78,17 @@ def boolean_value(value):
6378
}
6479

6580

81+
ODS_WRITE_FORMAT_COVERSION = {
82+
float: "float",
83+
int: "float",
84+
str: "string",
85+
datetime.date: "date",
86+
datetime.time: "time",
87+
datetime.timedelta: "timedelta",
88+
bool: "boolean"
89+
}
90+
91+
6692
VALUE_CONVERTERS = {
6793
"float": float_value,
6894
"date": date_value,
@@ -82,16 +108,6 @@ def boolean_value(value):
82108
"currency": "value"
83109
}
84110

85-
ODS_WRITE_FORMAT_COVERSION = {
86-
float: "float",
87-
int: "float",
88-
str: "string",
89-
datetime.date: "date",
90-
datetime.time: "time",
91-
datetime.timedelta: "timedelta",
92-
bool: "boolean"
93-
}
94-
95111

96112
if sys.version_info[0] < 3:
97113
ODS_WRITE_FORMAT_COVERSION[unicode] = "string"

test.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nosetests --with-cov --cov pyexcel_ods3 --cov tests --with-doctest --doctest-extension=.rst
1+
nosetests --with-cov --cov pyexcel_ods3 --cov tests --with-doctest --doctest-extension=.rst -I applymoban.py -I setup.py

0 commit comments

Comments
 (0)