Use pendulum for datetime operations when possible
Currently, we use both Python's built-in datetime library and Pendulum to do datetime operations. For the sake of consistency, we should try to stick to one library for datetimes. We could have used either, but Pendulum has a more ergonomic API, so I decided to go with it when possible. The places where were we didn't / couldn't replace datetime are: - checking instances of datetimes. Pendulum's objects are subclasses of python native datetime objects, so it's still useful to import datetime in those cases of using is_instance() - WTForms date validators expect datetime style string formats -- Pendulum has its own format for formatting/ parsing strings. As such, our custom validator DateRange needs to use datetime.stptime() to account for this format.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import datetime
|
||||
import pytest
|
||||
import re
|
||||
import pendulum
|
||||
|
||||
from atst.domain.audit_log import AuditLog
|
||||
from atst.domain.invitations import (
|
||||
@@ -53,7 +53,7 @@ def test_accept_expired_invitation():
|
||||
portfolio = PortfolioFactory.create()
|
||||
role = PortfolioRoleFactory.create(portfolio=portfolio)
|
||||
increment = PortfolioInvitations.EXPIRATION_LIMIT_MINUTES + 1
|
||||
expiration_time = datetime.datetime.now() - datetime.timedelta(minutes=increment)
|
||||
expiration_time = pendulum.now(tz="utc").subtract(minutes=increment)
|
||||
invite = PortfolioInvitationFactory.create(
|
||||
expiration_time=expiration_time,
|
||||
status=InvitationStatus.PENDING,
|
||||
|
Reference in New Issue
Block a user