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

Wrong parsing of year when using named month

4 Answers 153 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Beheer
Top achievements
Rank 1
Beheer asked on 02 May 2014, 09:29 AM
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>

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 02 May 2014, 12:07 PM
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!
 
0
Beheer
Top achievements
Rank 1
answered on 02 May 2014, 01:13 PM
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




0
Accepted
Georgi Krustev
Telerik team
answered on 02 May 2014, 03:29 PM
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!
 
0
Beheer
Top achievements
Rank 1
answered on 05 May 2014, 08:42 AM
My mistake, did not notice the erroneous closing bracket. The solution works as suggested. Thanks again.
Tags
Date/Time Pickers
Asked by
Beheer
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Beheer
Top achievements
Rank 1
Share this question
or