5

I am using the Kendo scheduler and the timezone offset appears to be adding hours and subtracting hours in the opposite direction from what should happen.

When I change my client timezone to a more western timezone, hours are added to the event date times and when I change my client browser to a more eastern timezone, hours are subtracted.

So a client in the Pacific timezone should see the start time as 10:00 AM, but instead it is displaying as 4:00PM. Clients set to the Atlantic timezone see the start time as 12:00PM.

Scheduler code:

$("#scheduler").kendoScheduler({
    date: new Date(),
    height: 900,
    editable: false,
    views: [
        {
            type: "month",
            selected: true,
            eventHeight: 50,
            eventTemplate: $("#event-template-month").html(),
        },{
            type: "agenda",
            eventHeight: 50,
            eventTemplate: $("#event-template-sched").html(),
        }
    ],
    timezone: "America/New_York",
    dataSource: webinarSchedule,
});

The event information is held in an array in a local js file and looks like this:

var webinarSchedule = [//Date are in utc -5:00
{
    title: "Part 1 <br/>The Golden Rule",
    shortName: "1) The Golden Rule ",
    presenter: "Bill Preston",
    description: "A great event",
    synopsis: "Learn stuff",
    seriesNote: "The first of a 4-part series.",
    registration: "https://attendee.gotowebinar.com/register/3782113333237861889",
    start: new Date("2015/1/24 1:00 PM"),
    end: new Date("2015/1/24 1:20 PM"),

},
billy jean
  • 1,219
  • 3
  • 21
  • 41

4 Answers4

5

Yeah, that doesn't seem to work right.

I find the only way to keep your sanity when dealing with JS dates (or dates in computing in general) is to use UTC dates, serialized in ISO format (in general, storing UTC dates on the server is also a better idea). So, I'd suggest creating your events using the appropriate ISO string for the source timezone:

{
    title: "Part 1 <br/>The Golden Rule",
    shortName: "1) The Golden Rule ",
    presenter: "Bill Preston",
    description: "A great event",
    synopsis: "Learn stuff",
    seriesNote: "The first of a 4-part series.",
    registration: "https://attendee.gotowebinar.com/register/3782113333237861889",
    start: new Date(Date.parse("2015-02-11T13:00:00-05:00")), 
    end: new Date(Date.parse("2015-02-11T13:20:00-05:00")),
}

then don't set the schedulers timezone option at all (so it uses local). If you need to pass to the server, you may also want to process the dates first using toISOString.

Lars Höppner
  • 17,834
  • 2
  • 41
  • 67
  • https://jsfiddle.net/loanburger/0s3Lcq17/ you'll see the behavior i described in the original question is still apparent in your example. If you switch your local time zone to PST the start time shows as 6:00PM when it should be 10:00AM. I am in EST and would like to have the dates displayed in the correct time according to the client's Time Zone whereever they are. I don't mind entering the times in the js file however needed.. so long as client in EST or PST sees the correct time according to their time zone. In the example EST should display 1:00PM and PST should display as 10:00AM – billy jean Feb 11 '15 at 20:48
  • @billyjean that's broken mate; also: you're using timezone on scheduler, you can leave it out; also:you're not using ISO UTC format – Lars Höppner Feb 11 '15 at 20:59
  • Awesome thanks. Your solution is working. I don't know why my shared fiddle doesn't work. It's working in the tab where i created it. Specifically, removing the timezone: "Etc/UTC" makes yours work. – billy jean Feb 11 '15 at 21:08
  • 1
    it's the HTTPS - the browser won't load the JS files from Telerik's CDN – Lars Höppner Feb 11 '15 at 21:10
  • start: new Date("2015-01-24T13:00:00.000-05:00"), end: new Date("2015-01-24T13:20:00.000-05:00") these work as does new Date(Date.parse("Wed Feb 4 2015 13:00:00 GMT-0500")),. But new Date(Date.parse("2015-02-11T13:00:00-05:00")) doesn't. Thanks again. – billy jean Feb 11 '15 at 21:14
  • Hi Lars, i just checked and it seems that once we get past daylight savings around March 11 the dates are off by 1 hour.. so displayed as 2:00PM instead of 1:00PM. Is there some easy way in the date formatting to accomodate Daylight Savings? – billy jean Feb 11 '15 at 21:45
  • how do you change time zone? in windows, you have a checkbox for "automatically adjust clock for daylight saving time", and if you leave that checked, it should work as is – Lars Höppner Feb 11 '15 at 21:54
  • If i uncheck it it shows correctly.. is this because the UTC dates defined should be -06:00 after daylight savings? i am so confused. – billy jean Feb 17 '15 at 21:17
  • actually, 2 PM is correct; EST changes to EDT on March 8th, i.e. it's no longer UTC-5 but UTC-4 – Lars Höppner Feb 17 '15 at 21:34
  • basically, "...T13:00:00-05:00" in EST == "...T13:00:00-04:00" in EDT; in both cases, the scheduler will show 1PM if you're in the respective time zone; if you send "...T13:00:00-05:00" in EDT, the scheduler will show 2PM because that's the correct local time then (1 hour plus because you are in UTC-04.00); so the solution depends on what you have stored in the DB and / or how you convert your dates and whether always showing 1 PM regardless of daylight savings is actually what you want – Lars Höppner Feb 17 '15 at 21:52
  • Thanks for more info. There's no DB here as per OP. So.. is there not a way to account for this without having to know when Daylight savings time occurs? It make logical sense to enter a date and time and mean it. If i say 1:00pm EST on Date x i'd like it to mean that. So is there a way to format the js date rather than UTC -x:00 to imply 1:00 EST and have it convert properly? This is the meat of this question. All the details above. thanks. – billy jean Feb 27 '15 at 21:49
  • I don't understand the program flow; where does the date come from and how does it get to another client? – Lars Höppner Feb 27 '15 at 22:29
2

The Scheduler expects to receive and send only UTC dates - that why you should load it's data in correct format with UTC timezone (otherwise when the date is created from the string, local user timezone will be used, which is JavaScript specific behaviour):

start: new Date("2015-01-24T13:00:00.000Z"),
end: new Date("2015-01-24T13:20:00.000Z"),

Additionally you can set the Scheduler timezone to "Etc/UTC" - this way the above dates will be shown as-is without conversion on the client side:

$("#scheduler").kendoScheduler({
   date: new Date("2015/1/24"),
   timezone: "Etc/UTC",

Here is a JSFiddle based on your code snippets above showing this: http://jsfiddle.net/loanburger/0s3Lcq17/

loan.burger
  • 3,578
  • 6
  • 39
  • 59
  • Sorry i spoke too soon. This does not work. If you change the timezone on your local computer the display time is still 1:00pm. I need the time to show correctly given the person's timezone. In my timezone the start time is 1:00pm. In PST timezone the time should display as 11:00am. – billy jean Feb 11 '15 at 19:29
  • 10:00am not 11:00am. sorry. – billy jean Feb 11 '15 at 20:44
  • I updated the JSFiddle it will work now. Just provide the Scheduler with the currentTimeMarker: { useLocalTimezone: true } – loan.burger Feb 11 '15 at 22:11
  • This solution has the daylight savings time issue as well. If you add a date after daylight savings it's off by an hour if the client computer is set to handle daylight savings. it could be that i am utterly confused with how DST works.. or how the dates should be created in JS. i don't know. – billy jean Feb 17 '15 at 21:18
0

A little late to the show but I am currently evaluating Telerik's MVC components and had a similar issue when working with the scheduler. The way I handled it was to make timezone required and then server side I did the following:

public SchedulerViewModel HandleTimezonesToUTC(SchedulerViewModel e)
{
    TimeZoneInfoHelper tziHelper = new TimeZoneInfoHelper();
    if (!string.IsNullOrEmpty(e.StartTimezone) && string.IsNullOrEmpty(e.EndTimezone))
    {
        TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(tziHelper.FindMSEquilivalent(e.StartTimezone));
        e.Start = DateTime.SpecifyKind(e.Start, DateTimeKind.Unspecified);
        e.End = DateTime.SpecifyKind(e.End, DateTimeKind.Unspecified);
        e.Start = TimeZoneInfo.ConvertTimeToUtc(e.Start, tzi);
        e.End = TimeZoneInfo.ConvertTimeToUtc(e.End, tzi);
    }
    if (!string.IsNullOrEmpty(e.StartTimezone) && !string.IsNullOrEmpty(e.EndTimezone))
    {
        TimeZoneInfo tziStart = TimeZoneInfo.FindSystemTimeZoneById(tziHelper.FindMSEquilivalent(e.StartTimezone));
        TimeZoneInfo tziEnd = TimeZoneInfo.FindSystemTimeZoneById(tziHelper.FindMSEquilivalent(e.EndTimezone));
        e.Start = TimeZoneInfo.ConvertTimeToUtc(e.Start, tziStart);
        e.End = TimeZoneInfo.ConvertTimeToUtc(e.End, tziEnd);
    }
    return e;
}

public SchedulerViewModel HandleTimezonesFromUTC(SchedulerViewModel e)
{
    TimeZoneInfoHelper tziHelper = new TimeZoneInfoHelper();
    if (!string.IsNullOrEmpty(e.StartTimezone) && string.IsNullOrEmpty(e.EndTimezone))
    {
        TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(tziHelper.FindMSEquilivalent(e.StartTimezone));
        e.Start = DateTime.SpecifyKind(e.Start, DateTimeKind.Utc);
        e.End = DateTime.SpecifyKind(e.End, DateTimeKind.Utc);
        e.Start = TimeZoneInfo.ConvertTimeFromUtc(e.Start, tzi);
        e.End = TimeZoneInfo.ConvertTimeFromUtc(e.End, tzi);
    }
    if (!string.IsNullOrEmpty(e.StartTimezone) && !string.IsNullOrEmpty(e.EndTimezone))
    {
        TimeZoneInfo tziStart = TimeZoneInfo.FindSystemTimeZoneById(tziHelper.FindMSEquilivalent(e.StartTimezone));
        TimeZoneInfo tziEnd = TimeZoneInfo.FindSystemTimeZoneById(tziHelper.FindMSEquilivalent(e.EndTimezone));
        e.Start = TimeZoneInfo.ConvertTimeFromUtc(e.Start, tziStart);
        e.End = TimeZoneInfo.ConvertTimeFromUtc(e.End, tziEnd);
    }
    return e;
}

By doing it this way you are removing any accidental local->utc conversions and as one of the other posters said let the browser adjust back to local time for you.

In theory you should not need the fromUTC but when I was testing the calendar was not converting it down to the local timezone. You might be able to get away with just assigning a "kind" but I did not test that.

Not sure what you are working in but hopefully it will help you clear up some of your wibbly wobbly timey wimey issues.

Chris
  • 466
  • 1
  • 8
  • 17
0

I solved this issue by using moment.js

Javascript:

new Date(moment.utc("INSERT DATE HERE").format())

That way I am eliminating the timezone issue. I do not alter the date on the MVC Controller whatsoever.