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-2843]chore: handled the cycle date time using project timezone #6187

Merged
merged 2 commits into from
Dec 12, 2024

Conversation

NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Dec 11, 2024

Description

Allow users to set a specific timezone for a project, ensuring that all cycle operations and calculations are performed according to the configured project timezone.

Type of Change

  • Improvement (change that would cause existing functionality to not work as expected)

References

Summary by CodeRabbit

  • New Features

    • Timezone handling for project-specific timezones has been added, improving date comparisons and displays.
    • Users can now select a timezone when updating project details in the Project Details Form.
  • Bug Fixes

    • Fixed a syntax error in the read-only fields list for the CycleUserPropertiesSerializer.
  • Chores

    • Updated import paths for the user_timezone_converter utility across multiple files, consolidating timezone conversion functionality.
  • Documentation

    • Added new functions for timezone conversions in the timezone_converter.py file, enhancing datetime handling capabilities.

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes in this pull request introduce enhancements to date handling across several components of the application. Key modifications include the addition of timezone conversion logic in the CycleWriteSerializer and CycleViewSet, ensuring that dates are consistently stored and compared in UTC format. Several import statements were updated to reflect a new utility for timezone conversion. Additionally, the user_timezone_converter function was refactored into a new file, consolidating timezone-related functionalities. Minor syntax corrections were also made in existing serializers.

Changes

File Path Change Summary
apiserver/plane/app/serializers/cycle.py - Updated CycleWriteSerializer to include UTC conversion for start_date and end_date.
- Fixed syntax error in CycleUserPropertiesSerializer's read_only_fields.
apiserver/plane/app/views/cycle/base.py - Added timezone handling in CycleViewSet methods (get_queryset, list, and post).
- Utilized convert_to_utc for cycle date checks in CycleDateCheckEndpoint.
apiserver/plane/app/views/issue/base.py - Updated import path for user_timezone_converter.
apiserver/plane/app/views/issue/sub_issue.py - Updated import path for user_timezone_converter.
apiserver/plane/app/views/module/archive.py - Updated import path for user_timezone_converter.
apiserver/plane/app/views/module/base.py - Updated import path for user_timezone_converter.
apiserver/plane/utils/timezone_converter.py - Introduced new functions: user_timezone_converter, convert_to_utc, and convert_utc_to_project_timezone for handling timezone conversions.
apiserver/plane/utils/user_timezone_converter.py - Removed the user_timezone_converter function as its functionality was refactored into timezone_converter.py.
web/core/components/project/form.tsx - Reintroduced CustomSearchSelect component and added timezone property in project update payload.
- Restored functionality for timezone selection UI and error handling.

Possibly related PRs

Suggested labels

⚙️backend, 🌟improvement

Suggested reviewers

  • sriramveeraghanta
  • pablohashescobar

🐇 In the land of code, where time does play,
A rabbit hops forth, to brighten the day.
With dates now in UTC, and timezones aligned,
Our cycles are managed, with logic refined.
So let’s celebrate changes, both big and small,
For in this new world, we’re conquering all! 🐇


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. (Experiment)
  • @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.

@NarayanBavisetti NarayanBavisetti marked this pull request as ready for review December 12, 2024 08:21
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: 4

🧹 Outside diff range and nitpick comments (7)
apiserver/plane/utils/timezone_converter.py (1)

6-6: Consider renaming 'queryset' parameter for clarity

The parameter queryset may be misleading since the function operates on dictionaries or lists of dictionaries, not Django QuerySets. Renaming it to data or items can improve readability.

apiserver/plane/app/views/cycle/base.py (5)

58-58: Remove unused import 'convert_utc_to_project_timezone'

The function convert_utc_to_project_timezone is imported but not used in this file. Removing the unused import cleans up the code:

 from plane.utils.timezone_converter import (
-    convert_utc_to_project_timezone,
     convert_to_utc,
     user_timezone_converter,
 )
🧰 Tools
🪛 Ruff (0.8.2)

58-58: plane.utils.timezone_converter.convert_utc_to_project_timezone imported but unused

Remove unused import: plane.utils.timezone_converter.convert_utc_to_project_timezone

(F401)


77-89: Refactor timezone conversion logic into a helper function

The code for fetching the project and converting the current time to the project's timezone is repeated. Extracting this logic into a helper function enhances reusability and maintainability:

🧰 Tools
🪛 Ruff (0.8.2)

87-87: Line too long (93 > 88)

(E501)


186-197: Duplicate code detected: Refactor timezone conversion logic

The timezone conversion logic is duplicated from the get_queryset method. Consider refactoring it into a shared helper function to avoid code redundancy.

🧰 Tools
🪛 Ruff (0.8.2)

195-195: Line too long (93 > 88)

(E501)


87-87: Line exceeds maximum recommended length

Line 87 exceeds 88 characters. Consider wrapping the line to improve readability:

 current_time_in_project_tz = timezone.now().astimezone(local_tz)
🧰 Tools
🪛 Ruff (0.8.2)

87-87: Line too long (93 > 88)

(E501)


195-195: Line exceeds maximum recommended length

Line 195 exceeds 88 characters. Consider wrapping the line to improve readability:

 current_time_in_project_tz = timezone.now().astimezone(local_tz)
🧰 Tools
🪛 Ruff (0.8.2)

195-195: Line too long (93 > 88)

(E501)

apiserver/plane/app/serializers/cycle.py (1)

Line range hint 75-75: Missing comma in 'read_only_fields'

There is a missing comma between "cycle" and "user" in read_only_fields. This will cause a syntax error or unintended behavior.

Apply this diff to fix the issue:

 class CycleUserPropertiesSerializer(BaseSerializer):
     class Meta:
         model = CycleUserProperties
         fields = "__all__"
-        read_only_fields = ["workspace", "project", "cycle" "user"]
+        read_only_fields = ["workspace", "project", "cycle", "user"]
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 38e8a5c and 4acdb64.

📒 Files selected for processing (9)
  • apiserver/plane/app/serializers/cycle.py (2 hunks)
  • apiserver/plane/app/views/cycle/base.py (10 hunks)
  • apiserver/plane/app/views/issue/base.py (1 hunks)
  • apiserver/plane/app/views/issue/sub_issue.py (1 hunks)
  • apiserver/plane/app/views/module/archive.py (1 hunks)
  • apiserver/plane/app/views/module/base.py (1 hunks)
  • apiserver/plane/utils/timezone_converter.py (1 hunks)
  • apiserver/plane/utils/user_timezone_converter.py (0 hunks)
  • web/core/components/project/form.tsx (6 hunks)
💤 Files with no reviewable changes (1)
  • apiserver/plane/utils/user_timezone_converter.py
✅ Files skipped from review due to trivial changes (4)
  • apiserver/plane/app/views/issue/base.py
  • apiserver/plane/app/views/issue/sub_issue.py
  • apiserver/plane/app/views/module/archive.py
  • apiserver/plane/app/views/module/base.py
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/app/views/cycle/base.py

58-58: plane.utils.timezone_converter.convert_utc_to_project_timezone imported but unused

Remove unused import: plane.utils.timezone_converter.convert_utc_to_project_timezone

(F401)


87-87: Line too long (93 > 88)

(E501)


195-195: Line too long (93 > 88)

(E501)

🔇 Additional comments (2)
web/core/components/project/form.tsx (2)

71-84: Timezone selection logic is correctly implemented

The timezone options and label rendering are properly handled, enhancing the user experience by allowing timezone selection.


Line range hint 389-413: Timezone field added to the project form successfully

The timezone field is correctly integrated into the project form with appropriate validation and rendering. Users can now select a timezone when updating project details.

apiserver/plane/utils/timezone_converter.py Show resolved Hide resolved
Comment on lines +62 to +63
if is_end_date:
localized_datetime -= timedelta(minutes=1)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Re-evaluate the logic for 'is_end_date' adjustment

Subtracting one minute from the start of the end date may lead to unexpected results, such as the end date being the previous day. Consider setting the time to the end of the day to accurately represent the end date:

# Instead of subtracting one minute
-localized_datetime -= timedelta(minutes=1)
+localized_datetime = localized_datetime.replace(hour=23, minute=59, second=59, microsecond=999999)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if is_end_date:
localized_datetime -= timedelta(minutes=1)
if is_end_date:
localized_datetime = localized_datetime.replace(hour=23, minute=59, second=59, microsecond=999999)

apiserver/plane/utils/timezone_converter.py Show resolved Hide resolved
apiserver/plane/app/views/cycle/base.py Show resolved Hide resolved
@sriramveeraghanta sriramveeraghanta merged commit 9ad8b43 into preview Dec 12, 2024
19 of 22 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix/cycle-datetime branch December 12, 2024 08:41
@pushya22 pushya22 changed the title chore: handled the cycle date time using project timezone [WEB-2843]chore: handled the cycle date time using project timezone Dec 12, 2024
nishantPFM pushed a commit to Pocket-Fm/plane that referenced this pull request Dec 12, 2024
…6187)

* chore: handled the cycle date time using project timezone

* chore: reverted the frontend commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants