[su_note note_color=”#fafafa”]Sitecore 8 added timezone support to all dates. Make sure you read this section of the documentation if you are not familiar.[/su_note]
We were mostly careful with our dates and put our Sitecore into GMT Standard Time from the very beginning to avoid converting things back and forth:
&lt;setting name="ServerTimeZone" set:value="GMT Standard Time"/&gt;
Turns out – and it’s equally important, silly, and frustrating – GMT Standard Time is not Greenwich Standard Time. The former observes daylight saving, the latter does not and both are referred to as GMT. Here’s a good thread on stackoverflow.
Sitecore documentation mentions GMT Standard Time as an example for your
ServerTimeZone and we just went with it. We should have used UTC instead.
Off By One Hour
Here’s how the problem manifests itself. We have an item representing an Event. It has a date:
Choosing a Global Software Development Partner to Accelerate Your Digital Strategy
To be successful and outpace the competition, you need a software development partner that excels in exactly the type of digital projects you are now faced with accelerating, and in the most cost effective and optimized way possible.
A razor view that does an equivalent of:
All good, right? Both dates are in server time right now. Both – the control in content editor and the
renderField pipeline will send the date through
In the database, however, the date is stored like this:
It’s stored in UTC and right now GMT Standard Time is on daylight saving time:
Does It Matter?
It wouldn’t matter if we weren’t sending the date field to another channel via a JSON feed or if our dates weren’t at 00:00:00. Right now some users experience 10/24 and the others see 10/23 – off by one hour became off by one day.
The JSON feed was given a date using an equivalent of:
((DateField) item.Fields["Effective Date"]).DateTime
- A date field sent through
renderFieldpipeline will be in server time
- A date displayed by the Content Editor date control will be in server time
DateTimefield value will be in UTC
- Date fields in the search index are also in UTC unless you computed them differently
And our biggest oversight was the assumption about GMT Standard Time. Never. Assume. Anything.