Use datetime.now().date() instead of today().
build_latest / build (push) Successful in 1m53s
build_release / build (push) Successful in 17s

This commit is contained in:
2024-05-22 16:23:53 -04:00
parent ed06748984
commit 1fd1be5576
4 changed files with 16 additions and 17 deletions
+7 -7
View File
@@ -1,9 +1,9 @@
"""File contains util functions."""
import calendar
import datetime
import os
from collections.abc import Sequence
from datetime import UTC, datetime
from enum import StrEnum
from pathlib import Path
@@ -30,7 +30,7 @@ TEMPLATES_DIR = f"{REPO_DIR}/message_templates"
VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"])
def get_datetime(day: str) -> datetime.datetime:
def get_datetime(day: str) -> datetime:
"""
Takes in a string month and day and returns a datetime object of that Month/Day this year.
@@ -40,7 +40,7 @@ def get_datetime(day: str) -> datetime.datetime:
Returns:
datetime: Datetime representation of Month/Day.
"""
today = datetime.datetime.now(tz=datetime.UTC).date()
today = datetime.now(tz=UTC).date()
year = today.year
month = int(day.split("/")[0])
day = int(day.split("/")[1])
@@ -52,7 +52,7 @@ def get_datetime(day: str) -> datetime.datetime:
if today.month == calendar.JANUARY and month > calendar.JANUARY:
year -= 1
return datetime.datetime(year, month, day, tzinfo=datetime.UTC)
return datetime(year, month, day, tzinfo=UTC)
def get_election_name(config: DakinyConfig) -> str:
@@ -96,7 +96,7 @@ def get_current_election_cycle(config: DakinyConfig) -> int:
Returns:
int: cycle index for active election. None for no active cycle
"""
today = datetime.datetime.now(tz=datetime.UTC).date()
today = datetime.now(tz=UTC).date()
for cycle, election in enumerate(config.election_cycles):
if (
@@ -119,7 +119,7 @@ def get_quarter_cycle(config: DakinyConfig) -> int:
Returns:
int: cycle index for current cycle.
"""
today = datetime.datetime.now(tz=datetime.UTC).date()
today = datetime.now(tz=UTC).date()
for cycle, election in enumerate(config.election_cycles):
if (
today.date() >= get_datetime(election.term_start).date()
@@ -357,7 +357,7 @@ def get_allowed_points(session: Session, points_limit: int, user: str, points: i
int: how many points are allowed to be given to the user.
"""
# check for limit
today = datetime.datetime.now(tz=datetime.UTC).date()
today = datetime.now(tz=UTC).date()
this_week = f"{today.isocalendar().year}-{today.isocalendar().week}"
stmt = select(EventPointsLimit).where(EventPointsLimit.UserId == user).where(EventPointsLimit.Week == this_week)