0

I have a site (.Net) using Daypilot pro (7.9) and ajaxtoolkit:CalendarExtender. It is used to book dates in Dynamics and it works like a charm UNTIL i choose a date in 2016... When i choose a date or weeknumber in the year 2016 the calendar jumps back to the week before the chosen week. I'm using swedish format and the only clue i have is that 2015 have 53 weeks and daypilot may get confused by this?

Here is the code (The date time picker comes from ajaxtoolkit)

<div id="divCalendar" runat="server" style="float: left; width: 90px; height:25px; margin-top: 2px;">
    <ajaxToolKit:CalendarExtender ID="calendar" runat="server" TargetControlID="dateTimeTextBox"
        Format="yyyy-MM-dd" PopupButtonID="popupButton" firstDayOfWeek="Monday" />
    <asp:TextBox ID="dateTimeTextBox" runat="server" CssClass="inputfields" Width="80px" AutoPostBack="true"
        OnTextChanged="DateTime_Changed" />
    <asp:CompareValidator ID="dateTimeTextBoxFormat" runat="server" ControlToValidate="dateTimeTextBox"
        Operator="DataTypeCheck" Type="Date" ErrorMessage="yyyy-mm-dd." Display="Dynamic"
        ValidationGroup="DateTime" />
    <asp:RequiredFieldValidator ID="dateTimeTextBoxRequired" runat="server" ControlToValidate="dateTimeTextBox"
        ErrorMessage="*" Display="Dynamic" ValidationGroup="DateTime" />
</div>
<div id="divCalendarButton" runat="server" style="float: left; width: 39px; margin-right: 12px;">
    <asp:Image ID="popupButton" runat="server" ImageUrl="/_imgs/btn_on_cal.gif" Style="cursor: pointer; height: 25px; padding-top: 3px;" />
</div>
<div id="divTime" runat="server" style="margin-left: 7px; padding-top: 3px;">
    <asp:DropDownList ID="dropDownHours" runat="server" AutoPostBack="true" />
    <asp:DropDownList ID="dropDownMinutes" runat="server" AutoPostBack="true" />
</div>

And here's the DayPilot part:

<div style="float: left; padding: 5px;">

<DayPilot:DayPilotCalendar ID="dayPilotCalendar" runat="server" DataStartField="Start"
    DataEndField="End"  DataTextField="Name" DataValueField="Id" DataTagFields="ActivityTypeName, ColorCode, Status"
    BusinessBeginsHour="8" BusinessEndsHour="18" CellDuration="15" CellHeight="13"
    HeightSpec="BusinessHours" ShowAllDayEvents="true" AllDayEnd="Date" ShowAllDayEventStartEnd="false"
    EventClickHandling="JavaScript" EventClickJavaScript="viewEvent(e);" EventDoubleClickHandling="JavaScript"
    EventDoubleClickJavaScript="editEvent(e);" DataAllDayField="WholeDayActivity"
    TimeRangeSelectedHandling="JavaScript" TimeRangeSelectedJavaScript="createEvent(start, end, resource);"
     TimeRangeDoubleClickHandling="JavaScript" TimeRangeDoubleClickJavaScript="createEvent(start, end, resource);"
    ContextMenuID="DayPilotMenuActivity" OnBeforeEventRender="OnBeforeEventRender"
    BubbleID="ActivityCalendarBubble" ShowToolTip="false">
</DayPilot:DayPilotCalendar>

I hope someone can help me find a solution for this. The customer is getting irritated that they have to choose the week after the one they want to open in the calendar =P

Mukklan
  • 1
  • 4
  • Have you checked the date that you assing to DayPilotCalendar.StartDate to change the view? Is it correct? – Dan Oct 07 '15 at 14:35

1 Answers1

0

Thx Dan, that was where the problem was. I got help from a hero on the office to help me put the right date to the.StartDate!

We changed from this:

public static DateTime GetDateFromWeekNumber(int year, int weekNumber)
    {
        DateTime date = new DateTime(year, 1, 1);
        date = date.AddDays(7 * (weekNumber - 1));
        date = date.AddDays(-(int)date.DayOfWeek + 1);

        return date;
    }

To this:

public static DateTime GetFirstDayOfWeek(DateTime dayInWeek)
    {
        CultureInfo cultureInfo = CultureInfo.CurrentCulture;

        DayOfWeek firstDay = cultureInfo.DateTimeFormat.FirstDayOfWeek;
        DateTime firstDayInWeek = dayInWeek.Date;
        while (firstDayInWeek.DayOfWeek != firstDay)
            firstDayInWeek = firstDayInWeek.AddDays(-1);

        return firstDayInWeek;
    }

And now it works as a charm! Wasn't Daypilot, just old Code =D

Mukklan
  • 1
  • 4