Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Auto-select type="text" for DateTimeOffset values #6758

Closed
wants to merge 3 commits into from

Conversation

dougbu
Copy link
Member

@dougbu dougbu commented Sep 3, 2017


Make VS-suggested changes to files updated in this PR

- #6648
- a different take on #4871
- `DateTime` can round-trip `DateTimeKind.UTC` with `[DataType("datetimeoffset")]` or `[UIHint("datetimeoffset")]`
- since they're now handled differently by default, add more `DateTime` tests
- expand tests involving `Html5DateRenderingMode.CurrentCulture`
@dougbu
Copy link
Member Author

dougbu commented Sep 3, 2017

/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 <input asp-for="ADateTimeOffset"/><select ...>...</select> approach and relies on auto-selection. In that case, adding type="datetime-offset" to the tag helper, adding [DataType("datetime-local")] to the property, or other kill-the-auto-select changes restore the browser's wizard.

@dougbu
Copy link
Member Author

dougbu commented Sep 3, 2017

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)
Copy link
Member Author

@dougbu dougbu Sep 3, 2017

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".
Copy link
Member Author

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")]
Copy link
Member Author

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,
Copy link
Member Author

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")]
Copy link
Member Author

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.

@dougbu
Copy link
Member Author

dougbu commented Sep 5, 2017

7e4a8fe
(thanks @pranavkm)

@dougbu dougbu closed this Sep 5, 2017
@dougbu dougbu deleted the dougbu/keep.offset.6648 branch September 5, 2017 23:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants