Conversation
…-Forms-for-Consistency Working/#83 update request forms for consistency
… issues using that createFromFormat
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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.
| if ( $dt instanceof DateTime ) { | |
| if ( $dt !== false && $dt->getLastErrors()['warning_count'] === 0 && $dt->getLastErrors()['error_count'] === 0 ) { |
No description provided.