From 312b07765747197e3cbcfa06666dc855454a4c3e Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Wed, 29 Jan 2025 16:35:25 +0530 Subject: [PATCH] [WEB-3177] fix: resolve cycle creation issue for equal start_date and completed_date (#6504) * fix: fixed cycle startdate if the the start_date and completed cyles dates are today * chore: updated validation for date match --- 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 3e14d0bf6..3740e8c97 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) - # 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) - # Return the UTC datetime for storage - return utc_datetime + 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) + + # Return the UTC datetime for storage + return utc_datetime def convert_utc_to_project_timezone(utc_datetime, project_id):