EasyUI Forum
April 29, 2024, 08:40:54 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Default century in datebox  (Read 969 times)
galcott
Newbie
*
Posts: 39


View Profile
« on: March 24, 2023, 08:39:42 AM »

I have dateboxes using US format (MM/DD/YYYY). If the user doesn't use the calendar, and types in the year as 2 digits, it defaults to 20th century dates (1923 instead of 2023). This seems like a bug. Can it be fixed?
Logged
galcott
Newbie
*
Posts: 39


View Profile
« Reply #1 on: March 29, 2023, 02:10:46 PM »

I posted this 5 days ago and haven't had an answer. Can you please reply? Thanks.

I have dateboxes using US format (MM/DD/YYYY). If the user doesn't use the calendar, and types in the year as 2 digits, it defaults to 20th century dates (1923 instead of 2023). This seems like a bug. Can it be fixed?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #2 on: March 29, 2023, 07:23:11 PM »

This is the default behaviour of the javascript object Date. To solve this issue, please override the $.fn.datebox.defaults.parser function to fill with '20' as the prefix while typing only 2 digital number.
Code:
$.extend($.fn.datebox.defaults, {
parser: function (s) {
var CDate = $.fn.calendar.defaults.Date;
if ($(this).data('datebox')) {
CDate = $(this).datebox('calendar').calendar('options').Date;
}
if (!s) return new CDate();
var ss = s.split('/');
var m = parseInt(ss[0], 10);
var d = parseInt(ss[1], 10);
var y = parseInt(ss[2], 10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)) {
if (y < 100) {
y = 2000 + y;
}
return new CDate(y, m - 1, d);
} else {
return new CDate();
}
}
})
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!