Make WordPress Core

Opened 6 months ago

Closed 8 weeks ago

Last modified 7 weeks ago

#62400 closed defect (bug) (reported-upstream)

RSS Block showing date in UTC when pubDate in feed is not

Reported by: kaitohm's profile kaitohm Owned by: pbearne's profile pbearne
Milestone: Priority: normal
Severity: normal Version: 6.7
Component: Editor Keywords: gutenberg-merge close
Focuses: Cc:

Description

Originally reported in this Japanese support thread.

To reproduce:

  1. Change the site timezone to something other than UTC+0. (Example: UTC+9)
  2. Include an RSS Block to any post.
  3. Add a link to an RSS feed where the pubDate item is not in GMT/UTC. (Example: https://www.mixonline.jp/DesktopModules/MixOnline_Rss/MixOnlinerss.aspx?rssmode=3 where pubDate has a +0900 offset.)
  4. In block settings, turn on Display date.
  5. Both in the editor and the published post, the date will be shown in UTC. (Example: An article with <pubDate>Wed, 13 Nov 2024 04:52:00 +0900</pubDate> in the feed will be shown November 12, 2024. With the site timezone set to UTC+9, I would expect this to say November 13, 2024)

Things I've tested:

Change History (30)

#1 @sainathpoojary
6 months ago

Hi @kaitohm,

Welcome to Trac, and thank you for opening this ticket!

I’ve confirmed that I could reproduce the issue on WordPress version 6.7. There seems to be an inconsistency in the date between the editor/front end, and the feed data.

Thanks again for bringing this to attention!

#2 @narenin
6 months ago

Hi @kaitohm

I have tried to replicate this issue and I am able to replicate this at my end too.

Environment

WordPress: 6.7-beta1-59152-src
PHP: 8.3.7
Server: nginx/1.25.4
Database: mysqli (Server: 8.3.0 / Client: mysqlnd 8.3.7)
Browser: Chrome 125.0.0.0
OS: macOS
Theme: Twenty Twenty-One Version 2.2
MU Plugins: None activated
Plugins:

Related File : packages/block-library/src/rss/index.php line no. 53,54

Also it looks like this is happening because we are using date_i18n() function in WordPress formats a date according to the locale and the settings defined in WordPress, but it does not automatically adjust the time according to the timezone set in WordPress settings (Settings > General > Timezone). It relies on the get_option( 'timezone_string' ) or get_option( 'gmt_offset' ) to determine the correct time zone. However, the date_i18n() function formats the date based on the server time (which could be in UTC or any other server timezone) unless you explicitly adjust for timezones.

Last edited 6 months ago by narenin (previous) (diff)

#3 @narenin
6 months ago

  • Keywords has-testing-info added

#4 follow-up: @sainathpoojary
6 months ago

Hey @kaitohm,

As this issue is related to Gutenberg, I’ve opened a issue in the Gutenberg repository for further review.

You can track the progress here: https://github.com/WordPress/gutenberg/issues/66970

This ticket was mentioned in Slack in #core-test by oglekler. View the logs.


6 months ago

#6 @oglekler
6 months ago

  • Keywords gutenberg-merge added

@kirasong please check this as as a candidate to 6.7.1. release.

#7 in reply to: ↑ 4 @kaitohm
6 months ago

Replying to sainathpoojary:

Hey @kaitohm,

As this issue is related to Gutenberg, I’ve opened a issue in the Gutenberg repository for further review.

You can track the progress here: https://github.com/WordPress/gutenberg/issues/66970

Thanks!

#8 @Mamaduka
6 months ago

Already replied on the Gutenberg issue, but the same problem probably affects the legacy RSS widget - https://github.com/WordPress/wordpress-develop/blob/a27e6a8ecd5279a45e47ef88d048643740d07b5a/src/wp-includes/widgets.php#L1654-L1660.

@kaitohm, can you clarify the expected behavior in the description?

I expect that the RSS block/widget will display dates in the format specified in WP, but the date will be in the origins timezone. Unless I'm missing something, the publishing date shouldn't be relative to the WP configuration.

#9 @kaitohm
6 months ago

@kaitohm, can you clarify the expected behavior in the description?

@Mamaduka Did you mean here in Trac, or in the GitHub issue?

Currently, if the feed says <pubDate>Wed, 13 Nov 2024 04:00:00 +0900</pubDate>, then regardless of site timezone, the block shows November 12th.

What should happen is, if the feed says <pubDate>Wed, 13 Nov 2024 04:00:00 +0900</pubDate>, then

  • if the site timezone is set to UTC+5, UTC+6, UTC+7..., then the block should show November 13th.
  • if the site timezone is set to UTC+4, UTC+3, UTC+2..., then the block should show November 12th.

As another example, if the feed says <pubDate>Wed, 13 Nov 2024 04:00:00 GMT</pubDate>, then

  • if the site timezone is set to UTC-4, UTC-3, UTC-2..., then the block should show November 13th.
  • if the site timezone is set to UTC-5, UTC-6, UTC-7..., then the block should show November 12th.

#10 follow-up: @Mamaduka
6 months ago

Thank you, @kaitohm!

Either place is fine. We'll also need to apply the fix to the legacy RSS widget.

This ticket was mentioned in PR #7798 on WordPress/wordpress-develop by @narenin.


6 months ago
#11

  • Keywords has-patch added

#12 in reply to: ↑ 10 @kaitohm
6 months ago

Replying to Mamaduka:

Thank you, @kaitohm!

Either place is fine. We'll also need to apply the fix to the legacy RSS widget.

My pleasure! :-)

