Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-3177] fix: resolve cycle creation issue for equal start_date and completed_date #6504

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

gurusainath
Copy link
Collaborator

@gurusainath gurusainath commented Jan 29, 2025

Description

  • Fixed an issue where cycles could not be created if start_date and completed_date were equal.
  • Ensured proper handling of cycles with the same start and completed dates.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

References

[WEB-3177]

Summary by CodeRabbit

  • Bug Fixes
    • Improved timezone conversion logic to handle date discrepancies more accurately.
    • Enhanced UTC datetime conversion for more precise time tracking.
    • Streamlined function structure for better coherence in date handling.

Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

The pull request modifies the convert_to_utc function in the timezone converter utility. The changes introduce enhanced logic for converting localized datetime to UTC, with a new approach to handling date conversions. The function now checks if the converted datetime's date matches the current date in the project's timezone. If they differ, it returns the current UTC datetime instead of the converted one. The implementation also reorganizes the handling of the is_start_date_end_date_equal flag while incorporating Django's timezone utilities.

Changes

File Change Summary
apiserver/plane/utils/timezone_converter.py - Updated convert_to_utc function logic
- Added date comparison for UTC conversion
- Reorganized handling of is_start_date_end_date_equal flag
- Imported additional Django timezone utilities

Possibly related PRs

Suggested labels

🐛bug

Suggested reviewers

  • NarayanBavisetti
  • pushya22

Poem

🕰️ In the realm of time's embrace,
A rabbit hops through timezone's grace
Converting dates with careful might
UTC now shines so clear and bright
Precision dancing, code's delight! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e61dd72 and e9b78e3.

📒 Files selected for processing (1)
  • apiserver/plane/utils/timezone_converter.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-apiserver
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
apiserver/plane/utils/timezone_converter.py (2)

6-7: LGTM: Django timezone import added appropriately.

The addition of Django's timezone utility is well-suited for handling timezone-aware datetime operations in a Django project.


84-94: 🛠️ Refactor suggestion

Refactor: Simplify the logic structure.

The else block contains the correct logic for handling equal start/end dates, but it's unnecessarily separated and could be unreachable due to the previous date comparison.

Simplify the entire function's structure:

def convert_to_utc(
    date, project_id, is_start_date=False, is_start_date_end_date_equal=False
):
    # [Previous setup code remains unchanged until localized_datetime creation]

    # If it's a start date, add one minute
    if is_start_date:
        localized_datetime += timedelta(minutes=0, seconds=1)

-    # 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 start and end dates are equal, add 23:59:59 to make it end of day
    if is_start_date_end_date_equal:
        localized_datetime += timedelta(hours=23, minutes=59, seconds=59)

    # Convert the localized datetime to UTC and return
    return localized_datetime.astimezone(pytz.utc)

This simplified structure:

  1. Maintains the original functionality for equal start/end dates
  2. Removes unnecessary date comparisons
  3. Makes the code more maintainable and easier to understand

Likely invalid or redundant comment.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
apiserver/plane/utils/timezone_converter.py (2)

85-87: Fix typo in comment.

The comment has grammatical errors.

-        # If it's start an end date are equal, add 23 hours, 59 minutes, and 59 seconds
+        # If start and end dates are equal, add 23 hours, 59 minutes, and 59 seconds

Line range hint 1-94: Consider adding timezone handling tests.

Given the complexity of timezone conversions and the various edge cases, it would be beneficial to add comprehensive tests covering:

  1. Equal start/end dates across different timezones
  2. Date boundary cases (e.g., midnight conversions)
  3. Future and past dates
  4. DST transition periods

Would you like me to help create a test suite covering these scenarios?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4af78c and e61dd72.

📒 Files selected for processing (1)
  • apiserver/plane/utils/timezone_converter.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint-apiserver
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (1)
apiserver/plane/utils/timezone_converter.py (1)

6-7: LGTM! Django timezone utilities import is properly organized.

The addition of Django's timezone utilities is well-placed and necessary for the new timezone-aware datetime comparisons.

apiserver/plane/utils/timezone_converter.py Outdated Show resolved Hide resolved
apiserver/plane/utils/timezone_converter.py Outdated Show resolved Hide resolved
@sriramveeraghanta sriramveeraghanta merged commit 312b077 into preview Jan 29, 2025
12 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-cycle-date-check branch January 29, 2025 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants