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:
graham-dds
2020-02-07 10:38:59 -05:00
parent 4afdc62329
commit 108f65f928
30 changed files with 108 additions and 126 deletions

View File

@@ -1,4 +1,4 @@
import datetime
import pendulum
import uuid
from unittest.mock import Mock, patch
@@ -613,7 +613,7 @@ def test_filter_environment_roles():
user = UserFactory.create()
# need to set the time created to yesterday, otherwise the original invite and resent
# invite have the same time_created and then we can't rely on time to order the invites
yesterday = datetime.date.today() - datetime.timedelta(days=1)
yesterday = pendulum.today().subtract(days=1)
invite = ApplicationInvitationFactory.create(
user=user, time_created=yesterday, email="original@example.com"
)