Title: [295369] trunk/Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm
- Revision
- 295369
- Author
- [email protected]
- Date
- 2022-06-07 17:26:51 -0700 (Tue, 07 Jun 2022)
Log Message
Datetime-local Field Picker Shows Incorrect Date when seconds is zero
https://bugs.webkit.org/show_bug.cgi?id=239778
Patch by Mike Wyrzykowski <[email protected]> on 2022-06-07
Reviewed by Aditya Keerthi.
In r286869, a change was made to WebCore::DateComponents::toStringForTime as
noted in the changelog:
The output will use the shortest possible string, omitting seconds or milliseconds when 0, as per
https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-normalised-local-date-and-time-string
however that broke WebDateTimePicker when seconds or milliseconds is specified yet they are zero.
Since the change to WebCore::DateComponents is to spec, change WebDateTimePicker to handle this behavior
change instead.
* Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm:
(-[WKDateTimePicker updatePicker:]):
-[NSDataFormatter dateFromString:] will return nil if the format
requires seconds but the seconds is omitted, so try fallback formats
without milliseconds or seconds.
(-[WKDateTimePicker dateFormatFallbackForFormat:]):
Fallback from milliseconds -> seconds -> time without seconds.
Canonical link: https://commits.webkit.org/251377@main
Modified Paths
Diff
Modified: trunk/Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm (295368 => 295369)
--- trunk/Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm 2022-06-07 23:57:24 UTC (rev 295368)
+++ trunk/Source/WebKit/UIProcess/mac/WebDateTimePickerMac.mm 2022-06-08 00:26:51 UTC (rev 295369)
@@ -240,13 +240,22 @@
NSString *currentDateValueString = _params.currentValue;
- [_dateFormatter setDateFormat:[self dateFormatStringForType:_params.type]];
+ NSString *format = [self dateFormatStringForType:_params.type];
+ [_dateFormatter setDateFormat:format];
if (![currentDateValueString length])
[_datePicker setDateValue:[self initialDateForEmptyValue]];
- else
- [_datePicker setDateValue:[_dateFormatter dateFromString:currentDateValueString]];
+ else {
+ NSDate *dateValue = [_dateFormatter dateFromString:currentDateValueString];
+ while (!dateValue && (format = [self dateFormatFallbackForFormat:format])) {
+ [_dateFormatter setDateFormat:format];
+ dateValue = [_dateFormatter dateFromString:currentDateValueString];
+ }
+
+ [_datePicker setDateValue:dateValue];
+ }
+
[_datePicker setMinDate:[NSDate dateWithTimeIntervalSince1970:_params.minimum / 1000.0]];
[_datePicker setMaxDate:[NSDate dateWithTimeIntervalSince1970:_params.maximum / 1000.0]];
@@ -289,6 +298,16 @@
return kDateFormatString;
}
+- (NSString *)dateFormatFallbackForFormat:(NSString *)format
+{
+ if ([format isEqualToString:kDateTimeWithMillisecondsFormatString])
+ return kDateTimeWithSecondsFormatString;
+ if ([format isEqualToString:kDateTimeWithSecondsFormatString])
+ return kDateTimeFormatString;
+
+ return nil;
+}
+
- (NSDate *)initialDateForEmptyValue
{
NSDate *now = [NSDate date];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes