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

Datetime conversion in python wrapper #15

Closed
ppetrid opened this issue Aug 15, 2014 · 1 comment
Closed

Datetime conversion in python wrapper #15

ppetrid opened this issue Aug 15, 2014 · 1 comment

Comments

@ppetrid
Copy link

ppetrid commented Aug 15, 2014

The current python implementation fails to convert the returned ISO-formatted timestamp to a datetime object if the characters representing seconds are less than 10.

For example, I have seen both
2014-08-15T15:39:55.461264+03:00 and
2014-08-15T15:39:55.5706103+03:00 returned by the REST API as TimeStamp in actual calls.
In the former case the parser fails since it tries to convert 55.461264+ to float.

The obvious solution is to replace
L83: time_tokens = timestamp[11:27].split(':') with
L83: time_tokens = timestamp[11:26].split(':') so that only the first 9 digits of seconds are parsed (or maybe even less).

However, I strongly recommend using a library such as dateutil to do this kind of work. It will add a dependency, but a pretty common one. Dateutil will also add timezone information, which is currently missing.

As a side note, I'd like to see other datetime objects returned by the REST API (such as InsDate returned by get_transaction) converted too, currently the wrapper only deals with TimeStamp.

If needed, I could create a pull request for this issue.

ppetrid pushed a commit to ppetrid/API that referenced this issue Aug 17, 2014
Added 'InsDate' & 'ClearanceDate` to the parsed datetimes, used the dateutil module for reliable conversion. Added minor PEP8 fixes (identation & line length)
@defilerc
Copy link

Hi @ppetrid ,

Thank you very much for your contribution.

Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants