-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(datetime): datetime locale with h23 will respect max time range #24610
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
Conversation
| */ | ||
| if (maxParts.hour !== undefined) { | ||
| processedHours = processedHours.filter(hour => { | ||
| const convertedHour = refParts.ampm === 'pm' ? (hour + 12) % 24 : hour; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this change works? If you are using 24 hour time, refParts.ampm should be undefined, which means convertedHour would be hour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workingParts (used as refParts in that util function) has ampm defined. Likely as a result of when we call processValue on initialization of the datetime component:
...
this.workingParts = {
...
ampm: hour >= 12 ? 'pm' : 'am'
}Where as the hour cycle only takes into consideration the locale or if the developer has hard-set the hour cycle.
So this case exists when the developer hasn't specified the hour cycle manually, but the locale requires it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks. Would it make more sense to not have ampm be optional then? https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/datetime/datetime-interface.ts#L21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that makes sense for now. I'll confirm we aren't using that interface for any partial date object comparisons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we are in a few places:
- https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/datetime/datetime.tsx#L1182
- https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/datetime/datetime.tsx#L563
- https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/datetime/datetime.tsx#L567
I'll create a tech debt task to have more strict explicit types.
|
Applies the same logic for restricting minutes used here fix(datetime): time picker format with hourCycle h23 #24476 Was this implemented? Since I am using ionic 6.0.4 and the minutes are not updated when choosing a time with the hour less than the hour of the max time. This was recently fixed for min value. |
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build) was run locally and any changes were pushednpm run lint) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Locales that have the hour cycle in 24 hour format, will not respect the max time range specified. This means if you set the max to
20:40, they are still able to select21, 22, 23for hour values.Issue Number: #24588
What is the new behavior?
Does this introduce a breaking change?
Other information