#13 @narenin
6 months ago

@Mamaduka I have added PR fix for the legacy RSS widget.

https://github.com/WordPress/wordpress-develop/pull/7798

#14 @desrosj
6 months ago

  • Milestone changed from Awaiting Review to 6.7.2

#15 @pbearne
6 months ago

  • Milestone changed from 6.7.2 to 6.8

#16 @pbearne
6 months ago

  • Owner set to pbearne
  • Status changed from new to assigned

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


2 months ago

#18 @audrasjb
2 months ago

  • Keywords needs-design added

#19 @audrasjb
2 months ago

  • Keywords needs-testing added; needs-design removed

Adding needs-testing keyword.

#20 @saurabh.dhariwal
2 months ago

  • Focuses tests added

Test Case: Incorrect Date Display in RSS Block When Site Timezone is Changed

Title: Verify if RSS block displays the correct date when the site timezone is changed from UTC+0 to UTC+9

Test Type: Functional, Regression

Environment:

WordPress Version: 6.7.2
Theme: Default
Plugins: None (Test with a clean setup)
PHP Version: 8.1
Debug Mode: Enabled (define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); define('WP_DEBUG_DISPLAY', false);)

Preconditions:

WordPress is installed and running.
Site timezone is initially set to UTC+0 under Settings > General > Timezone.
No caching plugin or custom time-related code is active.

Test Steps:

Navigate to Settings > General in the WordPress admin panel.
Change the Timezone to UTC+9 (Tokyo, JST) and save changes.
Create or edit an existing post and add an RSS Block.
In the RSS Block settings, enter an RSS feed URL where pubDate is not in GMT/UTC.

Example: https://www.mixonline.jp/DesktopModules/MixOnline_Rss/MixOnlinerss.aspx?rssmode=3
This feed contains <pubDate> with a +0900 offset.

Enable the Display Date option in the block settings.
Publish the post and view it on the frontend.
Observe the displayed date in both:

Block Editor Preview
Published Post View

Compare the displayed date with the expected local time conversion based on the site’s timezone.

Expected Result:

The date should be correctly converted and displayed based on the site's timezone (UTC+9).
Example: If the feed contains <pubDate>Wed, 13 Nov 2024 04:52:00 +0900</pubDate>, it should display as November 13, 2024.

Actual Result:

[FAIL] The RSS block still shows the date in UTC instead of the site's local timezone.

Example: It incorrectly displays November 12, 2024 instead of November 13, 2024.

[PASS] If the date is correctly shown in the site's timezone.

Post-Test Actions:

Check the RSS Block source code for time conversion logic.
Test with different timezones (e.g., UTC-5, UTC+5:30) to confirm if the issue is global.
Report the bug to WordPress Core or Gutenberg development team if confirmed.
Possible Workaround: Manually convert the time using a custom shortcode or plugin.

Additional Notes:

If using a caching plugin, clear cache and recheck.
Try using different RSS feeds to see if the issue persists.

Screenshot : when UTC 0 : https://prnt.sc/8PfPxql9jYGy
Screenshot: change to UTC 9 : https://prnt.sc/M_UN8StQ_NxI

#21 @SirLouen
8 weeks ago

  • Focuses tests removed
  • Keywords needs-unit-tests needs-patch added; has-patch needs-testing removed

Combined Reproduction Report and Patch Testing

Description

This report can't validate that the patch is working as expected.
@narenin can you check it out?
It also would be great to set up some unit tests

Patch tested: https://patch-diff.githubusercontent.com/raw/WordPress/wordpress-develop/pull/7798.diff

Environment

  • WordPress: 6.8-beta3-60042-src
  • PHP: 8.2.28
  • Server: nginx/1.27.4
  • Database: mysqli (Server: 8.4.4 / Client: mysqlnd 8.2.28)
  • Browser: Chrome 134.0.0.0
  • OS: Windows 10/11
  • Theme: My Twenty Twenty Child Theme 1.0
  • MU Plugins: None activated
  • Plugins:
    • Test Reports 1.2.0

