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

DatePicker default month when parsing day only

1 Answer 695 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 1
Christophe asked on 09 Aug 2019, 12:02 PM

I'm trying to configure the DatePicker to be able to parse a "dd" format, and when it does, i'd like it to use the current month, as it does for the current year when none is specified.

I analyzed the source code (especially the parseDate from kendo.core), but I didn't find any solution.

Is there an option to achieve that ?

Live exemple: https://dojo.telerik.com/OqeSaDEC

Thank you

1 Answer, 1 is accepted

Sort by
0
Alex Hajigeorgieva
Telerik team
answered on 13 Aug 2019, 10:27 AM
Hi, Christophe,

It seems that we have a logged feature request for this functionality in our Feedback Portal and I have already cast a vote there on your behalf:

https://feedback.telerik.com/kendo-jquery-ui/1359590-date-picker-autofill-current-month-year-when-day-entered

As for the source code, the reason for the behaviour is located here at the time of writing:

https://github.com/telerik/kendo-ui-core/blob/master/src/kendo.core.js#L1520-L1551

- we have a default year which is this year
- we do not have a default month so it remains null

This means that the browser gets the following in the Date constructor:

new Date(2019, null, 23, null, null, null, null)
 
Which evaluates as follows:



if (year === null && month === null && day === null && hasTime) {
      year = defaultYear;
      month = date.getMonth();
      day = date.getDate();
  } else {
      if (year === null) {
          year = defaultYear;
      }
 
      if (day === null) {
          day = 1;
      }
  }
 
  if (pmHour && hours < 12) {
      hours += 12;
  }
 
  if (UTC) {
      if (hoursOffset) {
          hours += -hoursOffset;
      }
 
      if (minutesOffset) {
          minutes += -minutesOffset;
      }
 
      value = new Date(Date.UTC(year, month, day, hours, minutes, seconds, milliseconds));
  } else {
      value = new Date(year, month, day, hours, minutes, seconds, milliseconds);
      adjustDST(value, hours);
  }

To change the behavior you would need to override the internal function and make kendo.parseDate() and kendo.parseExactDate() use it:

kendo.parseDate = function(value, formats, culture) {
    return myInternalParseDate(value, formats, culture, false);
};
 
kendo.parseExactDate = function(value, formats, culture) {
    return myInternalParseDate(value, formats, culture, true);
};

Kind Regards,
Alex Hajigeorgieva
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.
Tags
Date/Time Pickers
Asked by
Christophe
Top achievements
Rank 1
Answers by
Alex Hajigeorgieva
Telerik team
Share this question
or