Skip to content

Pro issue 5418 / Use WordPress date and time settings for entry timestamp in edit/view entry sidebar#2118

Merged
Crabcyborg merged 3 commits into
masterfrom
pro_issue_5418
Nov 25, 2024
Merged

Pro issue 5418 / Use WordPress date and time settings for entry timestamp in edit/view entry sidebar#2118
Crabcyborg merged 3 commits into
masterfrom
pro_issue_5418

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Nov 19, 2024

Fixes https://github.com/Strategy11/formidable-pro/issues/5418

Now I'm using our more commonly used get_formatted_time function that adds the time data, and some custom logic for the date format (I change long month names to the short month name so if you have it set to show "November", it will show "Nov" instead to save space).

This generally uses the WordPress setting, and not our global setting in Pro, as the Pro settings are all formats like Y/m/d and Y-m-d, none of which look as good as the more verbose format options that you can use in the WordPress date setting.

The @ is now at by default, but I think that's okay. It makes it more consistent with our other dates with times which is more important than the possible space saved.

Using the following settings These are set at /wp-admin/options-general.php
Screen Shot 2024-11-19 at 12 36 36 PM

Before
Screen Shot 2024-11-19 at 12 35 45 PM

After
Screen Shot 2024-11-19 at 12 35 20 PM

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 19, 2024

Walkthrough

The changes involve modifications to the FrmAppHelper class and the frm-entries/_sidebar-shared-pub.php file. A new private method, add_time_to_date, has been introduced to enhance date formatting capabilities by allowing time to be appended to dates. The get_formatted_time method has been updated to utilize this new method and now accepts a time format parameter. In the sidebar view, the date formatting logic has been made dynamic by retrieving the date format from options instead of using a hardcoded string, improving flexibility in timestamp display.

Changes

File Path Change Summary
classes/helpers/FrmAppHelper.php - Added private method add_time_to_date($time_format, $date).
- Updated get_formatted_time($date, $date_format = '', $time_format = '') to use the new method for time formatting and added a docblock for add_time_to_date.
classes/views/frm-entries/_sidebar-shared-pub.php - Replaced hardcoded date format with dynamic retrieval using get_option('date_format').
- Changed date formatting method from FrmAppHelper::get_localized_date() to FrmAppHelper::get_formatted_time(). Minor formatting adjustments made.
tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js - Updated assertions in Cypress tests to reflect changes in timestamp format and messages displayed when entries are not saved.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Sidebar
    participant FrmAppHelper

    User->>Sidebar: Request Entry Timestamps
    Sidebar->>FrmAppHelper: get_formatted_time(date, date_format, time_format)
    FrmAppHelper->>FrmAppHelper: add_time_to_date(time_format, date)
    FrmAppHelper-->>Sidebar: Return Formatted Date and Time
    Sidebar-->>User: Display Timestamps
Loading

Possibly related PRs

Warning

Rate limit exceeded

@Crabcyborg has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 22 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8751e6c and 547cfa6.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8751e6c and 547cfa6.

📒 Files selected for processing (1)
  • tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js (1 hunks)
🔇 Additional comments (1)
tests/cypress/e2e/Entries/EntriesPageDataValidations.cy.js (1)

161-161: LGTM! Test updated to match new timestamp format.

The regex pattern has been correctly updated to validate the new timestamp format that uses "at" instead of "@" and includes AM/PM indicators, aligning with the PR's objective to use WordPress date and time settings.


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 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
Copy Markdown
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: 0

🧹 Outside diff range and nitpick comments (3)
classes/views/frm-entries/_sidebar-shared-pub.php (2)

16-23: Consider enhancing date format handling robustness

While the implementation works, consider these improvements:

  1. Handle both uppercase 'F' and lowercase 'f' month formats
  2. Validate the date format string to ensure it's valid
  3. Consider making the month abbreviation configurable rather than hardcoding it

Here's a suggested improvement:

 $date_format = get_option( 'date_format' );
 if ( $date_format ) {
     // Use short months since the sidebar space is limited.
-    $date_format = str_replace( 'F', 'M', $date_format );
+    $date_format = str_ireplace( array( 'F', 'f' ), 'M', $date_format );
+    // Validate the format string
+    if ( ! FrmAppHelper::is_valid_date_format( $date_format ) ) {
+        $date_format = __( 'M j, Y', 'formidable' );
+    }
 } else {
     // Fallback if there is no option in the database.
     $date_format = __( 'M j, Y', 'formidable' );
 }

43-43: Consider validating the updated_at timestamp

While the code checks for existence and inequality with created_at, it might be good to validate the timestamp format to prevent potential display issues with invalid dates.

