OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.37k stars 1.12k forks source link

#8728: Upgrade/datetimefield format #8729

Open AgostiniAlessandro opened 8 months ago

AgostiniAlessandro commented 8 months ago

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.

AgostiniAlessandro commented 8 months ago

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:

    [Test]
    public void StatusCodeShouldBe404ForUnexistingResources() {
        var download = _webDownloader.Download("http://orchardproject.net/yepyep");
        Assert.That(download, Is.Not.Null);
        Assert.That(download.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
        Assert.That(download.Content, Is.Null);
    }

    [Test]
    public void StatusCodeShouldBe200ForValidRequests() {
        var download = _webDownloader.Download("http://orchardproject.net/");
        Assert.That(download, Is.Not.Null);
        Assert.That(download.StatusCode, Is.EqualTo(HttpStatusCode.OK));
        Assert.That(download.Content, Is.Not.Empty);
    }