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

scheduler start date : utc date conversion

5 Answers 466 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
peter
Top achievements
Rank 1
peter asked on 11 Aug 2019, 05:39 PM

In scheduler control, I can create a date like Aug 11 8am.
The view model saves the date as UTC :  start = new DateTime(value.Ticks, DateTimeKind.Utc);  
On the Server , I see a -7 hour offset , like Aug 11 1am.
----------------------------------------------------------------------
This wiki says "SchedulerEvent instances are created, where start/end dates are instantiated as JavaScript Date objects. During the process the dates will be offset against the local time."

https://docs.telerik.com/kendo-ui/controls/scheduling/scheduler/timezones

When I load the data back into the  scheduer , it shows the 1am date. Why doesn't the scheduler add my 7 hour offset and show  8am ? Do i need to add kendo.stringify ?

Thanks,Peter

5 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 14 Aug 2019, 03:11 PM
Hello Peter,

I reviewed a previous support ticket regarding this subject answered by my colleague Veselin. As he says, the Scheduler renders its events according to the client timezone. In addition to his suggestion to remove the  .Timezone("Etc/UTC") configuration, you will also need to set value.ToUniversalTime() to both start and end properties setters:
public DateTime Start
{
    get
    {
        return start;
    }
    set
    {
        start = value.ToUniversalTime();
    }
}
 
public DateTime End
{
    get
    {
        return end;
    }
    set
    {
        end = value.ToUniversalTime();
    }
}

Now the dates on the server should be always saved as UTC dates.

I hope I was helpful. Do not hesitate to ask if you have further questions.

Regards,
Martin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
peter
Top achievements
Rank 1
answered on 15 Aug 2019, 12:49 PM

Thanks Martin, That fixed my UTC issue !

I will close ticket  1425046

Regards, Peter

0
peter
Top achievements
Rank 1
answered on 18 Aug 2019, 11:29 PM

Martin, 

Can i please reopen ticket   1422110 or 1425046 ?I still have a UTC problem.
The issue is with the grid .Everything  works in locally Visual studio (iis express).

But when i publish to azure, it wrongly converts the date when saving in the grid . Do i need a OnSave javascript in the grid ?

Reproduce the error in azure : 
Step 1. grid loads with correct date time 8:30am  (see grid ok picture)
Step 2 : Write to database. Value in database is wrong     "Start": "2019-08-19T08:30:00Z"   - should be "2019-08-15T15:30:00Z",

this is my grid cshtml : 

@{
    ViewData["Title"] = "Approve";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
 
<h1>Approve Reservations</h1>
 
  
 
@(Html.Kendo().Grid<SkyApp.Models.CosmosDB.ScheduleViewModel>
    ()
    .Name("grid")
 
    .Columns(columns =>
    {
        columns.Bound(c => c.Title);
        columns.Bound(c => c.Start);
        columns.Bound(c => c.Status).Title("Approved");
        columns.Command(command => { command.Edit(); command.Destroy(); });
 
    })
 
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
         
        .Events(events => events
            .Error("error_handler")
 
        )
 
 
 
        .Model(model => {
            model.Id(p => p.Id);
            model.Field(p => p.Title).Editable(false);
            model.Field(p => p.Start).Editable(false);
        })
 
 
        .Read(read => read.Action("ReadPendingEvent", "Crud"))
        .Update(update => update.Action("UpdateEvent", "Crud"))
        .Destroy(destroy => destroy.Action("DestroyEvent", "Crud")
 
    ))
0
peter
Top achievements
Rank 1
answered on 19 Aug 2019, 12:33 PM

i am confused why this happens in Azure, but not in Visual Studio - is IIS express  different that  IIS ?

i tried to add a OnSave Function that Veselin gave me earlier , but it doesn't seem to work . 

<script type="text/javascript">
 
    function onSave(e) {
        var model = e.model;
        var date = model.Start;
        var offsetMiliseconds = date.getTimezoneOffset() * 60000;
        var newDate = new Date(date.getTime() + offsetMiliseconds);
        model.set('Start', newDate);
        var one = 1;
}

 

 

0
peter
Top achievements
Rank 1
answered on 21 Aug 2019, 12:52 PM
Lets switch to ticket 1425046 . Thanks,Peter
Tags
Scheduler
Asked by
peter
Top achievements
Rank 1
Answers by
Martin
Telerik team
peter
Top achievements
Rank 1
Share this question
or