10000 Fea: new date formates 9652 by vinayaknolastname · Pull Request #9686 · nocodb/nocodb · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fea: new date formates 9652 #9686

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

Merged

Conversation

vinayaknolastname
Copy link
Contributor

Change Summary

Added new date formates requested in - #9652

Change type

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

Test/ Verification

Provide summary of changes.

Additional information / screenshots (optional)

image

Anything for maintainers to be made aware of

If im missing something please mention it i will do it

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Oct 19, 2024
@CLAassistant
Copy link
CLAassistant commented Oct 19, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor
coderabbitai bot commented Oct 19, 2024
📝 Walkthrough

Walkthrough

The changes involve updates to documentation and code to support additional date formats in the Date Time and Date field types. Two new formats, DD MMM YYYY and DD MMM YY, have been added to the relevant documentation files and incorporated into the date handling utilities in the codebase. The modifications enhance the flexibility of date representations without altering existing functionalities or structures.

Changes

File Path Change Summary
packages/noco-docs/docs/070.fields/040.field-types/070.date-time-ba 8000 sed/010.date-time.md Updated to include new supported date formats: DD MMM YYYY and DD MMM YY.
packages/noco-docs/docs/070.fields/040.field-types/070.date-time-based/020.date.md Updated to include new supported date formats: DD MMM YYYY and DD MMM YY.
packages/nocodb-sdk/src/lib/dateTimeHelper.ts Added new date formats 'DD MMM YYYY' and 'DD MMM YY' to the dateFormats array.
packages/nocodb/src/helpers/convertDateFormat.ts Modified convertDateFormat function to handle new formats with conditions for 'mysql2' and 'sqlite3'.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DateField
    participant DateTimeHelper
    participant ConvertDateFormat

    User->>DateField: Input date in new format
    DateField->>DateTimeHelper: Parse date
    DateTimeHelper-->>DateField: Return parsed date
    DateField->>ConvertDateFormat: Convert date format
    ConvertDateFormat-->>DateField: Return converted date
    DateField-->>User: Display date
Loading

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.

@dosubot dosubot bot added the 🔦 Type: Feature New functionality is requested. label Oct 19, 2024
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: 1

🧹 Outside diff range and nitpick comments (7)
packages/noco-docs/docs/070.fields/040.field-types/070.date-time-based/020.date.md (2)

33-34: LGTM! New date formats added correctly.

The new date formats "DD MMM YYYY" and "DD MMM YY" have been added correctly to the "Supported date formats" table. These additions align with the PR objectives and the AI-generated summary, enhancing the flexibility of date input options as intended.

Consider adding a brief explanation of what "MMM" represents (abbreviated month names) in the table or in a note below the table, to ensure clarity for all users.


Line range hint 1-34: Consider enhancing the documentation for better clarity and organization.

The additions to the supported date formats table are valuable. To further improve the document, consider the following suggestions:

  1. Reorder the table entries to group similar formats together. For example, place the new "DD MMM YYYY" and "DD MMM YY" formats next to other day-first formats.

  2. Add a brief introduction to the new formats in the document, explaining their significance and use cases.

  3. Include a note about the flexibility these new formats provide, especially for international date representations.

Here's a suggested reordering of the table entries:

| Format       | Example      |
|--------------|--------------|
| YYYY-MM-DD   | 2023-09-22   |
| YYYY/MM/DD   | 2023/09/22   |
| YYYY MM DD   | 2023 09 22   |
| DD-MM-YYYY   | 22-09-2023   |
| DD/MM/YYYY   | 22/09/2023   |
| DD MM YYYY   | 22 09 2023   |
| DD MMM YYYY  | 22 JAN 2024  |
| DD MMM YY    | 22 JAN 24    |
| MM-DD-YYYY   | 09-22-2023   |
| MM/DD/YYYY   | 09/22/2023   |
| MM DD YYYY   | 09 22 2023   |

Consider adding a brief explanation before the table:

"NocoDB now supports a wide range of date formats, including formats with abbreviated month names (MMM). This enhancement provides greater flexibility for international date representations."

packages/noco-docs/docs/070.fields/040.field-types/070.date-time-based/010.date-time.md (2)

34-35: LGTM! New date formats added correctly.

The new date formats "DD MMM YYYY" and "DD MMM YY" have been added to the "Supported date formats" table. These additions are consistent with the existing format and provide clear examples.

