File tree Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Expand file tree Collapse file tree 2 files changed +5
-8
lines changed Original file line number Diff line number Diff line change 16
16
17
17
DEFAULT_DATE_FORMAT = "DD/MM/YY"
18
18
DEFAULT_TIME_FORMAT = "HH:MM:SS"
19
+ DEFAULT_LONGTIME_FORMAT = "[HH]:MM:SS"
19
20
DEFAULT_DATETIME_FORMAT = "%s %s" % (DEFAULT_DATE_FORMAT , DEFAULT_TIME_FORMAT )
20
21
EMPTY_SHEET_NOT_ALLOWED = "xlwt does not support a book without any sheets"
21
22
@@ -53,13 +54,9 @@ def write_row(self, array):
53
54
style = XFStyle ()
54
55
style .num_format_str = DEFAULT_DATETIME_FORMAT
55
56
elif isinstance (value , datetime .timedelta ):
56
- hours = value .days * 24 + value .seconds // 3600
57
- minutes = (value .seconds // 60 ) % 60
58
- seconds = value .seconds % 60
59
- tmp_array = [hours , minutes , seconds ]
60
- value = xlrd .xldate .xldate_from_time_tuple (tmp_array )
57
+ value = value .days + value .seconds / 86_400
61
58
style = XFStyle ()
62
- style .num_format_str = DEFAULT_TIME_FORMAT
59
+ style .num_format_str = DEFAULT_LONGTIME_FORMAT
63
60
elif isinstance (value , datetime .date ):
64
61
tmp_array = [value .year , value .month , value .day ]
65
62
value = xlrd .xldate .xldate_from_date_tuple (tmp_array , 0 )
Original file line number Diff line number Diff line change @@ -56,8 +56,8 @@ def test_writing_date_format(self):
56
56
assert r [0 , 1 ].strftime ("%H:%M:%S" ) == "11:11:11"
57
57
assert isinstance (r [0 , 2 ], datetime .date ) is True
58
58
assert r [0 , 2 ].strftime ("%d/%m/%y %H:%M:%S" ) == "25/12/14 11:11:11"
59
- assert isinstance (r [0 , 2 ], datetime .timedelta )
60
- assert r [0 , 1 ].strftime ("%H:%M:%S" ) == "3:30:20 "
59
+ assert isinstance (r [0 , 3 ], datetime .datetime )
60
+ assert r [0 , 3 ].strftime ("%D-% H:%M:%S" ) == "03/04/00-08:05:56 "
61
61
os .unlink (excel_filename )
62
62
63
63
You can’t perform that action at this time.
0 commit comments