From e61dd72ac88484da0b38137e93c134eca1b57cfa Mon Sep 17 00:00:00 2001 From: gurusinath Date: Wed, 29 Jan 2025 15:35:48 +0530 Subject: [PATCH 1/2] fix: fixed cycle startdate if the the start_date and completed cyles dates are today --- apiserver/plane/utils/timezone_converter.py | 35 +++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/apiserver/plane/utils/timezone_converter.py b/apiserver/plane/utils/timezone_converter.py index 3e14d0bf60b..48fb81ca93d 100644 --- a/apiserver/plane/utils/timezone_converter.py +++ b/apiserver/plane/utils/timezone_converter.py @@ -1,8 +1,14 @@ +# Python imports import pytz -from plane.db.models import Project from datetime import datetime, time from datetime import timedelta +# Django imports +from django.utils import timezone + +# Module imports +from plane.db.models import Project + def user_timezone_converter(queryset, datetime_fields, user_timezone): # Create a timezone object for the user's timezone @@ -65,16 +71,27 @@ def convert_to_utc( if is_start_date: localized_datetime += timedelta(minutes=0, seconds=1) - # If it's start an end date are equal, add 23 hours, 59 minutes, and 59 seconds - # to make it the end of the day - if is_start_date_end_date_equal: - localized_datetime += timedelta(hours=23, minutes=59, seconds=59) + # Convert the localized datetime to UTC + utc_datetime = localized_datetime.astimezone(pytz.utc) + + current_datetime_in_project_tz = timezone.now().astimezone(local_tz) + current_datetime_in_utc = current_datetime_in_project_tz.astimezone(pytz.utc) + + if utc_datetime.date() != current_datetime_in_utc.date(): + return current_datetime_in_utc + + return utc_datetime + else: + # If it's start an end date are equal, add 23 hours, 59 minutes, and 59 seconds + # to make it the end of the day + if is_start_date_end_date_equal: + localized_datetime += timedelta(hours=23, minutes=59, seconds=59) - # Convert the localized datetime to UTC - utc_datetime = localized_datetime.astimezone(pytz.utc) + # Convert the localized datetime to UTC + utc_datetime = localized_datetime.astimezone(pytz.utc) - # Return the UTC datetime for storage - return utc_datetime + # Return the UTC datetime for storage + return utc_datetime def convert_utc_to_project_timezone(utc_datetime, project_id): From e9b78e3de5f1d4e1cd93ea949c179917bd898782 Mon Sep 17 00:00:00 2001 From: gurusinath Date: Wed, 29 Jan 2025 16:12:01 +0530 Subject: [PATCH 2/2] chore: updated validation for date match --- apiserver/plane/utils/timezone_converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apiserver/plane/utils/timezone_converter.py b/apiserver/plane/utils/timezone_converter.py index 48fb81ca93d..3740e8c971b 100644 --- a/apiserver/plane/utils/timezone_converter.py +++ b/apiserver/plane/utils/timezone_converter.py @@ -77,7 +77,7 @@ def convert_to_utc( current_datetime_in_project_tz = timezone.now().astimezone(local_tz) current_datetime_in_utc = current_datetime_in_project_tz.astimezone(pytz.utc) - if utc_datetime.date() != current_datetime_in_utc.date(): + if utc_datetime.date() == current_datetime_in_utc.date(): return current_datetime_in_utc return utc_datetime