Some observations:

  1. The new formats are correctly aligned with the table structure.
  2. The examples provided ("22 JAN 2024" and "22 JAN 24") are clear and follow the specified format.
  3. These additions enhance the flexibility of date representations as mentioned in the PR objectives.

Consider adding a note or link to documentation about localization, as the month abbreviations (e.g., "JAN") might vary in different languages.


Image datetime.png is Missing from the Expected Location

The referenced image /img/v2/fields/types/datetime.png does not exist in the repository. Please ensure that the image is added to packages/noco-docs/public/img/v2/fields/types/ or update the documentation to reference the correct image path.

🔗 Analysis chain

Line range hint 1-35: Consider updating other sections for consistency.

The new date formats have been successfully added to the "Supported date formats" table. To ensure complete documentation:

  1. Review the "Create a date time field" section (steps 4-5) to check if it needs updating to mention the new format options.
  2. Consider adding an example using one of the new formats in the main description or in the field creation steps.
  3. Verify if the screenshot (/img/v2/fields/types/datetime.png) needs updating to reflect these new format options.

To check if the image needs updating, please run:

This will help determine if the image needs to be updated to reflect the new format options.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the datetime field image exists and when it was last modified

# Test: Check if the image exists and its last modification date
if [ -f "packages/noco-docs/public/img/v2/fields/types/datetime.png" ]; then
    echo "Image exists. Last modified:"
    stat -c %y "packages/noco-docs/public/img/v2/fields/types/datetime.png"
else
    echo "Image does not exist at the expected location."
fi

Length of output: 174

packages/nocodb/src/helpers/convertDateFormat.ts (2)

20-23: LGTM! Consider a minor optimization.

The new date format conditions for 'DD MMM YYYY' and 'DD MMM YY' are correctly implemented and consistent with the existing code structure. The use of '%b' for month abbreviation and the differentiation between '%Y' and '%y' for year formats are appropriate.

Consider combining the database type check to reduce repetition:

-  } else if (date_format === 'DD MMM YYYY') {
-    if (type === 'mysql2' || type === 'sqlite3') return '%d %b %Y';
-  } else if (date_format === 'DD MMM YY') {
-    if (type === 'mysql2' || type === 'sqlite3') return '%d %b %y';
+  } else if (type === 'mysql2' || type === 'sqlite3') {
+    if (date_format === 'DD MMM YYYY') return '%d %b %Y';
+    if (date_format === 'DD MMM YY') return '%d %b %y';
   }

This change would slightly improve readability and reduce the nesting level.


Line range hint 1-27: Consider future refactoring for improved maintainability.

The new date format additions are well-integrated and don't impact existing functionality. The function remains consistent in its approach to format conversion.

For future improvements, consider refactoring this function to use a mapping object or switch statement. This could enhance readability and make it easier to add or modify formats in the future. For example:

const formatMap = {
  'YYYY-MM-DD': '%Y-%m-%d',
  'YYYY/MM/DD': '%Y/%m/%d',
  // ... other formats ...
  'DD MMM YYYY': '%d %b %Y',
  'DD MMM YY': '%d %b %y',
};

export function convertDateFormat(date_format: string, type: string) {
  if (type === 'mysql2' || type === 'sqlite3') {
    return formatMap[date_format] || date_format;
  }
  return date_format;
}

This approach would make the function more scalable and easier to maintain as new date formats are added.

packages/nocodb-sdk/src/lib/dateTimeHelper.ts (1)

30-32: Approve new date formats with minor suggestions.

The addition of 'DD MMM YYYY' and 'DD MMM YY' formats is good and aligns with the PR objective. However, there are a few minor points to address:

  1. The comment could be improved for clarity and consistency with the codebase style. Consider changing it to:

    // Added 2 new formats as per issue #9652
  2. Use consistent quote style for string literals. Preferably single quotes to match the existing entries:

    'DD MMM YYYY',
    'DD MMM YY'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3e94215 and 18a523a.

📒 Files selected for processing (4)
  • packages/noco-docs/docs/070.fields/040.field-types/070.date-time-based/010.date-time.md (1 hunks)
  • packages/noco-docs/docs/070.fields/040.field-types/070.date-time-based/020.date.md (1 hunks)
  • packages/nocodb-sdk/src/lib/dateTimeHelper.ts (1 hunks)
  • packages/nocodb/src/helpers/convertDateFormat.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
