Permalink
Browse files

Added ability to handle non-integer time zones

  • Loading branch information...
1 parent 21d4d70 commit 225597e9b2299d6e2f1c40ec71ccc9bee752e3a8 @guyrt guyrt committed Apr 4, 2012
Showing with 10 additions and 5 deletions.
  1. +5 −4 ofxparse/ofxparse.py
  2. +5 −1 tests/test_parse.py
@@ -206,11 +206,12 @@ def parse(cls_, file_handle, fail_fast=True):
@classmethod
def parseOfxDateTime(cls_, ofxDateTime):
- #dateAsString looks something like 20101106160000.00[-5:EST]
- #for 6 Nov 2010 4pm UTC-5 aka EST
- res = re.search("\[(?P<tz>-?\d+)\:\w*\]$", ofxDateTime)
+ # dateAsString looks something like 20101106160000.00[-5:EST]
+ # for 6 Nov 2010 4pm UTC-5 aka EST
+ # Some places (e.g. Newfoundland) have non-integer offsets.
+ res = re.search("\[(?P<tz>-?\d+\.?\d*)\:\w*\]$", ofxDateTime)
if res:
- tz = int(res.group('tz'))
+ tz = float(res.group('tz'))
else:
tz = 0
View
@@ -144,7 +144,11 @@ def test_parses_time_offset(self):
self.assertEquals( OfxParser.parseOfxDateTime('19881201230100 [-5:EST]'),
datetime(1988, 12, 2, 4, 1) )
self.assertEquals( OfxParser.parseOfxDateTime('20120229230100 [-6:CAT]'),
- datetime(2012, 3, 1, 5, 1) )
+ datetime(2012, 3, 1, 5, 1) )
+ self.assertEquals( OfxParser.parseOfxDateTime('20120412120000 [-5.5:XXX]'),
+ datetime(2012, 04, 12, 17, 30))
+ self.assertEquals( OfxParser.parseOfxDateTime('20120412120000 [-5:XXX]'),
+ datetime(2012, 04, 12, 17))
class TestParseStmtrs(TestCase):
input = '''

0 comments on commit 225597e

Please sign in to comment.