Skip to content

Fix: Allow leading zeros in HowTo block time duration fields #22511

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 0 commits into
base: trunk
Choose a base branch
from

Conversation

param-chandarana
Copy link

Context

Users reported that they cannot enter leading zeros (like "00" or "01") in HowTo block time duration fields. This prevents them from inputting valid time formats like "00:30" for 30 minutes, which is a common use case for recipe and tutorial timings.

Summary

This PR can be summarized in the following changelog entry:

  • Fixes a bug where users could not enter leading zeros in HowTo block time duration fields when specifying cooking or preparation times.

Suggested label: changelog: bugfix

Relevant technical choices:

  • Replaced regex-based leading zero removal with direct parseInt() parsing in the formatDuration() method
  • Maintains backward compatibility and all existing validation logic
  • Uses standard JavaScript parseInt(string, 10) which properly handles leading zeros while still converting to proper integers
  • No changes to the public API or existing functionality

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  1. Create a new post or page in WordPress admin
  2. Add a HowTo block to the content
  3. Click "Add total time" in the HowTo block
  4. Try to enter "00" in the hours field - it should now accept this input
  5. Try to enter "01" in the minutes field - it should now accept this input
  6. Try to enter "05" in any time field - it should now accept this input
  7. Verify that the time displays correctly in the frontend (e.g., "00:30" should show as "30 minutes")
  8. Verify that existing functionality still works (entering "10", "30", etc.)

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

  • HowTo structured data blocks (time duration input fields)
  • Time duration formatting and validation logic
  • Frontend display of HowTo block time information

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #12541

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HH and MM fields in HowTo block do not allow 00
2 participants