Skip to content

Commit

Permalink
Update to the newer syntax for getting utcnow() (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddd authored and dwinston committed Nov 26, 2024
1 parent 5369b1a commit 39e0444
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions demo/metadata_migration/notebooks/bookkeeper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional
from enum import Enum
from datetime import datetime
from datetime import datetime, timezone

from pymongo import MongoClient
from nmdc_schema.migrators.migrator_base import MigratorBase
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(
@staticmethod
def get_current_timestamp() -> str:
r"""Returns an ISO 8601 timestamp (string) representing the current time in UTC."""
utc_now = datetime.utcnow()
utc_now = datetime.now(timezone.utc)
iso_utc_now = utc_now.isoformat()
return iso_utc_now # e.g. "2024-02-21T04:31:03.115107"

Expand Down
6 changes: 3 additions & 3 deletions nmdc_runtime/api/core/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Optional, Dict

from fastapi import Depends
Expand Down Expand Up @@ -101,9 +101,9 @@ def get_password_hash(password):
def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
to_encode = data.copy()
if expires_delta:
expire = datetime.utcnow() + expires_delta
expire = datetime.now(timezone.utc) + expires_delta
else:
expire = datetime.utcnow() + timedelta(minutes=15)
expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
Expand Down

0 comments on commit 39e0444

Please sign in to comment.