Question

I created a calendar event with all day selected (10/24/2013) . Then i tried to pull the e.EventStart and e.EventEnd. My expected result was EventStart =10/24/2013 12.00.00 am and

EventEnd= 10/25/2013 12.00.00 am. But what am getting is EventStart =10/24/2013 12.00.00 am and EventEnd= 10/24/2013 12.00.00 am.

The same works fine when I try with e.EventStartUtc and e.EventEndUtc. But I dont want the utc format as I am trying to pull out the ektron time for the users.

Was it helpful?

Solution

If you use the Framework API, the WebEventData class has a property called IsAllDay. You could use this to trigger the display change. For example, you might not want to display start/end times at all if it's an All Day event and just show the date.

If you do need to have particular start/end times for all day events, you can easily extend the Ektron WebEventData object with extension methods.

public static class WebEventExtensions
{
    public static DateTime GetDisplayStartDate(this WebEventData webEvent)
    {
        if (!webEvent.IsAllDay)
            return webEvent.EventStart;

        return new DateTime(webEvent.EventStart.Year, webEvent.EventStart.Month, webEvent.EventStart.Day);
    }

    public static DateTime GetDisplayEndDate(this WebEventData webEvent)
    {
        if (!webEvent.IsAllDay)
            return webEvent.EventEnd;

        return new DateTime(webEvent.EventEnd.Year, webEvent.EventEnd.Month, webEvent.EventEnd.Day, 23, 59, 59);
    }
}

Then those methods will appear on the object.

var eventManager = new WebEventManager();
WebEventData webEvent = eventManager.GetItem(730);
if (webEvent.IsAllDay)
{
    // do all-day stuff...
}

var start = webEvent.GetDisplayStartDate();
var end = webEvent.GetDisplayEndDate();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top