Skip to content

Commit 90c26aa

Browse files
committed
gppa-acf-date-formatter.php: Fixed date formatting issue caused by timezone offset resulting in a one-day discrepancy.
1 parent b2580db commit 90c26aa

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

gp-populate-anything/gppa-acf-date-formatter.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,24 @@
1313
* Plugin URI: http:///gravitywiz.com.com/documentation/gravity-forms-populate-anything/
1414
* Description: This snippet will format the value from a ACF Date field that is retrieved from the database and convert it into a Gravity Forms format Date field.
1515
* Author: Gravity Wiz
16-
* Version: 0.1
16+
* Version: 0.2
1717
* Author URI: http://gravitywiz.com
1818
*/
1919
add_filter( 'gppa_process_template_value', function( $template_value, $field, $template_name, $populate, $object, $object_type, $objects ) {
20-
2120
if ( strpos( $field->cssClass, 'gppa-format-acf-date' ) === false ) {
2221
return $template_value;
2322
}
2423

25-
return wp_date( 'd/m/Y', strtotime( $template_value ) );
24+
$timezone = new DateTimeZone( 'UTC' );
25+
26+
try {
27+
// Attempt to parse the date value.
28+
$date = new DateTime( $template_value );
29+
$date->setTimezone( $timezone ); // Ensure it's parsed as UTC.
30+
31+
return wp_date( 'd/m/Y', $date->getTimestamp(), $timezone );
32+
} catch ( Exception $e ) {
33+
// Handle invalid date formats gracefully.
34+
return $template_value;
35+
}
2636
}, 10, 7 );

0 commit comments

Comments
 (0)