Scheduler/ParseDate - Developer timezone specific?

0 Answers 18 Views
Scheduler
Kevin
Top achievements
Rank 2
Iron
Iron
Iron
Kevin asked on 28 Jun 2022, 02:47 PM

Hi,

I'm not sure if the issue I have is related to kendo ui, but seeing an issue where code I run on my local computer on central time works fine, but when I deploy to the server (eastern time), some of my dates are shifting in the Scheduler control when I iterate through it.

I'm using the kendo.parseDate function on start/end dates

return kendo.parseDate(kendo.toString(input, 'd')).toLocaleDateString("en-US");

That works fine locally, but deployed to the server shifts an hour, which then saves the wrong date in my database.

Is there a timezone saved anywhere in the configs for developer machine that might be getting pushed to server?  Switching my computer timezone to eastern and then deploying seems to work fine.


Thanks

Veselin Tsvetanov
Telerik team
commented on 01 Jul 2022, 08:42 AM

Hi Kevin,

May I ask you to provide a bit more details on how dates are saved on your server and what do you use the kendo.parseDate() for? Normally, date shift is usually present when saving dates to the db in the local timezone. The recommended approach would be to always keep dates in UTC, so that they could either:

a. Receive the required shift based on the configured timezone in the Scheduler; or when no timezone is set

b. Receive the required shift based on the timezone configured on the client viewing the Scheduler.

In order to guarantee all values are saved in UTC, normally you should specify that in the model parsing on the server. Here is how that would be done in ASP.NET Core:

https://demos.telerik.com/aspnet-core/scheduler/basic-usage

Under "View source" check the TaskViewModel.cs class:

       public DateTime Start
        {
            get
            {
                return start;
            }
            set
            {
                start = value.ToUniversalTime();
            }
        }

You should also guarantee those dates are interpreted as UTC upon read. In the TaskSetvice.cs implementation:

result = db.Tasks.ToList().Select(task => new TaskViewModel
                    {
                        TaskID = task.TaskID,
                        Title = task.Title,
                        Start = DateTime.SpecifyKind(task.Start, DateTimeKind.Utc),
                        End = DateTime.SpecifyKind(task.End, DateTimeKind.Utc),
                        StartTimezone = task.StartTimezone,
                        EndTimezone = task.EndTimezone,
                        Description = task.Description,
                        IsAllDay = task.IsAllDay,
                        RecurrenceRule = task.RecurrenceRule,
                        RecurrenceException = task.RecurrenceException,
                        RecurrenceID = task.RecurrenceID,
                        OwnerID = task.OwnerID
                    }).ToList();

Here is some more infor on how timezones work in Scheduler:

No answers yet. Maybe you can help?

Tags
Scheduler
Asked by
Kevin
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or