More in this section

Forums / Developing with Sitefinity / Sitefinity Event Module TimeZone Confusion

Sitefinity Event Module TimeZone Confusion

2 posts, 0 answered
  1. Mark
    Mark avatar
    147 posts
    01 Jun 2010
    01 Mar 2013
    Link to this post

    I'm hoping someone here can help me out because I'm completely at a loss as to how to get event times to show up correctly.

    My server is located in the Central Time Zone. I have customers that are using the same assembly in a few different time zones across the United States. I am having trouble wrapping my head around the time zone conversions and would appreciate some help. 

    I have a front end widget that allows users to submit events using RadDateTimePickers. This same widget allows administrators to modify events. I have another widget that displays event information. It works great in the Central Time Zone, but does not work in other time zones.

    Create event setup:
    dtEventBegin.SelectedDate = DateTime.UtcNow.ToSitefinityUITime().RoundQuarterHour();
    dtEventEnd.SelectedDate = DateTime.UtcNow.ToSitefinityUITime().RoundQuarterHour().AddHours(1);

    Create event save:
    calEvent.EventStart = dtEventBegin.SelectedDate.Value.ToUniversalTime();
    calEvent.EventEnd = dtEventEnd.SelectedDate.Value.ToUniversalTime();

    Modify event setup:
    dtEventBegin.SelectedDate = eventTemplate.EventStart.ToSitefinityUITime();
    dtEventEnd.SelectedDate = eventTemplate.EventEnd.HasValue ? eventTemplate.EventEnd.Value.ToSitefinityUITime() : eventTemplate.EventStart.AddHours(1.0).ToSitefinityUITime();

    Modify event save:
    ev.EventStart = eventCreatorCtl.dtEventBegin.SelectedDate.HasValue ?
                                                       eventCreatorCtl.dtEventBegin.SelectedDate.Value.ToUniversalTime() :
    ev.EventEnd = eventCreatorCtl.dtEventEnd.SelectedDate.HasValue ?
                                                       eventCreatorCtl.dtEventEnd.SelectedDate.Value.ToUniversalTime() :

    Display event time on detail page:
    DateTime startDT = calendarEvent.EventStart.ToSitefinityUITime();
    DateTime endDT = calendarEvent.EventEnd.HasValue ? calendarEvent.EventEnd.Value.ToSitefinityUITime() : calendarEvent.EventStart.ToSitefinityUITime();
    date.AppendLine("<div>" + startDT.ToString("h:mm tt") + " to " + endDT.ToString("h:mm tt") + "</div>");

    Releated time conversion
    public static DateTime RoundQuarterHour(this DateTime dateTime)
                return new DateTime(dateTime.Year, dateTime.Month,
                     dateTime.Day, dateTime.Hour, (dateTime.Minute / 30) * 30, 0);

  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    28 Aug 2017
    04 Mar 2013
    Link to this post
    Hi Mark,

    We have addressed the matter in the support ticket you have open on the same issue. You can check our response there, and for your convenience please find below a quote of the response, too:
    "Thank you for contacting Telerik Support.

    Let me elaborate a bit on how the EventDates are persisted in the database and what the extension method ToSitefinityUITime() does.

    By default Sitefintiy Events (when creating an Event using the backend Create Event functionality) module will persist the dates converted to UTC time format. When creating them through API the value you're passing will be the value you've set for the EventStart and EventEnd properties of the item.

    Calling ToSitefinityUITime() on a retrieved Event item would do the following:
    If there is a time zone configured for this particular site (From Adminsitration->Settings) the date will be converted to that time zone
    If no time zone has been explicitly configured, then we'll be using TimeZoneInfo.Local for resolving the correct timezone and consecutively the event dates.

    In other words when persisting the event dates yourself you can take care of persisting them in UTC format, and then, when displaying them to the user, use the ToSitefinityUITime() to resolve the date for the specified site time zone.

    For your convenience I've tried wrapping up the above in a short demonstrative video, hope you find it useful"

    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered