Wrong parsing of year when using named month

5 posts, 1 answers
  1. Beheer
    Beheer avatar
    3 posts
    Member since:
    Nov 2013

    Posted 02 May 2014 Link to this post

    In the following code, the button is wired to parse the value of the datepicker when clicked. It works fine until I try to enter the name of the month e.g. 15 juli 2015 will be converted to 2014-07-15. This means that the month and year are parsed correctly, whilst the year is not. The culture in this case is set to NL, but this also fails when using en-US with the date value July 15 2015.

    <!DOCTYPE html>
    <html>
    <head>
        <style>html { font-size: 12px; font-family: Arial, Helvetica, sans-serif; }</style>
        <title></title>
    </head>
    <body>
         
            <div id="example" class="k-content">
                <div id="email-settings">
                    <div style="margin-top: -6px; margin-left: 180px">
                        <input id="datepicker" value="10/10/2011" style="width:150px;" />
                    </div>               
                  <div><button onclick="alert(kendo.parseDate($('#datepicker').val()));">Test</button></div>
                </div>
            <script>
                $(document).ready(function() {
                    kendo.culture("nl-NL");
                   
                    // create DatePicker from input HTML element
                    $("#datepicker").kendoDatePicker();
     
                    $("#monthpicker").kendoDatePicker({
                        // defines the start view
                        start: "year",
     
                        // defines when the calendar should return date
                        depth: "year",
     
                        // display month and year in the input
                        format: "MMMM yyyy"
                    });
                });
            </script>
            <style scoped>
                #example h2 {
                    font-weight: normal;
                }
                #email-settings {
                    width: 395px;
                    margin: 30px auto;
                    padding: 110px 0 0 30px;
                    background: url('../../content/web/datepicker/mailSettings.png') transparent no-repeat 0 0;
                }
            </style>
            </div>
     
    </body>
    </html>
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 02 May 2014 Link to this post

    Hi Beheer,

    The kendo.parseDate method uses the date formats defined in the used culture script to parse the date string. If the date string format cannot be found in the current culture script then the value will be consided as invalid. If you need to parse date strings with custom formats then I will suggest you pass a second parameter to the kendo.parseDate method - list of date formats.

    Regards,
    Georgi Krustev
    Telerik
     
    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. Beheer
    Beheer avatar
    3 posts
    Member since:
    Nov 2013

    Posted 02 May 2014 in reply to Georgi Krustev Link to this post

    Hi Georgi,

    thanks for your answer, but what do you mean by "considered as invalid"? Do you mean that the parse function should return a null value, or format part of the date as is happening right now?

    I tried to simplify things and just made a page with only this code: console.log(kendo.parseDate('15 juli 2015'), ['dd MMM yyyy']);

    and I still get the following output: Tue Jul 15 2014 00:00:00 GMT+0200 (W. Europe Daylight Time) ["dd MMM yyyy"]

    Regards,
    Edward




  5. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 02 May 2014 Link to this post

    Hello again Beheer,

    The kendo.parseDate is called without passing the list of date formats:
    console.log(kendo.parseDate('15 juli 2015' /* method is closed earlier*/), ['dd MMM yyyy']);

    Check this demo, which shows how to define the formats and the correct way to call the method. It works as expected with correct parameters.

    Regards,
    Georgi Krustev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Beheer
    Beheer avatar
    3 posts
    Member since:
    Nov 2013

    Posted 05 May 2014 in reply to Georgi Krustev Link to this post

    My mistake, did not notice the erroneous closing bracket. The solution works as suggested. Thanks again.
Back to Top
Kendo UI is VS 2017 Ready