-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
#8728: Upgrade/datetimefield format #8729
#8728: Upgrade/datetimefield format #8729
Conversation
2 tests failed but when I tried to rerun them locally I got no problem. Also, since the tests that failed don't have nothing to do with the files I worked on I guess there was some problem running the test, probably some connection issues. Here is the code for the two tests that are failing:
|
Indeed, the test failures were caused by the domain being unreachable, I've fixed the test since then. Please merge from 1.10.x. |
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.
If you agree with the suggestions, please be sure to commit them from the UI in bulk (= one commit), so that the corresponding conversation is also resolved, then proceed with follow-up changes (due to property name changes), if necessary.
@@ -1,7 +1,9 @@ | |||
using System; | |||
using System.Runtime.InteropServices.WindowsRuntime; |
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.
using System.Runtime.InteropServices.WindowsRuntime; |
using Orchard.ContentManagement; | ||
using Orchard.ContentManagement.FieldStorage; | ||
using Orchard.Fields.Settings; | ||
using Orchard.UI.Notify; |
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.
using Orchard.UI.Notify; |
@@ -10,15 +12,15 @@ public DateTime DateTime { | |||
get { | |||
var settings = this.PartFieldDefinition.Settings.GetModel<DateTimeFieldSettings>(); |
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.
var settings = this.PartFieldDefinition.Settings.GetModel<DateTimeFieldSettings>(); |
@@ -10,15 +12,15 @@ public DateTime DateTime { | |||
get { | |||
var settings = this.PartFieldDefinition.Settings.GetModel<DateTimeFieldSettings>(); | |||
var value = Storage.Get<DateTime>(); | |||
if (settings.Display == DateTimeFieldDisplays.DateOnly) { | |||
if (Display == DateTimeFieldDisplays.DateOnly) { | |||
return new DateTime(value.Year, value.Month, value.Day); | |||
} | |||
return value; | |||
} | |||
|
|||
set { | |||
var settings = this.PartFieldDefinition.Settings.GetModel<DateTimeFieldSettings>(); |
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.
var settings = this.PartFieldDefinition.Settings.GetModel<DateTimeFieldSettings>(); |
Editor = new DateTimeEditor() { | ||
Date = showDate ? DateLocalizationServices.ConvertToLocalizedDateString(value, options) : null, | ||
Time = showTime ? DateLocalizationServices.ConvertToLocalizedTimeString(value, options) : null, | ||
ShowDate = showDate, | ||
ShowTime = showTime, | ||
} | ||
} |
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.
} | |
} |
@@ -42,6 +42,7 @@ public override IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPart | |||
builder.WithSetting("DateTimeFieldSettings.Required", model.Required.ToString(CultureInfo.InvariantCulture)); | |||
model.DefaultValue = model.Editor == null ? model.DefaultValue : _dateLocalizationServices.ConvertFromLocalizedString(model.Editor.Date, model.Editor.Time); | |||
builder.WithSetting("DateTimeFieldSettings.DefaultValue", model.DefaultValue.HasValue ? model.DefaultValue.Value.ToString(CultureInfo.InvariantCulture) : String.Empty); | |||
builder.WithSetting("DateTimeFieldSettings.AllowDisplayOptionsOverride", model.AllowDisplayOptionsOverride.ToString(CultureInfo.InvariantCulture)); |
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.
builder.WithSetting("DateTimeFieldSettings.AllowDisplayOptionsOverride", model.AllowDisplayOptionsOverride.ToString(CultureInfo.InvariantCulture)); | |
builder.WithSetting("DateTimeFieldSettings.AllowDisplayOptionOverride", model.AllowDisplayOptionsOverride.ToString(CultureInfo.InvariantCulture)); |
|
||
<fieldset> | ||
<label for="@Html.FieldIdFor(m => Model.Editor.Date)" @if (Model.IsRequired) { <text> class="required" </text> }>@Model.Name</label> | ||
@Html.EditorFor(m => m.Editor) | ||
@if (Model.AllowDisplayOptionsOverride) { |
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.
@if (Model.AllowDisplayOptionsOverride) { | |
@if (Model.AllowDisplayOptionOverride) { |
get { | ||
return Storage.Get<string>("DisplayOption"); | ||
} | ||
set { | ||
Storage.Set("DisplayOption", value ?? String.Empty); | ||
} |
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.
get { | |
return Storage.Get<string>("DisplayOption"); | |
} | |
set { | |
Storage.Set("DisplayOption", value ?? String.Empty); | |
} | |
get => Storage.Get<string>("DisplayOption"); | |
set => Storage.Set("DisplayOption", value ?? string.Empty); |
set { | ||
DisplayOption = value.ToString(); | ||
} |
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.
set { | |
DisplayOption = value.ToString(); | |
} | |
set => DisplayOption = value.ToString(); |
if (settings.AllowDisplayOptionsOverride) { | ||
if (Enum.TryParse(DisplayOption, out DateTimeFieldDisplays displayOption)){ | ||
return displayOption; | ||
} | ||
} | ||
return settings.Display; |
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.
if (settings.AllowDisplayOptionsOverride) { | |
if (Enum.TryParse(DisplayOption, out DateTimeFieldDisplays displayOption)){ | |
return displayOption; | |
} | |
} | |
return settings.Display; | |
return settings.AllowDisplayOptionOverride && Enum.TryParse(DisplayOption, out DateTimeFieldDisplays displayOption) | |
? displayOption | |
: settings.Display; |
Fixes #8728
Added the AllowDisplayOptionsOverride property in DateTimeFieldSetting.
Handled this setting in DateTimeField so that it returns the overriding value (if set) or (if there's no overriding value set) the setting value.
Handles a new case in in DefaultDateLocalizationServices.cs: when converting a DateTime to and from UTC with the IgnoreDate setting, if the DateTime had a valid Date (!= DateTime.min) the code was returning a wrong value since it didn't handle the solar time correctly.
Probably this case wasn't handled correctly since DateTimeFields were only allowing the user to insert the time when their Display property was set to TimeOnly, but we decided to show both the Date and Time editors when the AllowDisplayOptionsOverride is set to true so now it's possibile to have to convert DateTime with a valid date and the IgnoreDate option set to true.