- '<b>' . esc_html( FrmAppHelper::get_formatted_time( $entry->updated_at, $date_format ) ) . '</b>'
+ '<b>' . esc_html( FrmAppHelper::is_valid_timestamp( $entry->updated_at ) ? 
+     FrmAppHelper::get_formatted_time( $entry->updated_at, $date_format ) : 
+     __( 'Invalid date', 'formidable' ) ) . '</b>'
classes/helpers/FrmAppHelper.php (1)

2698-2702: LGTM! Consider extracting the " at " string to a constant.

The new add_time_to_date method is well-structured and handles time formatting appropriately. For improved maintainability, consider extracting the " at " string to a class constant since it's a UI text that may need to be modified in the future.

+ private const TIME_SEPARATOR = ' at ';
  private static function add_time_to_date( $time_format, $date ) {
      if ( empty( $time_format ) ) {
          $time_format = get_option( 'time_format' );
      }

      $trimmed_format = trim( $time_format );
      $time = '';
      if ( $time_format && ! empty( $trimmed_format ) ) {
-         $time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
+         $time = ' ' . __( 'at', 'formidable' ) . self::TIME_SEPARATOR . self::get_localized_date( $time_format, $date );
      }

      return $time;
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0e23fb2 and 8751e6c.

📒 Files selected for processing (2)
  • classes/helpers/FrmAppHelper.php (1 hunks)
  • classes/views/frm-entries/_sidebar-shared-pub.php (2 hunks)
🔇 Additional comments (2)
classes/views/frm-entries/_sidebar-shared-pub.php (2)

8-9: LGTM!

The variable fallback is implemented correctly.


29-29: Verify timezone handling in the new time formatting implementation

The switch to get_formatted_time() looks good, but we should ensure it properly handles timezone conversions like the previous implementation.

✅ Verification successful

Let me gather more information about the timezone handling implementation.


Let me check the complete implementation of get_formatted_time to understand how it handles dates.


Let me check the implementation of get_localized_date since it seems to be handling the actual date formatting.


Timezone handling is properly implemented in the new code

The get_formatted_time() implementation correctly handles timezone conversion through WordPress core functions:

  • Uses get_date_from_gmt() to convert from GMT to local timezone
  • Uses date_i18n() for localized date formatting
  • Respects WordPress date and time format settings via get_option()
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for timezone handling in the new method
ast-grep --pattern 'function get_formatted_time($_) {
  $$$
}'

# Look for timezone-related code in the helper class
rg -l "timezone|get_option.*timezone|date_default_timezone" --type php

Length of output: 178


Script:

#!/bin/bash
# Check the implementation in FrmAppController.php
rg -A 10 "timezone|get_option.*timezone|date_default_timezone" classes/controllers/FrmAppController.php

# Look for the actual get_formatted_time implementation
rg -A 5 "function get_formatted_time" --type php

Length of output: 980


Script:

#!/bin/bash
# Get the full implementation of get_formatted_time
rg -B 2 -A 20 "function get_formatted_time" classes/helpers/FrmAppHelper.php

# Look for any WordPress date/time related functions being used
rg "get_option\( '(date_format|time_format|timezone|gmt_offset)" classes/helpers/FrmAppHelper.php

Length of output: 969


Script:

#!/bin/bash
# Get the implementation of get_localized_date
rg -B 2 -A 15 "function get_localized_date" classes/helpers/FrmAppHelper.php

# Also check if there are any timezone-related functions being used
rg "date_default_timezone_get|wp_timezone|get_timezone" classes/helpers/FrmAppHelper.php

Length of output: 628

@Crabcyborg Crabcyborg added this to the 6.16.2 milestone Nov 19, 2024
@Crabcyborg Crabcyborg changed the title Pro issue 5418 Pro issue 5418 / Use WordPress date and time settings for entry timestamp in view entry sidebar Nov 19, 2024
@Crabcyborg Crabcyborg changed the title Pro issue 5418 / Use WordPress date and time settings for entry timestamp in view entry sidebar Pro issue 5418 / Use WordPress date and time settings for entry timestamp in edit/view entry sidebar Nov 19, 2024
@Crabcyborg Crabcyborg modified the milestones: 6.16.2, 6.16.3 Nov 20, 2024
Copy link
Copy Markdown
Contributor

@lauramekaj1 lauramekaj1 left a comment

Choose a reason for hiding this comment

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

@Crabcyborg I tested it and it's working as expected. Thank you!

@Crabcyborg
Copy link
Copy Markdown
Contributor Author

Thank you Laura!

🚀

@Crabcyborg Crabcyborg merged commit 998be60 into master Nov 25, 2024
@Crabcyborg Crabcyborg deleted the pro_issue_5418 branch November 25, 2024 15:58
This was referenced Nov 26, 2024
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.

2 participants