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

Timezone in DatePicker and Custom Format

4 Answers 793 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rainer
Top achievements
Rank 1
Rainer asked on 27 Jan 2014, 01:56 PM
Hello Telerik-Team,

we are using Kendo 2013.2.716 and have an application that is not interested in local timezones. Internally all dates are stored as UTC, but the time part should always be ignored.
- we have a grid and a datepicker with a custom format (yyyy-MM-dd) within this grid
- we have also implemented your guide: Using UTC time on both client and server sides

reading and displaying of the Dates works perfectly :)

Because of our custom date format we also needed to change the parametermap:
$(document).ready(function () {
    var grid = $("#Grid").data("kendoGrid"),
    mvcTransport = new kendo.data.transports["aspnetmvc-ajax"]();
    grid.dataSource.transport.parameterMap = function (options, type) {
        if (type === "update" || type === "create") {
            var d = new Date(options.Startdate);
            options.Startdate = kendo.toString(new Date(d), "yyyy-MM-dd");
        }
        return mvcTransport.parameterMap(options, type);
    };
});

For employees in Asia and EU it works perfectly, but for the US (Timezone: UTC-5) we now have the following situation:
- if the user edits a date, the date is correctly sent to the Server (if the user selects Jan 2nd, then 2014-01-02 00:00:00 is submitted to the Server) -> perfect.
- but immediately after the update the grid shows Jan 1st
- only after the user hits the browser's refresh button it loads the correct date from the Server and displays it (Jan 2nd)

If I modify the ParameterMap and add the time offset myself (e.g. options.Startdate = "2014-01-02T05:00:00.000-05:00"), then the grid immediately shows the correct date, but the value sent to the server is useless, because it's a DateTime with Type "local", but I do not have any information about the timezone. If I just ignore the time and only store the date part, then it might be correct for the US users, but will be wrong for the EU & Asians...

Thank you,
Rainer

4 Answers, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 29 Jan 2014, 11:25 AM
Hello Rainer,

Actually what you described was updated and fixed in the code library in some version above. Now I see that in the code library there are two attached files, did you try the bottom one ?

http://www.telerik.com/support/code-library/using-utc-time-on-both-client-and-server-sides

Anyway the case is that probably you are doing the requestEnd logic only for the read operation. Here is how the requestEnd handler looks like (so will also supports grouping)

<script type="text/javascript">
    function convert(e) {
        if (e.response.Data && e.response.Data.length) {
            var offsetMiliseconds = new Date().getTimezoneOffset() * 60000;
            var persons = e.response.Data;
            for (var i = 0; i < persons.length; i++) {
                persons[i].BirthDate = persons[i].BirthDate.replace(/\d+/,
                function (n) { return parseInt(n) + offsetMiliseconds }
            );
            }
        }       
    }
</script>

If still struggling share your code related to the Grid and the action methods so we can seek potential issues.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rainer
Top achievements
Rank 1
answered on 29 Jan 2014, 02:34 PM
Awesome! It works like a charm now. Thank you so much!
Best regards,
Rainer
0
Per
Top achievements
Rank 1
answered on 11 May 2015, 09:37 PM

Hi,

Your suggestion does not account for DST!

BR

Per

0
T. Tsonev
Telerik team
answered on 14 May 2015, 07:49 AM

Hello Per,

Indeed the snippet does not account for the DST offset for each specific BirthDate.

The offsetMiliseconds value should be requested for each BirthDate, not for the current date.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Rainer
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Rainer
Top achievements
Rank 1
Per
Top achievements
Rank 1
T. Tsonev
Telerik team
Share this question
or