Off By One Hour
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:
<setting name="ServerTimeZone" set:value="GMT Standard Time"/>
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:
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.