A Potential Challenge in SharePoint 2013 Calendar

I’ve recently been working on a project for an intranet site using SharePoint 2013 Calendar on-Premises and encountered an issue when displaying an all-day event in search results. It actually shows as one day earlier. This only happens to an event item when the “All Day” flag is enabled.

In our case scenario, a Search Result Web Part is configured to query against an Event Calendar list and display content in a customized display template for branding purposes. We created an all-day event for December 25 but it actually showed up on December 24 which begun at 8 pm in our customized display template! I checked on the data from this list, and the start time for this event (December 25 at 12:00 am) was correct(see caption 2). Why is an all-day event not rendered properly and where is this offset coming from?

Image explaining the problem with calendar in SharePoint. Events are showing wrong start date.

A bit of our background here: our SharePoint server has been configured its default time zone to EST (Eastern Standard Time). This applies to the default time zone at the top-level web application as well as an individual site collection and user.

Causes

When you create a new calendar event item, SharePoint server 2013 stores raw date values into the SQL database using the Coordinated Universal Time (UTC) regardless of what time zone is configured for the current user. This SharePoint event will then be shared across time zone and adjusted to the time local as has been configured in SharePoint Settings.

In our case, we configured refiners for our search results and the event’s start time is being mapped to a managed property, RefinableDate00. RefinableDate00 is of a DateTime data type that includes the Event Start Time to the index for a more refined search results experience. What happened is that the date value that is returned to this managed property is not being offset by the SharePoint server. It returned the time value in UTC which is 4 hours earlier than the user’s time zone (EST) (or 5 hours earlier during the Daylight Saving Time).

Resolution

To resolve this issue, we first checked the “All Day” event flag is checked for an event. Then, we applied a JavaScript method, getUTCDate() on the start date for that event and returns the day of the month according to the universal time in this format ‘yyyy-mm-dd hh:mi:ss.mmm’.

var eventDate = New Date(ctx.CurrentItem.RefinableDate00)

where the start date of an event is mapped to RefinableDate00

Conversely, you can use a method such as getUTCHours() to get the hour in local time offset from UTC/GMT.

Reference materials

TechNet Blogs – All Day Events and GMT

Microsoft Development Network – Choosing Between DateTime, DateTimeOffset, TimeSpan, and TimeZoneInfo