2
Vote

Date Time Field Saving and Retrieving Different Results

description

There are two issues here, 1 which has a fix and the other I don't know how to fix.

When I use the Orchard Date Time field it can be added but then the field does not re-appear for that content type. I have isolated this (to what I believe) is the error in that since 1.6 the field.DateTime Kind is stored as DateTimeKind of Local. This causes an error on Displaying (or editing again) because it cannot use "ConvertTimeFromUtc" with a DateTimeKind of Local. Here is some code that takes care of the issue (not sure if it is the best fix though):

value = DateTime.SpecifyKind(value, DateTimeKind.Unspecified);

On to the second issue. I cannot understand why when I enter a date/time it is returned on display in a different date/time. I have stepped through the code for over two hours and all I know is that I don't understand how TimeZoneInfo.ConvertTimeFromUtc and TimeZoneInfo.ConvertTimeToUtc work / were intended to work here in Orchard. The concept seems great, the user enters a time in the field and it gets converted to UTC. Then, when retrieved, it gets converted back from UTC. However, what I enter in is not what I get back. I have messed around with the default time zone settings in the main settings area and that simply causes the time to shift one way or the other, doesn't actually fix the problem.

comments

manudea wrote Nov 30, 2012 at 10:27 PM

Same problem...
using:
    @Html.LabelFor(m => m.BirthDate)
    @Html.EditorFor(m => m.BirthDate)
date is correclty saved on db, but incorrectly loaded causing revert to default...
How can I specify Kind as suggested in my view or in EditorFor?