Skip to content

Commit

Permalink
everything is using datetime now naive
Browse files Browse the repository at this point in the history
  • Loading branch information
Lescurel authored and emanuelen5 committed Dec 29, 2024
1 parent 8e82e73 commit 05d2935
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 23 deletions.
13 changes: 9 additions & 4 deletions api/src/firstrun.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import argparse
import random
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from getpass import getpass
from typing import Any, Dict, Generic, Literal, Optional, Tuple, TypeVar, cast

Expand Down Expand Up @@ -452,7 +452,12 @@ def create_shop_transactions() -> None:
transaction = get_or_create(
Transaction,
id=index,
defaults=dict(member_id=1, amount=membership_prod.price, status="completed", created_at=datetime.now()),
defaults=dict(
member_id=1,
amount=membership_prod.price,
status="completed",
created_at=datetime.now(timezone.utc).replace(tzinfo=None),
),
)
transaction_content = get_or_create(
TransactionContent,
Expand All @@ -472,7 +477,7 @@ def create_shop_transactions() -> None:
action_type="add_labaccess_days",
value=10,
status="completed",
completed_at=datetime.now(),
completed_at=datetime.now(timezone.utc).replace(tzinfo=None),
),
)
index += 1
Expand All @@ -485,7 +490,7 @@ def create_shop_transactions() -> None:
member_id=None,
amount=100,
status="completed",
created_at=datetime.now(),
created_at=datetime.now(timezone.utc).replace(tzinfo=None),
),
)

Expand Down
6 changes: 3 additions & 3 deletions api/src/member/member.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
from pathlib import Path
from typing import Any, List
from urllib.parse import quote_plus
Expand Down Expand Up @@ -30,7 +30,7 @@ def send_access_token_email(redirect, user_identification, ip, browser):
MessageTemplate.LOGIN_LINK,
member,
url=url,
now=format_datetime(datetime.now()),
now=format_datetime(datetime.now(timezone.utc).replace(tzinfo=None)),
)

