-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Auto-select type="text"
for DateTimeOffset
values
#6758
Conversation
/cc @Eilon, @DamianEdwards for 2.0.x patch consideration. This fix breaks one of the workarounds I described in #6648 (here in particular) but only if a developer uses the |
Working on failures. A few expected strings are obviously set for my locale |
@@ -347,10 +346,10 @@ public static IHtmlContent EmailAddressInputTemplate(IHtmlHelper htmlHelper) | |||
return GenerateTextBox(htmlHelper, inputType: "email"); | |||
} | |||
|
|||
public static IHtmlContent DateTimeInputTemplate(IHtmlHelper htmlHelper) | |||
public static IHtmlContent DateTimeOffsetTemplate(IHtmlHelper htmlHelper) |
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.
FYI the DateTimeInputTemplate(...)
method was un-referenced.
{ | ||
// Auto-select a format that round-trips Offset and sub-Second values in a DateTimeOffset. Not | ||
// done if user chose the "text" type in .cshtml file or with data annotations i.e. when | ||
// inputTypeHint==null or "text". |
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.
Avoiding auto-selection of the RFC3339 format if .cshtml file contains <input asp-for="ADateTimeOffset" type="text"/>
is why this block is a bit more complicated.
@@ -457,6 +457,77 @@ public void Process_GeneratesFormattedOutput(string specifiedType, string expect | |||
Assert.Equal(expectedTagName, output.TagName); | |||
} | |||
|
|||
[Theory] | |||
[InlineData("datetime", "datetime")] | |||
[InlineData(null, "datetime-local")] |
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.
FYI this demonstrates the default is still datetime-local
for DateTime
properties.
@@ -786,7 +788,7 @@ public void Editor_InputTypeDateTime_RendersAsDateTime() | |||
hour: 3, | |||
minute: 4, | |||
second: 5, | |||
millisecond: 6, | |||
millisecond: 60, |
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.
FYI I made a few of these changes to make the DateTime
and DateTimeOffset
values consistent.
[InlineData("date", "{0:d}", "2000-01-02", "date")] | ||
[InlineData("datetime", null, "2000-01-02T03:04:05.060", "datetime-local")] | ||
[InlineData("datetime-local", null, "2000-01-02T03:04:05.060", "datetime-local")] | ||
[InlineData("DateTimeOffset", "{0:o}", "2000-01-02T03:04:05.060Z", "text")] |
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.
FYI this demonstrates user can opt into new type
and format combination for DateTime
properties.
DateTime
can round-tripDateTimeKind.UTC
with[DataType("datetimeoffset")]
or[UIHint("datetimeoffset")]
DateTime
testsHtml5DateRenderingMode.CurrentCulture
Make VS-suggested changes to files updated in this PR