packages/noco-docs/docs/070.fields/040.field-types/070.date-time-based/010.date-time.md (1)

Line range hint 1-35: Approved: New date formats successfully added.

This review has covered the following aspects:

  1. The new date formats "DD MMM YYYY" and "DD MMM YY" have been correctly added to the "Supported date formats" table.
  2. The additions are consistent with the existing document structure and enhance the flexibility of date representations.
  3. The overall document remains well-structured and informative.

Suggestions for further improvement have been provided in previous comments, including:

  • Considering a note about localization for month abbreviations.
  • Reviewing other sections of the document for consistency with the new formats.
  • Verifying if the associated image needs updating.

These suggestions are minor and do not impact the approval of the current changes. Great job on expanding the supported date formats!

packages/nocodb-sdk/src/lib/dateTimeHelper.ts (1)

Line range hint 1-32: Summary of changes and recommendations

The changes to dateTimeHelper.ts are minimal and focused, successfully adding two new date formats as requested. The implementation is correct and doesn't require changes to existing functions, which is positive for maintaining current functionality.

To further improve this PR:

  1. Address the minor code style suggestions for consistency.
  2. Consider adding tests to verify the new formats work correctly with existing functions.
  3. If applicable, update any relevant documentation to reflect the newly supported date formats.

Overall, good job on implementing this feature with minimal impact on the existing codebase.

Comment on lines +30 to +32
///added 2 new format#9652
'DD MMM YYYY',
"DD MMM YY"
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Add tests for the newly introduced date formats.

No existing tests cover the new date formats 'DD MMM YYYY' and "DD MMM YY". To ensure these formats are correctly validated and parsed across all relevant functions, please add the following tests:

  1. Validation Tests:

    • Verify that validateDateWithUnknownFormat correctly validates dates in the new formats.
  2. Format Identification Tests:

    • Ensure that getDateFormat accurately identifies and returns the new formats.
  3. Date-Time Parsing Tests:

    • Confirm that getDateTimeFormat handles the new date formats in combination with existing time formats.

Implementing these tests will help maintain the robustness of the codebase and prevent potential issues related to date handling.

🔗 Analysis chain

Consider adding tests for new date formats.

The addition of new date formats is straightforward and doesn't require changes to existing functions. However, to ensure robustness, consider adding tests that verify:

  1. validateDateWithUnknownFormat correctly validates dates in the new formats.
  2. getDateFormat correctly identifies and returns the new formats.
  3. getDateTimeFormat works correctly with the new date formats combined with existing time formats.

This will help catch any potential issues and ensure the new formats integrate smoothly with the existing codebase.

To assist in verifying the impact and usage of these new formats, you can run the following script:

This script will help identify if there are existing tests for the new formats and where date format validation or parsing is used in the codebase, which might need to be updated or tested with the new formats.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage and tests of new date formats

# Test: Search for usage of new date formats in test files
echo "Searching for tests of new date formats:"
rg --type typescript -g '*test*' -i "DD MMM (YYYY|YY)"

# Test: Search for usage of date format validation or parsing in the codebase
echo "Searching for date format validation or parsing usage:"
rg --type typescript 'validateDateWithUnknownFormat|getDateFormat|getDateTimeFormat'

Length of output: 423


Script:

#!/bin/bash
# Description: Check for usage and tests of new date formats with corrected file type patterns

# Test: Search for usage of new date formats in test files
echo "Searching for tests of new date formats:"
rg -g "*.ts" -g "*.tsx" -i "DD MMM (YYYY|YY)" 

# Test: Search for usage of date format validation or parsing in the codebase
echo "Searching for date format validation or parsing usage:"
rg -g "*.ts" -g "*.tsx" 'validateDateWithUnknownFormat|getDateFormat|getDateTimeFormat'

Length of output: 3601

@vinayaknolastname vinayaknolastname changed the title Fea/new date formates 9652 Fea: new date formates 9652 Oct 19, 2024
@DarkPhoenix2704 DarkPhoenix2704 merged commit 2766dc8 into nocodb:develop May 21, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:S This PR changes 10-29 lines, ignoring generated files. 🔦 Type: Feature New functionality is requested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0