Steps taken

  1. Change timezone to UTC-7
  2. Added the RSS https://www.newtimesslo.com/sanluisobispo/Rss.xml
  3. Display date activated on the block
  1. Change timezone to UTC+9
  2. Added the RSS https://www.mixonline.jp/DesktopModules/MixOnline_Rss/MixOnlinerss.aspx?rssmode=3(https://www.mixonline.jp/DesktopModules/MixOnline_Rss/MixOnlinerss.aspx?rssmode=3)

Results Before patch

  1. ✅ Can confirm a misalignment with the date in Japanese test
  2. ✅ Can confirm a misalignment with the date in USA test

Patch testing

  1. ❌ After testing patch in both Japanese and USA feeds with their respective time zones, its not working as expected for any of the two scenarios


Supplemental Artifacts

Screenshot of USA Test before the patch https://i.imgur.com/JsJm8RH.png
Screenshot of USA Test after patch: https://i.imgur.com/gwOX8ZE.png

Screenshot of Japanese Test before patch: https://i.imgur.com/3h1sIz3.png
Screenshot of Japanese Test after patch: https://i.imgur.com/dmKTVXZ.png

Last edited 8 weeks ago by SirLouen (previous) (diff)

This ticket was mentioned in PR #8543 on WordPress/wordpress-develop by @SirLouen.


8 weeks ago
#22

  • Keywords has-patch added; needs-patch removed

This patch solves the problem that GMT Offset is not aligning correctly with the RSS Feeds in the RSS Gutenberg Block

For testing, check the instructions in the OP Post in Trac

Trac ticket: https://core.trac.wordpress.org/ticket/62400

#23 @SirLouen
8 weeks ago

  • Keywords has-unit-tests needs-testing added; needs-unit-tests removed

Added unit tests

@SirLouen commented on PR #8543:


8 weeks ago
#24

Ok @peterwilsoncc I think I've sorted everything

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


8 weeks ago

@SirLouen commented on PR #8543:


8 weeks ago
#26

@peterwilsoncc added all recommended changes + added the patch to Gutenberg repo:
https://github.com/WordPress/gutenberg/pull/69645

I've been checking, and I can't see any Gutenberg Unit Tests section.

Also, I'm not sure, if the changes to src/wp-includes/blocks/rss.php should stay, should be reverted, or are nowadays irrelevant.

I'm not 100% confident yet how the integration of Gutenberg works with WP Core. All I know there is a plugin for Gutenberg, but then I also know that there is like a slightly older and more stable version, being regularly integrated into core. But I'm not sure how this is integration is being done.

@peterwilsoncc commented on PR #8543:


8 weeks ago
#27

I've been checking, and I can't see any Gutenberg Unit Tests section.

The tests for blocks in the Gutenberg repo are in https://github.com/WordPress/gutenberg/tree/trunk/phpunit/blocks -- the RSS block doesn't have any tests, so you'd need to create a file.

Also, I'm not sure, if the changes to src/wp-includes/blocks/rss.php should stay, should be reverted, or are nowadays irrelevant.

I'm not 100% confident yet how the integration of Gutenberg works with WP Core. All I know there is a plugin for Gutenberg, but then I also know that there is like a slightly older and more stable version, being regularly integrated into core. But I'm not sure how this is integration is being done.

It's a little confusing.

The edited file in this pull request is actually published in the Gutenberg NPM package @wordpress/block-library and updated as part of the syncing script, npm run sync-gutenberg-packages. So once the PR is merged in to the Gutenberg repo, this PR can be discarded as the fix will be included in the appropriate syncing.

I know it's odd to have PHP in an NPM package, but needs must.

The Gutenberg plugin is the bleeding-edge work, where as the files synced in to WordPress-Develop are considered stable.

Again, sorry I missed this was a Gutenberg generated file when I reviewed it yesterday.

#28 @SirLouen
8 weeks ago

  • Keywords close added; has-testing-info has-patch has-unit-tests needs-testing removed
  • Resolution set to invalid
  • Status changed from assigned to closed

This has been finally resolved here
https://github.com/WordPress/gutenberg/pull/69645

I'm proposing this for closing.

#29 @peterwilsoncc
7 weeks ago

  • Component changed from Date/Time to Editor
  • Milestone 6.8 deleted
  • Resolution changed from invalid to reported-upstream

I've modified the resolution of this ticket to reported-upstream, see GB#66970.

Thanks all for participating on this ticket, I'll be including you all in the props when merging the pull request in the Gutenberg repo.

@peterwilsoncc commented on PR #7798:


7 weeks ago
#30

An alternative version of this pull request was merged, see #69645.

Note: See TracTickets for help on using tickets.