Date Time Off in Published App (Azure)

5 posts, 0 answers
  1. Marcab
    Marcab avatar
    7 posts
    Member since:
    Apr 2019

    Posted 01 Aug Link to this post

    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.

  2. Georgi
    Admin
    Georgi avatar
    574 posts

    Posted 05 Aug Link to this post

    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.
  3. Marcab
    Marcab avatar
    7 posts
    Member since:
    Apr 2019

    Posted 14 Aug in reply to Georgi Link to this post

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

    I'll give your solution a try.

    Thanks for the response. I appreciate it.

  4. Marcab
    Marcab avatar
    7 posts
    Member since:
    Apr 2019

    Posted 20 Aug in reply to Georgi Link to this post

    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.

  5. Georgi
    Admin
    Georgi avatar
    574 posts

    Posted 22 Aug Link to this post

    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.
Back to Top