Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support times with more than 24 hours #5

Merged
merged 2 commits into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pyexcel_ods3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def time_value(value):
hour = int(value[2:4])
minute = int(value[5:7])
second = int(value[8:10])
ret = datetime.time(hour, minute, second)
if hour < 24:
ret = datetime.time(hour, minute, second)
else:
ret = datetime.timedelta(hours=hour, minutes=minute, seconds=second)
return ret


Expand Down Expand Up @@ -85,6 +88,7 @@ def boolean_value(value):
str: "string",
datetime.date: "date",
datetime.time: "time",
datetime.timedelta: "timedelta",
bool: "boolean"
}

Expand Down Expand Up @@ -178,6 +182,12 @@ def write_row(self, array):
value_type = ODS_WRITE_FORMAT_COVERSION[type(cell)]
if value_type == "time":
cell = cell.strftime("PT%HH%MM%SS")
elif value_type == "timedelta":
hours = cell.days * 24 + cell.seconds // 3600
minutes = (cell.seconds // 60) % 60
seconds = cell.seconds % 60
cell = "PT%02dH%02dM%02dS" % (hours, minutes, seconds)
value_type = "time"
self.native_sheet[self.current_row, count].set_value(
cell,
value_type=value_type)
Expand Down
3 changes: 3 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pyexcel
import datetime
import os
from nose.tools import raises

Expand Down Expand Up @@ -123,6 +124,8 @@ def test_formats(self):
assert self.data["Sheet1"][1][1].strftime(time_format) == "12:12:11"
assert self.data["Sheet1"][2][1].strftime(time_format) == "12:00:00"
assert self.data["Sheet1"][3][1] == 0
assert self.data["Sheet1"][4][1] == datetime.timedelta(hours=27, minutes=17, seconds=54)
assert self.data["Sheet1"][5][1] == "Other"
# boolean
assert self.data["Sheet1"][0][2] == "Boolean"
assert self.data["Sheet1"][1][2] is True
Expand Down
Binary file modified tests/fixtures/ods_formats.ods
Binary file not shown.