Ich verstehe nicht, warum in dem folgenden Skript das Startdatum mit dem CurrentDate geändert wird, aber Name1 bleibt gleich.Warum wird das Startdatum zusammen mit dem aktuellen Datum erhöht?
getWorkdays('01/03/2017', '05/03/2017', 'Jimmy');
function getWorkdays (startDate, endDate, name1) {
var startDate = nlapiStringToDate(startDate);
var endDate = nlapiStringToDate(endDate);
var name1 = name1;
nlapiLogExecution('DEBUG', 'Conversion of String to Date', 'startDate is now ' + startDate + ' and endDate ' + endDate + ' and the name is ' + name1);
var name2 = name1;
var currentDate = startDate;
nlapiLogExecution('DEBUG', '', 'The currentDate is'+ currentDate + ' and the startDate is ' + startDate);
while (currentDate <= endDate) { // Loop through all dates between startDate and endDate
var weekday = currentDate.getDay(); // Retrieve the weekday (in numeric format with sunday = 0) from the currentDate
if (weekday == 1 || weekday == 6){ // Perform the following loop only if weekday is a Saturday or Sunday
nlapiLogExecution('DEBUG', '', 'The weekday number is ' + weekday + ' and the name is ' + name2);
}
var name2 = 'Jose';
currentDate.setDate(currentDate.getDate() + 1); // Go to the next date
nlapiLogExecution('DEBUG', '', 'name2 is '+ name2 + ' and name1 ' + name1);
nlapiLogExecution('DEBUG', '', 'The currentDate is'+ currentDate + ' and the startDate is ' + startDate);
}
}
Wie kann das startDate am 01.03.2017 gehalten werden?
Oder erstellen Sie ein neues Date-Objekt basierend auf 'startDate' und ordnen Sie es dem' currentDate' zu, wenn er diese Zeile entfernt, wird der Code ungültig. – Lixus
@Lixus Ja, ich habe den Code falsch gelesen. Ich korrigiere meine Antwort. – Kapol
Was ist mit der Datumsmethode .clone()? Könnte das auch benutzt werden und einer? – MisterTuna