Datasource Model fields of type "date" lose time portion?

6 posts, 0 answers
  1. Brian
    Brian avatar
    8 posts
    Member since:
    Feb 2012

    Posted 27 Sep 2012 Link to this post

    The model defined below on kendo ui datasource strips off the time portion of the StartDate and EndDate when deserialized on client.  I tried setting the model type to "datetime" but that didn't seem to work.  If i remove the model then the time portion is not lost but i have to do ISO date parsing manuallly.  What am i doing wrong?

    More info:
    I'm using web api controller that returns dates in ISO 8601 format.
    schema: {
                      errors: function (response) {
                          return response.errors;
                      },
                      model: {
                          id: "ItemID",
                          fields: {
                              "Subject": { type: "string" },
                              "StartDate": { type: "date" },
                              "EndDate": { type: "date" }
                          }
                      }
                  },
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2877 posts

    Posted 02 Oct 2012 Link to this post

    Hi Brian,

    Your code looks OK, there is no "datetime" field - the correct type is "date" and it holds information about both date and time portions.

    The build-in DataSource parser uses kendo.parseDate to parse the incoming formatted string as JavaScript date. I tested both if kendo.parseDate parses date in ISO 8601 format and if the same works as expected in the DataSource and received a positive result.
    kendo.parseDate("2010-03-07T12:44:07Z");
    //returns Sun Mar 07 2010 14:44:07 GMT+0200 (FLE Standard Time)

    Could you please check my test page and let me know what I am missing? 


    Regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Ray
    Ray avatar
    4 posts
    Member since:
    Aug 2012

    Posted 04 Oct 2012 Link to this post

    Hi Alexander
    I have same problem like Brian.
    I use your test page and figure out what's different. 
    this is my test page http://jsfiddle.net/ray521/nbjr9/24/ 
    I added foo 4 and bar's datetime is 2012-09-26T11:56:38.807 



  5. Brian
    Brian avatar
    8 posts
    Member since:
    Feb 2012

    Posted 06 Oct 2012 Link to this post

    Hi Ray,

    I found that you have to include timezone in your json date serialization.  In mvc4 project i had to add the following to my WebApiConfig under the App_Start folder:
    config.Formatters.JsonFormatter.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
    config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;

    Note, you can also use DateTimeZoneHandling.Utc if you store dates in UTC in your db.  Hope that helps.
  6. Sypher
    Sypher avatar
    79 posts
    Member since:
    Aug 2006

    Posted 09 Oct 2012 Link to this post

    Brian,

    Thanks! That worked for me as well. My times were being dropped until I added those config settings. My only changes were to use UTC and place the code in the Application_Start of my Global.asax file (since I'm using Web API in ASP.NET WebForms):

    HttpConfiguration config = GlobalConfiguration.Configuration;
    config.Formatters.JsonFormatter.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
    config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;

    Bryan
  7. Ray
    Ray avatar
    4 posts
    Member since:
    Aug 2012

    Posted 10 Oct 2012 Link to this post

    Thanks Brian.
    It's work !
Back to Top
Kendo UI is VS 2017 Ready