8000 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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ keywords: ['Fields', 'Field types', 'Date & Time', 'Create date time field']
| DD MM YYYY | 22 09 2023 |
| MM DD YYYY | 09 22 2023 |
| YYYY MM DD | 2023 09 22 |

| DD MMM YYYY | 22 JAN 2024 |
| DD MMM YY | 22 JAN 24 |

### Supported time formats
| Format | Example |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ keywords: ['Fields', 'Field types', 'Date & Time', 'Create date field']
| DD MM YYYY | 22 09 2023 |
| MM DD YYYY | 09 22 2023 |
| YYYY MM DD | 2023 09 22 |
| DD MMM YYYY | 22 JAN 2024 |
| DD MMM YY | 22 JAN 24 |

## Related fields
- [DateTime](010.date-time.md)
Expand Down
3 changes: 3 additions & 0 deletions packages/nocodb-sdk/src/lib/dateTimeHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const dateFormats = [
'DD MM YYYY',
'MM DD YYYY',
'YYYY MM DD',
///added 2 new format#9652
'DD MMM YYYY',
"DD MMM YY"
Comment on lines +30 to +32
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

];

export const isDateMonthFormat = (format: string) =>
Expand Down
5 changes: 5 additions & 0 deletions packages/nocodb/src/helpers/convertDateFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export function convertDateFormat(date_format: string, type: string) {
if (type === 'mysql2' || type === 'sqlite3') return '%m %d %Y';
} else if (date_format === 'YYYY MM DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y %m %d';
} 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';
}

// pg / mssql
return date_format;
}
0