1
Vote

Huge issue with time-only DateTimeField and DST

description

Hi,

I have an huge issue with time-only DateTimeField in a productive site running Orchard 1.9.x.

The issue is that time-only fields are always stored as UTC (converted from CurrenetTimeZone at moment of saving/publishing a content item) time but rendered as local time (at the moment of displaying the content item) and this depends if DST is active for moment of creation and/or displaying the field.

First for clarification:
Central European Summer Time (CEST) = Central European Daylight Saving Time (CEDT= CET DST). CEDT = UTC + 2.
Central Summer Time (CEST) = Central European Daylight Saving Time (CEDT= CET DST). CET = UTC + 1.



Example:
At my Event content type, I have one date-only field for the date and one time-only field for the time. I took this approach since it should be possible for an event to have no time.
Regard the following 4 cases all dealing with creation of a time for a CET date - they differ only in creation date (whether CET or CEDT) and display date (whether CET or CEDT)

Case 1: On November 2015 (CET) create an event with a date for May 2016 (CEDT). Set the time-only field to 10:00 a.m. Since creation is while CET it is stored as 09:00 a.m. (UTC=CET-1).
Case 1a: Look at the item while CET, e. g. January 2016: time is displayed correctly, since CET = UTC+1 ==> 10:00 a.m.
Case 1b: Look at the item while CEDT, e. g. May 2016: time is displayed incorrectly, since CEDT = UTC+2 ==> 11:00 a.m.

Case 2: On April 2016 (CEDT) create an event with a date for May 2016 (CEDT). Set the time-only field to 10:00 a.m. Since creation is while CEDT it is stored as 08:00 a.m. (UTC=CEDT-2).
Case 2a: Look at the item while CEDT, e. g. May 2016: time is displayed correctly, since CEDT = UTC+2 ==> 10:00 a.m.
Case 2b: Look at the item while CET, e. g. January 2017: time is displayed incorrectly, since CET = UTC+1 ==> 09:00 a.m.

I took a look at the implementation in DefaultDateLocalizationService:ConvertFromLocalizedString and DateTimeFieldDriver:Display/Editor.
I think to fix the issue we need to add "options.EnableTimeZoneConversion = false;" for time-only fields in the DateTimeFieldDriver:Display and in the DateTimeFieldDriver:Editor methods.

Totally there are two occurences where I applied added here disabling the time zone conversion:
if (settings.Display == DateTimeFieldDisplays.TimeOnly) {
                options.EnableCalendarConversion = false;
                options.EnableTimeZoneConversion = false;
                options.IgnoreDate = true
}


Please give me feedback if this is a suitable fix or if there is any better way to fix it.

I am not sure yet how to fix > hundred time entries for given events. I cannot automatically fix them depending of the four cases because creation date is unchanged when duplicating an item, so I do not when exactly the user entered the date, so I do not know whether I have to go 0, 1 or 2 hours back...any ideas here?
I guess I have to inform all event owners to verify their times after having fixed that.

Thanks,
Dieter

comments