Skip to content

Qa/fix potential date issue#51

Open
anobjectw wants to merge 3 commits intodevelopfrom
qa/fix-potential-date-issue
Open

Qa/fix potential date issue#51
anobjectw wants to merge 3 commits intodevelopfrom
qa/fix-potential-date-issue

Conversation

@anobjectw
Copy link
Copy Markdown
Contributor

No description provided.

mfucilli-troyweb and others added 3 commits August 6, 2025 09:17
@anobjectw anobjectw requested a review from Copilot October 8, 2025 10:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes a potential date formatting issue by replacing inline date handling with a robust helper function. Instead of directly using DateTime::createFromFormat() with a single format assumption, the code now uses a new waterportal_format_date_meta() function that handles multiple date formats gracefully.

  • Replaces inline date formatting logic with a dedicated helper function
  • Adds support for multiple date formats (Y-m-d, Y-m-d H:i:s, Y-m-d\TH:i:sP)
  • Improves date range display by trimming unnecessary characters

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


foreach ( $formats as $format ) {
$dt = DateTime::createFromFormat( $format, $raw_date );
if ( $dt instanceof DateTime ) {
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

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

The DateTime::createFromFormat() method can return false on failure, but it can also return a DateTime object with parsing errors. Use $dt !== false && $dt->getLastErrors()['warning_count'] === 0 && $dt->getLastErrors()['error_count'] === 0 instead of just checking instanceof to ensure the date was parsed correctly.

Suggested change
if ( $dt instanceof DateTime ) {
if ( $dt !== false && $dt->getLastErrors()['warning_count'] === 0 && $dt->getLastErrors()['error_count'] === 0 ) {

Copilot uses AI. Check for mistakes.
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