Skip to content
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

text_date_timestamp field incorrectly displaying some timestamps #1448

Closed
PaulBRobinson opened this issue Feb 17, 2022 · 6 comments
Closed

Comments

@PaulBRobinson
Copy link

PaulBRobinson commented Feb 17, 2022

Describe the bug

On entering some dates the text_date_timestamp field type will display an incorrect date after the field has been saved.

Steps to reproduce

  1. Create a text_date_timestamp field as normal, I am using it on a custom post type, but this doesn't seem to matter.
  2. Using the default date format as shown in the CMB documentation enter the date 07/23/2022. It has occurred with other dates too but this is just one I've chosen for testing.
  3. Save the post. If your post type is using the Gutenberg editor you will need to refresh the page, due to the save being done without reloading.
  4. The date field should now show an incorrect date, I see 02/17/4400

Possible Solution

I believe I have tracked the issue down to a change (commit 37c8763 I believe) to the CMB2_Utils::make_valid_time_stamp() function. Passing a valid timestamp through strtotime() such as 1658534400 (which is the timestamp for 07/23/2022) does not always return false and so returns an unexpected timestamp such as 76687491533 which is 02/17/4400.

Replicated on a fresh WordPress install, using a fresh download of the git repo. Also replicated by taking an unrelated project using an older version of CMB2 (2.7.0) and adding the changes implemented to CMB2_Utils::make_valid_time_stamp(). Doing so introduced the problem described above, and was fixed by reverting the code.

I have rolled back to the code to from before the commit and that has fix the issue for my client's site. I believe the commit was required to help with dates from the API etc so that may not be the best overall solution.

CMB2 Field Registration Code:

Replicated in multiple projects. Using the registration code taken from the documentation for a text_date_timestamp field has reproduced this error during testing. For example:

//... Standard registration for text_date_timestamp
$cmb->add_field( array(
    'name' => 'Test Date Picker (UNIX timestamp)',
    'id'   => 'wiki_test_textdate_timestamp',
    'type' => 'text_date_timestamp',
    // 'timezone_meta_key' => 'wiki_test_timezone',
    // 'date_format' => 'l jS \of F Y',
) );

The code provided for the text_date_timestamp in the example-functions.php file can also be used.

Your Environment

Replicated on multiple environments (Apache + Nginx), using PHP versions 7.4 and 8.0.

Additional Notes

The problem does not appear to be too disruptive as the timestamp is saved to the database correctly, it is just displayed in the admin field incorrectly. However if the page is saved while the incorrect date is shown in the field it appears to replace the date with the incorrect date causing disruption to the site.

@zodit
Copy link

zodit commented Feb 21, 2022

I confirm, this bug is in version 2.10 (wrong specific dates on both versions: 18-01-2022 or 01/18/2022, 21-04-2022, 18-06-2022).
Reverting back to 2.9 the bug is not present.

@jtsternberg
Copy link
Member

Thank you for reporting. Can you test the changes on the develop branch to confirm the issue is fixed for your use-cases?

@zodit
Copy link

zodit commented Feb 22, 2022

Thank you for reporting. Can you test the changes on the develop branch to confirm the issue is fixed for your use-cases?

Done, fixed.

@PaulBRobinson
Copy link
Author

Thank you for your quick response. Yes, I can also confirm this is fixed.

@jtsternberg
Copy link
Member

2.10.1 was just pushed to fix this.

@fedesib
Copy link

fedesib commented May 4, 2022

Hi there,
I just found out that with version 2.10.1 if you choose a date before 1900 it is rendered in a wrong way in the editor (the timestamp in the DB is correct). Reverting to version 2.9 solves the issue.
PHP version: 7.4.28 WP version: 5.9.3

Image with an example follows:
CMB2-2 10 1
CMB2-2 9 0

Thanks!

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

No branches or pull requests

4 participants