Skip to content

fix: date picker field returns incorrect data #217

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 2.3.0

## Update Notice

This release refactored some internals regarding how Clone fields and Group fields behave. There was no intentional breaking changes to the Schema, but if you are using Clone and Group fields there is a chance that if you were benefiting from a "bug as a feature" there might be some changes that could impact your Schema and/or resolvers, we recommend testing this update on a staging site to ensure things are still working for you as expected. Should you run into any problems, please [open a new issue](https://github.com/wp-graphql/wpgraphql-acf/issues/new/choose) and provide as much detail as possible to help us reproduce the scenario. Thanks! 🙏

## New Features

- [#193](https://github.com/wp-graphql/wpgraphql-acf/pull/193): feat: improved handling of clone and group fields

## Chores / Bugfixes

- [#194](https://github.com/wp-graphql/wpgraphql-acf/pull/194): ci: test against WordPress 6.5

## 2.2.0

## New Features
Expand Down
10 changes: 10 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Learn more about how [Appsero collects and uses data](https://appsero.com/privac

== Upgrade Notice ==

= 2.3.0 =

This release refactored some internals regarding how Clone fields and Group fields behave. There was no intentional breaking changes to the Schema, but if you are using Clone and Group fields there is a chance that if you were benefiting from a "bug as a feature" there might be some changes that could impact your Schema and/or resolvers, we recommend testing this update on a staging site to ensure things are still working for you as expected. Should you run into any problems, please [open a new issue](https://github.com/wp-graphql/wpgraphql-acf/issues/new/choose) and provide as much detail as possible to help us reproduce the scenario. Thanks! 🙏

= 2.1.0 =

While fixing some [performance issues](https://github.com/wp-graphql/wpgraphql-acf/pull/152) we had to adjust the fallback logic for mapping ACF Field Groups to the Schema if they do not have "graphql_types" defined.
Expand All @@ -116,6 +120,12 @@ This release is a complete re-architecture of WPGraphQL for ACF, introducing bre

== Changelog ==

= 2.3.0 =

**New Features**

**Chores / Bugfixes**

= 2.2.0 =

**New Features**
Expand Down
14 changes: 0 additions & 14 deletions src/FieldConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,20 +541,6 @@ static function ( $opt ) {
$value = apply_filters( 'the_content', $value );
}

if ( ! empty( $acf_field_config['type'] ) && in_array(
$acf_field_config['type'],
[
'date_picker',
'time_picker',
'date_time_picker',
],
true
) ) {
if ( ! empty( $value ) && ! empty( $acf_field_config['return_format'] ) ) {
$value = gmdate( $acf_field_config['return_format'], strtotime( $value ) );
}
}

if ( ! empty( $acf_field_config['type'] ) && in_array( $acf_field_config['type'], [ 'number', 'range' ], true ) ) {
$value = (float) $value ?: null;
}
Expand Down
21 changes: 4 additions & 17 deletions src/FieldType/DatePicker.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace WPGraphQL\Acf\FieldType;

use DateTimeInterface;
use WPGraphQL\Acf\FieldConfig;

class DatePicker {
Expand All @@ -24,27 +25,13 @@ public static function register_field_type(): void {
'resolve' => static function ( $root, $args, $context, $info, $field_type, FieldConfig $field_config ) {
$value = $field_config->resolve_field( $root, $args, $context, $info );

if ( empty( $value ) ) {
return null;
}

$acf_field = $field_config->get_acf_field();

// Get the return format from the ACF Field
$return_format = $acf_field['return_format'] ?? null;

if ( empty( $return_format ) ) {
return $value;
}

$date_time = \DateTime::createFromFormat( $return_format . '|', $value );
$timestamp = strtotime( $value );

if ( empty( $date_time ) ) {
if ( false === $timestamp ) {
return null;
}

// appending '|' to the format prevents the minutes and seconds from being determined from the current time
return $date_time->format( \DateTimeInterface::RFC3339 );
return gmdate( DateTimeInterface::RFC3339, $timestamp );
},
]
);
Expand Down
15 changes: 3 additions & 12 deletions src/FieldType/DateTimePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,13 @@ public static function register_field_type(): void {
return null;
}

$acf_field = $field_config->get_acf_field();
$timestamp = strtotime( $value );

// Get the return format from the ACF Field
$return_format = $acf_field['return_format'] ?? null;

if ( empty( $return_format ) ) {
return $value;
}

$date_time = \DateTime::createFromFormat( $return_format, $value );

if ( empty( $date_time ) ) {
if ( false === $timestamp ) {
return null;
}

return $date_time->format( DateTimeInterface::RFC3339 );
return gmdate( DateTimeInterface::RFC3339, $timestamp );
},
]
);
Expand Down
4 changes: 2 additions & 2 deletions wpgraphql-acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: WPGraphQL for ACF seamlessly integrates Advanced Custom Fields with WPGraphQL.
* Author: WPGraphQL, Jason Bahl
* Author URI: https://www.wpgraphql.com
* Version: 2.2.0
* Version: 2.3.0
* Text Domain: wpgraphql-acf
* Requires PHP: 7.3
* Requires at least: 5.9
Expand All @@ -31,7 +31,7 @@
}

if ( ! defined( 'WPGRAPHQL_FOR_ACF_VERSION' ) ) {
define( 'WPGRAPHQL_FOR_ACF_VERSION', '2.2.0' );
define( 'WPGRAPHQL_FOR_ACF_VERSION', '2.3.0' );
}

if ( ! defined( 'WPGRAPHQL_FOR_ACF_VERSION_WPGRAPHQL_REQUIRED_MIN_VERSION' ) ) {
Expand Down