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:
@@ -9,7 +9,7 @@ from sqlalchemy import (
|
||||
String,
|
||||
)
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import date
|
||||
import pendulum
|
||||
|
||||
from atst.models.base import Base
|
||||
import atst.models.mixins as mixins
|
||||
@@ -75,5 +75,5 @@ class CLIN(Base, mixins.TimestampsMixin):
|
||||
@property
|
||||
def is_active(self):
|
||||
return (
|
||||
self.start_date <= date.today() <= self.end_date
|
||||
self.start_date <= pendulum.today() <= self.end_date
|
||||
) and self.task_order.signed_at
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import datetime
|
||||
import pendulum
|
||||
from enum import Enum
|
||||
import secrets
|
||||
|
||||
@@ -90,7 +90,7 @@ class InvitesMixin(object):
|
||||
@property
|
||||
def is_expired(self):
|
||||
return (
|
||||
datetime.datetime.now(self.expiration_time.tzinfo) > self.expiration_time
|
||||
pendulum.now(tz=self.expiration_time.tzinfo) > self.expiration_time
|
||||
and not self.status == Status.ACCEPTED
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user