return {"status": "sent"}
Expand All @@ -47,7 +47,7 @@ def send_updated_member_info_email(member_id: int, msg_swe: str, msg_en: str):
send_message(
MessageTemplate.UPDATED_MEMBER_INFO,
member,
now=format_datetime(datetime.now()),
now=format_datetime(datetime.now(timezone.utc).replace(tzinfo=None)),
message_swe=msg_swe,
message_en=msg_en,
)
Expand Down
6 changes: 3 additions & 3 deletions api/src/multiaccessy/accessy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from collections.abc import Iterable
from dataclasses import dataclass, field
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, timezone
from enum import Enum
from logging import getLogger
from random import random
Expand Down Expand Up @@ -361,9 +361,9 @@ def __ensure_token(self) -> None:
if (
not self.session_token
or self.session_token_token_expires_at is None
or datetime.now() > self.session_token_token_expires_at
or datetime.now(timezone.utc).replace(tzinfo=None) > self.session_token_token_expires_at
):
now = datetime.now()
now = datetime.now(timezone.utc).replace(tzinfo=None)
data = request(
"post",
"/auth/oauth/token",
Expand Down
4 changes: 2 additions & 2 deletions api/src/shop/accounting/sie_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
from decimal import Decimal
from logging import getLogger
from typing import Dict, List, Tuple
Expand Down Expand Up @@ -35,7 +35,7 @@ def date_format(dt: datetime) -> str:

def get_header(signer: str, start_date: datetime, end_date: datetime) -> str:
return HEADER_TEMPLATE.format(
date=date_format(datetime.now()),
date=date_format(datetime.now(timezone.utc).replace(tzinfo=None)),
signer=signer,
date_start=date_format(start_date),
date_end=date_format(end_date),
Expand Down
2 changes: 1 addition & 1 deletion api/src/shop/accounting/test/export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_export_accounting(self, get_payments_from_stripe: Mock) -> None:
row = sie_rows.pop(0)

if row.startswith("#GEN"):
assert datetime.now().strftime("%Y%m%d") in row
assert datetime.now(timezone.utc).replace(tzinfo=None).strftime("%Y%m%d") in row
assert self.member.firstname in row
assert self.member.lastname in row

Expand Down
2 changes: 1 addition & 1 deletion api/src/shop/accounting/test/sie_file_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_get_sie_string(self) -> None:
row = sie_rows.pop(0)

if row.startswith("#GEN"):
assert datetime.now().strftime("%Y%m%d") in row
assert datetime.now(timezone.utc).replace(tzinfo=None).strftime("%Y%m%d") in row
assert signer in row

if row.startswith("#DIM"):
Expand Down
8 changes: 4 additions & 4 deletions api/src/statistics/maker_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import math
import time
from dataclasses import dataclass
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, timezone
from typing import Any, Dict, List, Optional, Tuple

from membership.membership import get_members_and_membership, get_membership_summaries
Expand Down Expand Up @@ -138,7 +138,7 @@ def membership_number_months2(membership_type: str, startdate: date, enddate: da


def membership_number_months_default():
now = datetime.now()
now = datetime.now(timezone.utc).replace(tzinfo=None)
starttime = now - timedelta(days=30 * 12)
return {
"membership": membership_number_months("membership", starttime.date(), now.date()),
Expand All @@ -147,7 +147,7 @@ def membership_number_months_default():


def membership_number_months2_default():
now = datetime.now()
now = datetime.now(timezone.utc).replace(tzinfo=None)
starttime = now - timedelta(days=30 * 12)
return {
"membership": membership_number_months2("membership", starttime.date(), now.date()),
Expand Down Expand Up @@ -212,7 +212,7 @@ def shop_statistics() -> ShopStatistics:
def mapify(rows: List[Tuple[Any, Any]]) -> Dict[Any, Any]:
return {r[0]: r[1] for r in rows}

date_lower_limit = datetime.now() - timedelta(days=365)
date_lower_limit = datetime.now(timezone.utc).replace(tzinfo=None) - timedelta(days=365)

sales_by_product: Dict[int, float] = mapify(
db_session.query(TransactionContent.product_id, func.sum(TransactionContent.amount))
Expand Down
4 changes: 2 additions & 2 deletions api/src/test_aid/obj.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from datetime import datetime
from datetime import datetime, timezone
from decimal import Decimal
from logging import getLogger
from random import choice, randint, seed
Expand Down Expand Up @@ -81,7 +81,7 @@ def create_phone_request(self, **kwargs):
phone=random_phone_number(),
validation_code=randint(1, 999999),
completed=False,
timestamp=datetime.now(),
timestamp=datetime.now(timezone.utc).replace(tzinfo=None),
)
obj.update(kwargs)
self.phone_request = obj
Expand Down
6 changes: 3 additions & 3 deletions devel_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import json
import random
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from pprint import pprint

import requests
Expand Down Expand Up @@ -80,8 +80,8 @@ def create_span(member_id, startdate, enddate, span_type, creation_reason=None):
member = create_user("test user", "blah", f"test_user_{random.randrange(0, 100000)}", "user", None)

delete_all_spans(member["member_id"])
startTime = datetime.now() + timedelta(days=random.randrange(-300, 0))
endTime = datetime.now() + timedelta(days=random.randrange(-300, 100))
startTime = datetime.now(timezone.utc).replace(tzinfo=None) + timedelta(days=random.randrange(-300, 0))
endTime = datetime.now(timezone.utc).replace(tzinfo=None) + timedelta(days=random.randrange(-300, 100))
startTime = startTime.strftime("%Y-%m-%d")
endTime = endTime.strftime("%Y-%m-%d")
create_span(member["member_id"], startTime, endTime, "membership", str(random.randrange(0, 100000)))
Expand Down

0 comments on commit 05d2935

Please sign in to comment.