2
0
forked from Wavyzz/dolibarr

Fix parsing input date for eldy calendar when using short year

This commit is contained in:
Laurent Destailleur (aka Eldy)
2024-12-15 15:38:38 +01:00
parent 4c40c78868
commit 65f9e7f172
2 changed files with 48 additions and 29 deletions

View File

@@ -222,37 +222,59 @@ function getObjectFromID(id){
return theObject;
}
// Called after selection of a date to save details into detailed fields
// Called after the selection or typing of a date to save details into detailed fields
function dpChangeDay(dateFieldID, format)
{
//showDP.datefieldID=dateFieldID;
console.log("Call dpChangeDay, we save date into detailed fields from format = "+format);
var thefield=getObjectFromID(dateFieldID);
var thefieldday=getObjectFromID(dateFieldID+"day");
var thefieldmonth=getObjectFromID(dateFieldID+"month");
var thefieldyear=getObjectFromID(dateFieldID+"year");
var thefield = getObjectFromID(dateFieldID);
var thefieldday = getObjectFromID(dateFieldID+"day");
var thefieldmonth = getObjectFromID(dateFieldID+"month");
var thefieldyear = getObjectFromID(dateFieldID+"year");
var date=getDateFromFormat(thefield.value, format);
var date = getDateFromFormat(thefield.value, format);
//console.log(date);
if (date)
{
thefieldday.value=date.getDate();
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value=date.getMonth()+1;
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value=date.getFullYear();
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
thefieldday.value = date.getDate();
if (thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value = date.getMonth()+1;
if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value = date.getFullYear();
if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
return 1;
}
else
{
thefieldday.value='';
if(thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value='';
if(thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value='';
if(thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
// Replace yyyy into yy
newformat = format.replace(/yyyy/g, 'yy');
if (newformat != format) {
console.log("dpChangeDay, we try now from format = "+newformat);
var date = getDateFromFormat(thefield.value, newformat);
//console.log(date);
if (date)
{
thefieldday.value = date.getDate();
if (thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value = date.getMonth()+1;
if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value = date.getFullYear();
if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
return 2;
}
}
thefieldday.value = '';
if (thefieldday.onchange) thefieldday.onchange.call(thefieldday);
thefieldmonth.value = '';
if (thefieldmonth.onchange) thefieldmonth.onchange.call(thefieldmonth);
thefieldyear.value = '';
if (thefieldyear.onchange) thefieldyear.onchange.call(thefieldyear);
return 0;
}
/*
@@ -337,13 +359,13 @@ function formatDate(date,format)
* Licence: GPL
* ==================================================================
*/
function getDateFromFormat(val,format)
function getDateFromFormat(val, format)
{
// alert('getDateFromFormat val='+val+' format='+format);
// Force parameters en chaine
val=val+"";
format=format+"";
val = val+"";
format = format+"";
if (val == '') return 0;
@@ -356,17 +378,14 @@ function getDateFromFormat(val,format)
var seconde=now.getSeconds();
var i=0;
var d=0; // -d- follows the date string while -i- follows the format
// string
var d=0; // -d- follows the date string while -i- follows the format string
while (i < format.length)
{
c=format.charAt(i); // Recupere char du format
substr="";
j=i;
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char
// successif
// identiques
while ((format.charAt(j)==c) && (j < format.length)) // Get successive similar characters
{
substr += format.charAt(j++);
}