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

Date Time Off in Published App (Azure)

4 Answers 88 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Marcab
Top achievements
Rank 1
Veteran
Marcab asked on 01 Aug 2019, 05:17 PM

I'm having a VERY odd problem.

I have an application with a number of date/time pickers. When running the application locally, all date times are displayed correctly, and stored correctly in the database.

When the application is published to Azure, there's an issue. For example, if a user adds a record with a date of 8/1/2019, then saves / refreshes. The record is displayed with a date of 7/31/2019 (date minus 1). In this scenario, the correct date is still being stored in the database.

It's seems likely that something is amiss with Azure (since there are no issues when running locally) but I'm not sure where I should be looking. I checked the obvious stuff (time zones, etc) but couldn't find anything that accounts for this odd behavior.

Has anyone experienced this issue before? Any feedback would be much appreciated.

4 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 05 Aug 2019, 11:28 AM
Hello Marcab,

In general, internally when we process the response from the server, we map each date field to a Date object. When a new js date object is created the timezone offset is taken from the operating system's clock. Thus, when the server and client are in different timezones, when the date is created on the client, the browser adjusts the date according to the offset of the client.

You can avoid this behavior by storing and displaying the dates in UTC.

e.g.

// model property
 
    private DateTime birthDate;
    public DateTime BirthDate
    {
        get { return this.birthDate; }
        set {
            this.birthDate = new DateTime(value.Ticks, DateTimeKind.Utc);
        }
    }
 
// remove offset on client before displaying the date
 
                    utcDate = returnedFromServerDate.replace(/-?\d+/, function (n) {
                        var offsetMiliseconds = new Date(parseInt(n)).getTimezoneOffset() * 60000;
                        return parseInt(n) + offsetMiliseconds
                    });

I hope this helps.


Regards,
Georgi
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
Marcab
Top achievements
Rank 1
Veteran
answered on 14 Aug 2019, 08:58 PM

Sorry for the late reply. I've been on vacation.

I'll give your solution a try.

Thanks for the response. I appreciate it.

0
Marcab
Top achievements
Rank 1
Veteran
answered on 20 Aug 2019, 02:11 PM

Hi Georgi,

I made a small prototype project using your suggestion, and it worked after I published it to Azure.

The issue that I'm now having is that the solution isn't acceptable to my client.

The solution only works when the grid is in in-line edit mode.

I'm using a custom editor template, as the number of fields involved make inline editing unworkable. The client wanted the new application to look as much like the old, familiar, application as possible. I tried to achieve this using a custom editor template.

Is there another possible solution? Is there any other documentation I can look at? Is there maybe a different way to lay out the UI that I haven't thought of?

Oh, and I should probably mention that the current UI uses a 2-tier, hierarchical grid, which list donations for a selected donor. I want to preserve this layout as the client really likes it (and so do I).

Thanks again for the help.

0
Georgi
Telerik team
answered on 22 Aug 2019, 06:41 AM
Hi,

Adjusting the timezone offset does not depend on the UI. You could adjust the client timezone within the RequestEnd of the dataSource which is always triggered - no matter the edit mode.

I would suggest you to take a look at the following article which explains how to use UTC on both client and server:



Regards,
Georgi
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.
Tags
Date/Time Pickers
Asked by
Marcab
Top achievements
Rank 1
Veteran
Answers by
Georgi
Telerik team
Marcab
Top achievements
Rank 1
Veteran
Share this question
or