Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Does Acrobat include array.include(value)?

Community Beginner ,
Jul 19, 2021 Jul 19, 2021

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!

TOPICS
How to, JavaScript, PDF forms

Views

54

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jul 19, 2021 Jul 19, 2021
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); ...

Likes

Translate

Translate
Adobe Community Professional ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Try the function indexOf

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Tried it and it doesn't die anymore but the value in the output field stays at 1

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 19, 2021 Jul 19, 2021

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).

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

I tried that. It runs now but the indexOf simply skipps the Holidays.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

What script does you use?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 19, 2021 Jul 19, 2021

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

I am using the newest version of Acrobat Pro DC (64bit). Where can I see the version number?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

Of JavaScript? It's in the Acrobat SDK documentation.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jul 19, 2021 Jul 19, 2021

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 19, 2021 Jul 19, 2021

Copy link to clipboard

Copied

LATEST

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;

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines