This is a migrated thread and some comments may be shown as answers.

kendo date manipulations

1 Answer 44 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jurgen
Top achievements
Rank 1
Jurgen asked on 10 Mar 2020, 09:50 AM

I have implemented a custom scheduler view based on the timeline multi day view. I did this by "forking" from the kendo scheduler source code, as suggested in a support ticket. This works for 95%, but there are issues with events that have start or end dates equal to the min and max dates in the scheduler's date range: the tasks' head and tail properties are not set correctly because they are the result of comparing dates that are off by a few hours (the timezone offset) (`createTasks` function in /src/views/timeline/utils.ts).

So I started debugging and I also digged in the source code. It appears to me that kendo does all kinds of strange Date interpretations. For example, the `toUTCDate` function (located in /src/views/utils.ts):

export function toUTCDate(localDate: Date): Date {
    return new Date(Date.UTC(
        localDate.getFullYear(),
        localDate.getMonth(),
        localDate.getDate()
    ));
}

For a localDate that represents for example '2020-03-09T00:00:00+0100', you cannot simple take the full year (2020), month (02) and date (09) parts and treat them as if they were utc (which is what Date.UTC does: It returns the number of milliseconds since January 1, 1970, 00:00:00 UTC).

The result of

new Date(Date.UTC(2020, 2, 9))

is actually '2020-03-09T00:01:00+0100' (which is the same instant as '2020-03-09T00:00:00Z' but is not the same instant the original localDate). This is utterly confusing. Why is this?

 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 12 Mar 2020, 09:45 AM

Hi Jurgen,

Thank you for the provided feedback.

Indeed the UTC dates are used in order to avoid any calculation errors caused by the DST account settings on the browser.

Let me know if any further assistance is required.

Regards,
Martin
Progress Telerik

Get quickly onboarded and successful with your Telerik and Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
General Discussions
Asked by
Jurgen
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or