Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/raistlin7447/csvkit into …
Browse files Browse the repository at this point in the history
…raistlin7447-master
  • Loading branch information
onyxfish committed Aug 22, 2013
2 parents 63d589b + f989aa4 commit 6e223a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion csvkit/convert/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def normalize_datetime(dt):
if ms < 1000:
return dt.replace(microsecond=0)
elif ms > 999000:
return dt.replace(second=dt.second + 1, microsecond=0)
return dt.replace(microsecond=0) + datetime.timedelta(seconds=1)

return dt

Expand Down
18 changes: 18 additions & 0 deletions tests/test_convert/test_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest

from csvkit.convert import xlsx
from datetime import datetime

class TestXLSX(unittest.TestCase):
def test_xlsx(self):
Expand All @@ -18,3 +19,20 @@ def test_xlsx_with_sheet(self):

with open('examples/sheetsxlsx_converted.csv', 'r') as f:
self.assertEquals(f.read(), output)

def test_normalize_datetime(self):
dt = datetime(2013, 8, 22, 9, 51, 59, 999001)
self.assertEqual(datetime(2013, 8, 22, 9, 52, 0), xlsx.normalize_datetime(dt))

dt = datetime(2013, 8, 22, 9, 51, 58, 999001)
self.assertEqual(datetime(2013, 8, 22, 9, 51, 59), xlsx.normalize_datetime(dt))

dt = datetime(2013, 8, 22, 9, 51, 59, 0)
self.assertEqual(dt, xlsx.normalize_datetime(dt))

dt = datetime(2013, 8, 22, 9, 51, 59, 999)
self.assertEqual(datetime(2013, 8, 22, 9, 51, 59, 0), xlsx.normalize_datetime(dt))

dt = datetime(2013, 8, 22, 9, 51, 59, 5000)
self.assertEqual(dt, xlsx.normalize_datetime(dt))

0 comments on commit 6e223a5

Please sign in to comment.