Skip to content

Commit

Permalink
feat: add timezone handling for member activity dates
Browse files Browse the repository at this point in the history
  • Loading branch information
amindadgar committed Jan 20, 2025
1 parent 2726bf0 commit 4ccd1ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 3 additions & 6 deletions tc_analyzer_lib/algorithms/member_activity_history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# checking the past history of member activities

from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

from tc_analyzer_lib.algorithms.utils.member_activity_history_utils import (
MemberActivityPastUtils,
Expand Down Expand Up @@ -106,11 +106,8 @@ def check_past_history(
# db_analysis_start_date = None
db_analysis_end_date = None

# # the input date_range in format of datetime
# # converting the dates into datetime format
# date_format = "%y/%m/%d"
# date_range_start = datetime.datetime.strptime(date_range[0], date_format)
# date_range_end = datetime.datetime.strptime(date_range[1], date_format)
if db_analysis_end_date:
db_analysis_end_date = db_analysis_end_date.replace(tzinfo=timezone.utc)

new_date_range: list[datetime]
# if for the requested date_range, its results were available in db
Expand Down
3 changes: 3 additions & 0 deletions tc_analyzer_lib/metrics/analyzer_memberactivities.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def analysis_member_activity(
if not from_start:
# first date of storing the data
first_storing_date = member_activity_c.get_last_date()
if first_storing_date:
first_storing_date = first_storing_date.replace(tzinfo=timezone.utc)

activities = self.utils.refine_memberactivities_data(
activities, first_storing_date
)
Expand Down
3 changes: 2 additions & 1 deletion tc_analyzer_lib/models/MemberActivityModel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import logging
from datetime import datetime

import pymongo
from tc_analyzer_lib.models.BaseModel import BaseModel
Expand All @@ -12,7 +13,7 @@ def __init__(self, database=None):
raise Exception("Database should not be None")
super().__init__(collection_name="memberactivities", database=database)

def get_last_date(self):
def get_last_date(self) -> datetime | None:
"""
Gets the date of the last document
"""
Expand Down

0 comments on commit 4ccd1ff

Please sign in to comment.