Skip to content

Commit 312b077

Browse files
authored
[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
1 parent c65e42f commit 312b077

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

apiserver/plane/utils/timezone_converter.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
# Python imports
12
import pytz
2-
from plane.db.models import Project
33
from datetime import datetime, time
44
from datetime import timedelta
55

6+
# Django imports
7+
from django.utils import timezone
8+
9+
# Module imports
10+
from plane.db.models import Project
11+
612

713
def user_timezone_converter(queryset, datetime_fields, user_timezone):
814
# Create a timezone object for the user's timezone
@@ -65,16 +71,27 @@ def convert_to_utc(
6571
if is_start_date:
6672
localized_datetime += timedelta(minutes=0, seconds=1)
6773

68-
# If it's start an end date are equal, add 23 hours, 59 minutes, and 59 seconds
69-
# to make it the end of the day
70-
if is_start_date_end_date_equal:
71-
localized_datetime += timedelta(hours=23, minutes=59, seconds=59)
74+
# Convert the localized datetime to UTC
75+
utc_datetime = localized_datetime.astimezone(pytz.utc)
76+
77+
current_datetime_in_project_tz = timezone.now().astimezone(local_tz)
78+
current_datetime_in_utc = current_datetime_in_project_tz.astimezone(pytz.utc)
79+
80+
if utc_datetime.date() == current_datetime_in_utc.date():
81+
return current_datetime_in_utc
82+
83+
return utc_datetime
84+
else:
85+
# If it's start an end date are equal, add 23 hours, 59 minutes, and 59 seconds
86+
# to make it the end of the day
87+
if is_start_date_end_date_equal:
88+
localized_datetime += timedelta(hours=23, minutes=59, seconds=59)
7289

73-
# Convert the localized datetime to UTC
74-
utc_datetime = localized_datetime.astimezone(pytz.utc)
90+
# Convert the localized datetime to UTC
91+
utc_datetime = localized_datetime.astimezone(pytz.utc)
7592

76-
# Return the UTC datetime for storage
77-
return utc_datetime
93+
# Return the UTC datetime for storage
94+
return utc_datetime
7895

7996

8097
def convert_utc_to_project_timezone(utc_datetime, project_id):

0 commit comments

Comments
 (0)