braintree / braintree_python

Braintree Python library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
242 stars 115 forks source link

datetime is not timezone aware #64

Closed tisdall closed 8 years ago

tisdall commented 8 years ago

The docs mention than search results and such are always in UTC, but the datetime.datetime objects being created with this library are not timezone aware. I can understand not wanting to add pytz just to accomplish this, so you could define your own UTC object (as shown in the datetime docs) that could be used in this case.

raymondberg commented 8 years ago

Thanks for the note, @tisdall. You are correct that timestamps from the Python library are currently returned as UTC values with no timestamp (default assumption being UTC). ​ We will consider adding timezone specificity to the datetime objects in a future library release, but at this point introducing such a change would break a lot of backwards compatability. ​ For others that may find this issue, here's the quickest pytz way to add timezone details to dates (assuming you know that the datetime is already naive UTC like in this library): ​

import pytz
​
transaction = braintree.Transaction.find("my_transaction_id")
created_at_utc = transaction.created_at.replace(tzinfo=pytz.utc)

​ ​ Happy Holidays!