[62132] Fix issue when converting offset-aware datetime objects to timestamp#154
Conversation
|
This pull request has been linked to Clubhouse Story #62132: [GitHub Issue #143] Cannot use timezone aware datetimes in messages API. |
`datetime.timezone` does not exist on Python < 3.3 so we have to use `pytz` to provide us a timezone example
datetime objects to timestampdatetime objects to timestamp
| # return delta.total_seconds() | ||
|
|
||
| return delta.seconds + delta.days * 86400 | ||
|
|
There was a problem hiding this comment.
maybe a good idea to use timedelta from the datetime package for adding or subtracting time values from datetime.
Also, datetime has a timestamp() method, so that could be just: return dt.timestamp()
There was a problem hiding this comment.
Thanks for pointing my attention to timedelta it helps clean the code a bit! Regarding datetime.timestamp() I initially used that as the solution, but unfortunately it's only available from Python 3.3 and up, and we still support Python 2.7 I believe so I had to scrap that idea.
There was a problem hiding this comment.
ok, this is good for py2, that timestamp() is in py3. datetime in python isn't the best package
There was a problem hiding this comment.
So I've heard :/
…t-use-timezone-aware
New `nylas` v5.0.0 release bringing in the following additions: * Add support for the Nylas Neural API (#163) * Add `metadata` support (#152) * Add new Room Resource fields (#156) * Add `Nylas-API-Version` header support (#157, #151) as well as the following changes: * Transitioned from `app_id` and `app_secret` naming to `client_id` and `client_secret` (#159, #86) * Fix adding a tracking object to an existing `draft` (#153) * Fix issue when converting offset-aware `datetime` objects to `timestamp` (#154, #143) * Fix `limit` value in filter not being used when making `.all()` call (#155) * Fix `from_` field set by attribute on draft ignored (#162, #160) * Remove `bumpversion` from a required dependency to an extra dependency (#158, #144)
Description
Wherever we accept a date as a filtering parameter, we usually convert it from a
datetimeobject to atimestampobject. However the way we convert it does not take into consideration if thedatetimeis offset-aware or not (timezone), and thus would throw an error when it's attempted. Now we check if thedatetimeis context-aware, and if it is, we convert it properly to being an offset-naive object before converting it to a timestamp.License
I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.