rienafairefr / pynYNAB

a python client for the new YNAB
MIT License
138 stars 12 forks source link

Date format issue when date has timezone #28

Closed gehan closed 7 years ago

gehan commented 7 years ago

This line fails if the date has a time attached.

https://github.com/rienafairefr/nYNABapi/blob/master/pynYNAB/schema/Entity.py#L236

For instance:

column.name = "last_reconciled_date"
entityDict = {
    u'direct_connect_account_id': None,
    u'sortable_index': -1207959552,
    u'account_type': u'Checking',
    u'direct_connect_last_error_code': None,
    u'last_entered_check_number': u'-1',
    u'on_budget': True,
    u'direct_connect_institution_id': None,
    u'last_reconciled_balance': 140000,
    u'last_reconciled_date': u'2016-08-10T00:00:00',
    u'account_name': u'N&P',
    u'note': None,
    u'is_tombstone': False,
    u'direct_connect_last_imported_at': None,
    u'hidden': True,
    u'direct_connect_enabled': False,
    u'id': u'8c232866-1bfa-af57-e189-2c4f4ffa8dc6',
}

when running:

datetime.strptime(entityDict[column.name], '%Y-%m-%d').date()

this happens

ValueError: unconverted data remains: T00:00:00
gehan commented 7 years ago

I have no idea why it attaches a time even though YNAB doesn't deal with times. Presumably that part can be stripped off.

Anyway if I strip off the timezone then it works.

date_string = entityDict[column.name].split('T')[0]
datetime.strptime(date_string, '%Y-%m-%d').date()
rienafairefr commented 7 years ago

Thanks for the bug report. Out of curiosity, can you see if you have anything weird in the 'flags' or 'feature-fags' data somewhere in what is fetched from the api ? Look at sync_data object in the sync_obj method. You might be part of a group of people to which they are pushing a new feature gradually. f9fb65b29e8aeeccff0cc84c9c3c84e21b217033 was just pushed to address the date parsing from an API dictionary, if there is anything else that bugs out let me know