|
| 1 | +# Python imports |
1 | 2 | import pytz |
2 | | -from plane.db.models import Project |
3 | 3 | from datetime import datetime, time |
4 | 4 | from datetime import timedelta |
5 | 5 |
|
| 6 | +# Django imports |
| 7 | +from django.utils import timezone |
| 8 | + |
| 9 | +# Module imports |
| 10 | +from plane.db.models import Project |
| 11 | + |
6 | 12 |
|
7 | 13 | def user_timezone_converter(queryset, datetime_fields, user_timezone): |
8 | 14 | # Create a timezone object for the user's timezone |
@@ -65,16 +71,27 @@ def convert_to_utc( |
65 | 71 | if is_start_date: |
66 | 72 | localized_datetime += timedelta(minutes=0, seconds=1) |
67 | 73 |
|
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) |
72 | 89 |
|
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) |
75 | 92 |
|
76 | | - # Return the UTC datetime for storage |
77 | | - return utc_datetime |
| 93 | + # Return the UTC datetime for storage |
| 94 | + return utc_datetime |
78 | 95 |
|
79 | 96 |
|
80 | 97 | def convert_utc_to_project_timezone(utc_datetime, project_id): |
|
0 commit comments