Change datetime calls to include timezone

main
Bob Mottram 2023-11-21 11:15:44 +00:00
parent 02d80c73be
commit 2057c10715
3 changed files with 10 additions and 10 deletions

View File

@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
import os
from datetime import datetime
from utils import date_from_numbers
from utils import has_object_string
from utils import remove_domain_port
from utils import has_users_path
@ -183,8 +184,8 @@ def remove_old_hashtags(base_dir: str, max_months: int) -> str:
"""Remove old hashtags
"""
max_months = min(max_months, 11)
max_days_since_epoch = \
(date_utcnow() - datetime(1970, 1 + max_months, 1)).days
prev_date = date_from_numbers(1970, 1 + max_months, 1, 0, 0)
max_days_since_epoch = (date_utcnow() - prev_date).days
remove_hashtags = []
for _, _, files in os.walk(base_dir + '/tags'):

View File

@ -12,7 +12,7 @@ from uuid import UUID
from hashlib import md5
from datetime import datetime
from datetime import timedelta
from utils import date_from_numbers
from utils import date_from_string_format
from utils import acct_handle_dir
from utils import is_public_post
@ -1138,9 +1138,8 @@ def dav_report_response(base_dir: str, nickname: str, domain: str,
if query_start_day == query_end_day:
# calendar for one day
search_date = \
datetime(year=query_start_year,
month=query_start_month,
day=query_start_day)
date_from_numbers(query_start_year, query_start_month,
query_start_day, 0, 0)
ical_events = \
get_todays_events_icalendar(base_dir, nickname, domain,
search_date.year,

View File

@ -68,8 +68,8 @@ def date_utcnow():
return datetime.datetime.now(datetime.timezone.utc)
def _date_from_numbers(year: int, month: int, day: int,
hour: int, mins: int):
def date_from_numbers(year: int, month: int, day: int,
hour: int, mins: int):
"""returns an offset-aware datetime
"""
return datetime.datetime(year, month, day, hour, mins, 0,
@ -101,7 +101,7 @@ def date_from_string_format(date_str: str, formats: []):
def date_epoch():
"""returns an offset-aware version of epoch
"""
return _date_from_numbers(1970, 1, 1, 0, 0)
return date_from_numbers(1970, 1, 1, 0, 0)
def get_attributed_to(field) -> str:
@ -3276,7 +3276,7 @@ def week_day_of_month_start(month_number: int, year: int) -> int:
"""Gets the day number of the first day of the month
1=sun, 7=sat
"""
first_day_of_month = _date_from_numbers(year, month_number, 1, 0, 0)
first_day_of_month = date_from_numbers(year, month_number, 1, 0, 0)
return int(first_day_of_month.strftime("%w")) + 1