Copy link to clipboard
Copied
I worked on this date calculator outside of Acrobat and wanted to import it later but it seems Acrobat doesn't include functions like .include() or am I missing something?
var StartDate = new Date(this.getField("1").value);
var EndDate = new Date(this.getField("2").value);
//Gets input field value
var StartDate = util.scand("dd/mm/yyyy HH:MM:SS", StartDate + " 00:00:01");
var EndDate = util.scand("dd/mm/yyyy HH:MM:SS", EndDate + " 23:59:59");
//Formatting them to the correct date format
var DaysBetween = [];
var StartDateC = new Date(StartDate);
while (StartDateC <= EndDate) {
DaysBetween.push(new Date(StartDateC));
StartDateC.setDate(StartDateC.getDate() + 1);
}
var Holidays = [
new Date("01.01.2021").getTime(),
new Date("01.02.2021").getTime(),
new Date("01.06.2021").getTime()
];
var Weekend = 0;
var Holiday = 0;
DaysBetween.forEach((entry) => {
if (entry.getDay() == 5 || entry.getDay() == 0) {
Weekend++;
} else if (Holidays.includes(entry.getTime()) == true) {
Holiday++;
} else {
}
});
var DaysAway = DaysBetween.length - Holiday - Weekend;
event.value = DaysAway;
Any and all help is appreciated!
I fixed it:
//Only modify marked values and variables
var StartDate = this.getField("1").value;
var EndDate = this.getField("2").value;
//Gets input field value
var StartDate = util.scand("dd/mm/yyyy HH:MM:SS", StartDate + "00:00:00");
var EndDate = util.scand("dd/mm/yyyy HH:MM:SS", EndDate + "00:00:00");
//Formatting them to the correct date format
console.println("StartDate: " + StartDate);
console.println("EndDate: " + EndDate);
var DaysBetween = [];
var StartDateC = new Date(StartDate);
...
Copy link to clipboard
Copied
Try the function indexOf
Copy link to clipboard
Copied
Tried it and it doesn't die anymore but the value in the output field stays at 1
Copy link to clipboard
Copied
Do not use the full timestamp in the Holidays array. If it's off by one millisecond it won't work.
Compare the dates as simple dd/mm/yyyy strings (or whatever format you want to use, as long as it's consistent).
Copy link to clipboard
Copied
I tried that. It runs now but the indexOf simply skipps the Holidays.
Copy link to clipboard
Copied
What script does you use?
Copy link to clipboard
Copied
It depends on the version of Acrobat you're using. It might be supported in Acrobat DC, but not in earlier versions, depending on the implementation of JavaScript that's included in it. That's why I prefer to avoid using such methods (forEach falls in the same category) and stick with the core ones, instead.
Copy link to clipboard
Copied
I am using the newest version of Acrobat Pro DC (64bit). Where can I see the version number?
Copy link to clipboard
Copied
Of JavaScript? It's in the Acrobat SDK documentation.
Copy link to clipboard
Copied
Or do you mean of the methods? That information is available in the online documentations of the core JS objects, like this one: https://developer.mozilla.org/en-US/docs/Web/JavaScript
Copy link to clipboard
Copied
I fixed it:
//Only modify marked values and variables
var StartDate = this.getField("1").value;
var EndDate = this.getField("2").value;
//Gets input field value
var StartDate = util.scand("dd/mm/yyyy HH:MM:SS", StartDate + "00:00:00");
var EndDate = util.scand("dd/mm/yyyy HH:MM:SS", EndDate + "00:00:00");
//Formatting them to the correct date format
console.println("StartDate: " + StartDate);
console.println("EndDate: " + EndDate);
var DaysBetween = [];
var StartDateC = new Date(StartDate);
while (StartDateC <= EndDate) {
DaysBetween.push(new Date(StartDateC));
StartDateC.setDate(StartDateC.getDate() + 1);
}
/*----------------------------------*
|Use this format for holidays: |
| mm/dd/yyyy |
|new Date("01/01/2021").getTime(), |
|new Date("01/02/2021").getTime(), |
*-----------------------------------*/
var Holidays = [
new Date("01/01/2021").getTime(),
new Date("01/02/2021").getTime(),
new Date("01/06/2021").getTime()
];
//---------------------------------*/
var Weekend = 0;
var Holiday = 0;
DaysBetween.forEach((entry) => {
if (entry.getDay() == 6 || entry.getDay() == 0) {
Weekend++;
} else if (Holidays.indexOf(entry.getTime()) >= 0) {
Holiday++;
} else {
}
});
var DaysAway = DaysBetween.length - Holiday - Weekend;
event.value = DaysAway;