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
+4 -5
View File
@@ -3,12 +3,9 @@ Contains the election cycle class
"""
import collections
from datetime import datetime, timedelta
from datetime import UTC, datetime, timedelta
import nextcord
from sqlalchemy import select, true, update
from sqlalchemy.orm import Session
from classes.nominate_highcouncil_views import NominateHighCouncilView
from classes.nominate_views import NominateView
from classes.voting_highcouncil_views import VoteHighcouncilView
@@ -20,6 +17,8 @@ from database_setup.sql_data_classes import (
Votes,
engine,
)
from sqlalchemy import select, true, update
from sqlalchemy.orm import Session
from utils import (
TEMPLATES_DIR,
VoteType,
@@ -143,7 +142,7 @@ class ElectionCycle:
"""
Function checks current date to see if something needs to be run.
"""
today = datetime.today()
today = datetime.now(tz=UTC).date()
# check all dates if action is needed
if today.date() == self.election_start.date():
+2 -2
View File
@@ -2,7 +2,7 @@
Contains commands and views for set commands.
"""
from datetime import datetime
from datetime import UTC, datetime
import nextcord
from nextcord.ext import commands
@@ -57,7 +57,7 @@ class setCog(commands.Cog, name="Set Commands"):
return
# check if valid day
today = datetime.today()
today = datetime.now(tz=UTC).date()
try:
birthday = datetime(today.year, month, day)
except ValueError:
+3 -3
View File
@@ -3,7 +3,7 @@ Defines the daily loop that runs the Dakiny bot functions.
"""
import random
from datetime import datetime, time
from datetime import UTC, datetime, time
import nextcord
from nextcord.ext import commands, tasks
@@ -92,7 +92,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
if random.randint(0, 99) == 0:
birthday_list.append(239547993106284544)
today = datetime.today()
today = datetime.now(tz=UTC).date()
birthday = f"{today.month}/{today.day}"
stmt = select(UserBirthday.UserId).where(UserBirthday.Birthday == birthday)
@@ -105,7 +105,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"):
Loops through the guild's humans checking for joined_at dates that match today's date. Sends a message
saying happy cakeday.
"""
today = datetime.today()
today = datetime.now(tz=UTC).date()
guild: nextcord.Guild = self.bot.get_guild(self.bot.config.params.guild_id)
announce_channel: nextcord.TextChannel = guild.get_channel(self.bot.config.params.general_channel_id)
+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)