This project is read-only.


Date Time Field Saving and Retrieving Different Results


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.
Closed Jul 7, 2013 at 12:56 AM by sebastienros


manudea wrote Nov 30, 2012 at 11:27 PM

Same problem...
    @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?

Jetski5822 wrote Jun 7, 2013 at 11:19 PM

I cannot seem to replicate. What I did...
  1. Add a DateTime Field to the "Page" Content Type called "Birthday"
  2. Create a new "Page" with a datetime of "6/12/2013" and "7:15 am"
  3. I published that content
  4. I left the page and the summary and detail views showed the correct values.
  5. I went back to said content and it was the correct value.
Please could you check on the latest 1.x branch.

jao28 wrote Jun 12, 2013 at 8:39 PM

I have gone ahead and pulled the latest dev branch and it works good on localhost. I have not deployed it to the server yet but I would like to paint the scenario better for above.
  • The server I host on is three time zones away
  • If I set the "Default Time Zone" to my actual time zone the time I enter will not be the time displayed
  • If I set the "Default Time Zone" to the time zone of the server the time I enter will not be the time displayed
  • If I set the "Default Time Zone" to "(UTC) Coordinated Universal Time" then the time I enter WILL be the time displayed
I would expect the "Default Time Zone" to be either my local time or at least the local time of the server. I have not tested the latest 1.x branch yet on a server outside my time zone to see what happens. If you have any further insights into what I am seeing it is appreciated.