Published on

Timezone conversion from Sitefinity OData Event API Service


So this all came about with the ask for showing a kendoTooltip popup when hovering on an event in the scheduler. The issue with showing the data is that none of the data you want to show comes across in the default endpoint. It’s basically the title and dates, enough for the item to render… and as it should be, you want it fast and lean.

The rest of the data can be pulled (quickly) from the OData endpoint at /api/default/events

//Something like this
var itemdefaulturl = item.find(".event-item").data("itemdefaulturl");
var route = "/api/default/events?$filter=ItemDefaultUrl eq '" + itemdefaulturl.replace("'", "%27%27") + "'";

Note the replace as single quotes in a urlname (thanks for not filtering those out on create btw Sitefinity…) will break the querystring.

Anywho, the date format from the native endpoint is WCF, and it’s an ISO string from the OData endpoint.

So here’s how you can convert that to actually use it properly without going insane

var eventStartDate = new Date(data.EventStartWithOffset);
eventStartDate.setMinutes(eventStartDate.getMinutes() + eventStartDate.getTimezoneOffset());

var dateString = kendo.toString(eventStartDate, "MM/dd/yyyy h:mm tt")); //Let kendo convert it to readable for you

Boost your online presence.

Let us create the perfect digital experience for your company.

Contact us now