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

Fix/12 hour format validation #1631

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Sho-ki
Copy link

@Sho-ki Sho-ki commented May 16, 2024

Fix issue: #1625

Description of the Bug

The DateTime.fromFormat() function incorrectly validates certain 24-hour formats as valid when they should be considered invalid.
When using the 12-hour (h) format in the format parameter, the function does not properly invalidate times where the hour exceeds 12.

Actual vs Expected Behavior

DateTime.fromFormat('18:30 AM', 'h:mm a').isValid;

Actual: isValid returns true for DateTime.fromFormat('18:30 AM', 'h:mm a').
Expected: isValid shouldn't be true because 18 is not a valid hour for the 12-hour (h) format.

Fix Description

This PR addresses the issue by ensuring that when the 12-hour (h) format is used in the format parameter, any hour value greater than 12 is considered invalid, and isValid will throw error.

Copy link

linux-foundation-easycla bot commented May 16, 2024

CLA Signed


The committers listed above are authorized under a signed CLA.

@diesieben07
Copy link
Collaborator

While this is a valid bugfix, I am reluctant to merge this in and release it as a minor update, because it is technically a breaking change. Normally that would be fine for a bug fix, but I can imagine many people intentionally or unintentionally relying on this behavior. Maybe we should add a strictHours option for backwards compatibility?

What do you think, @icambron?

@jw642459986
Copy link

@diesieben07 are you suggesting something like this?
DateTime.fromFormat('18:30 AM', 'h:mm a').isValid('strictHours': true);

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

Successfully merging this pull request may close these issues.

3 participants