大多数时候,我在 Acrobat 中的 JavaScript 是 运行
My JavaScript in Acrobat is running, most of the time
我写了一个 JavaScript 来计算两个日期之间的天数,包括开始日期和结束日期。
此脚本还减去周末和假期。
我在 JSFiddle 上试过了,效果很好。它可能不是最快或最通用的解决方案,但它适合我的目的。
当我在 Acrobat 中尝试 运行 时,它首先根本不起作用,但在 Acrobat 64 位上运行。
仍然不完美,但它有效。
我想知道是否有人有时间看一看,也许可以给我一些信息,说明为什么它只在特定条件下有效。
代码:
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:01");
var EndDate = util.scand("dd/mm/yyyy HH:MM:SS", EndDate + " 23:59:59");
//Formatting them to the correct date format
var Saturday = 6;
var Sunday = 7;
//Weekends will have to be defined as the first of the year
var Holiday = [
14,
15,
16
];
//Could improve that but for now the holidays are represented as the number of day in the year
var now = new Date(StartDate);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var StartDate = day;
var now = new Date(EndDate);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var EndDate = day;
//Converting the start and end dates
var DaysBetween = [];
for (var i = StartDate; i <= EndDate; i++) {
DaysBetween.push(i);
}
//Array for days in between
var Holidays = 0;
Holiday.forEach((entry) => {
if (entry >= StartDate & entry <= EndDate) {
Holidays++;
}
});
//Checks if holidays fall into this span
var Saturdays = 0;
DaysBetween.forEach((entry) => {
if (entry % Saturday == 0) {
Saturdays++;
}
});
var Sundays = 0;
DaysBetween.forEach((entry) => {
if (entry % Sunday == 0) {
Sundays++;
}
});
//Checks if the days between are a multiple of the first weekend
var DaysAbsent = 0;
DaysAbsent = DaysBetween.length - Holidays - Saturdays - Sundays;
event.value = DaysAbsent;
我还有这些错误日志:
TypeError: this.getField(...) 为空
3:Field:Calculate
TypeError: this.getField(...) 为空
3:Field:Calculate
这对我有用!我不知道具体发生了什么变化,我猜是输入字段中的日期格式起作用了,但 Acrobat 接受了它并且没有抛出任何错误。
var StartDate = this.getField("1").value
console.println("StartDate: " + StartDate);
var EndDate = this.getField("2").value
console.println("EndDate: " + EndDate);
//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 Saturday = 6;
var Sunday = 7;
//Weekends will have to be defined as the first of the year
var Holiday = [
01 / 01 / 2021,
01 / 02 / 2021,
01 / 03 / 2021
];
//Could improve that but for now the holidays are represented as the number of day in the year
var now = new Date(StartDate);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var StartDate = day;
console.println("StartDate: " + StartDate);
var now = new Date(EndDate);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var EndDate = day;
//Converting the start and end dates
var DaysBetween = [];
for (var i = StartDate; i <= EndDate; i++) {
DaysBetween.push(i);
}
//Array for days in between
var Holidays = 0;
Holiday.forEach((entry) => {
var now = new Date(entry);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
entry = day;
if (entry >= StartDate & entry <= EndDate) {
Holidays++;
}
});
//Checks if holidays fall into this span
var Saturdays = 0;
DaysBetween.forEach((entry) => {
if (entry % Saturday == 0) {
Saturdays++;
}
});
var Sundays = 0;
DaysBetween.forEach((entry) => {
if (entry % Sunday == 0) {
Sundays++;
}
});
//Checks if the days between are a multiple of the first weekend
var DaysAbsent = 0;
DaysAbsent = DaysBetween.length - Holidays - Saturdays - Sundays;
event.value = DaysAbsent;
周六和周日的计算仍然存在缺陷,但我正在研究新的解决方案。如果您对该解决方案感兴趣,请 lmk。
我写了一个 JavaScript 来计算两个日期之间的天数,包括开始日期和结束日期。 此脚本还减去周末和假期。
我在 JSFiddle 上试过了,效果很好。它可能不是最快或最通用的解决方案,但它适合我的目的。
当我在 Acrobat 中尝试 运行 时,它首先根本不起作用,但在 Acrobat 64 位上运行。 仍然不完美,但它有效。
我想知道是否有人有时间看一看,也许可以给我一些信息,说明为什么它只在特定条件下有效。
代码:
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:01");
var EndDate = util.scand("dd/mm/yyyy HH:MM:SS", EndDate + " 23:59:59");
//Formatting them to the correct date format
var Saturday = 6;
var Sunday = 7;
//Weekends will have to be defined as the first of the year
var Holiday = [
14,
15,
16
];
//Could improve that but for now the holidays are represented as the number of day in the year
var now = new Date(StartDate);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var StartDate = day;
var now = new Date(EndDate);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var EndDate = day;
//Converting the start and end dates
var DaysBetween = [];
for (var i = StartDate; i <= EndDate; i++) {
DaysBetween.push(i);
}
//Array for days in between
var Holidays = 0;
Holiday.forEach((entry) => {
if (entry >= StartDate & entry <= EndDate) {
Holidays++;
}
});
//Checks if holidays fall into this span
var Saturdays = 0;
DaysBetween.forEach((entry) => {
if (entry % Saturday == 0) {
Saturdays++;
}
});
var Sundays = 0;
DaysBetween.forEach((entry) => {
if (entry % Sunday == 0) {
Sundays++;
}
});
//Checks if the days between are a multiple of the first weekend
var DaysAbsent = 0;
DaysAbsent = DaysBetween.length - Holidays - Saturdays - Sundays;
event.value = DaysAbsent;
我还有这些错误日志:
TypeError: this.getField(...) 为空 3:Field:Calculate TypeError: this.getField(...) 为空 3:Field:Calculate
这对我有用!我不知道具体发生了什么变化,我猜是输入字段中的日期格式起作用了,但 Acrobat 接受了它并且没有抛出任何错误。
var StartDate = this.getField("1").value
console.println("StartDate: " + StartDate);
var EndDate = this.getField("2").value
console.println("EndDate: " + EndDate);
//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 Saturday = 6;
var Sunday = 7;
//Weekends will have to be defined as the first of the year
var Holiday = [
01 / 01 / 2021,
01 / 02 / 2021,
01 / 03 / 2021
];
//Could improve that but for now the holidays are represented as the number of day in the year
var now = new Date(StartDate);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var StartDate = day;
console.println("StartDate: " + StartDate);
var now = new Date(EndDate);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var EndDate = day;
//Converting the start and end dates
var DaysBetween = [];
for (var i = StartDate; i <= EndDate; i++) {
DaysBetween.push(i);
}
//Array for days in between
var Holidays = 0;
Holiday.forEach((entry) => {
var now = new Date(entry);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
entry = day;
if (entry >= StartDate & entry <= EndDate) {
Holidays++;
}
});
//Checks if holidays fall into this span
var Saturdays = 0;
DaysBetween.forEach((entry) => {
if (entry % Saturday == 0) {
Saturdays++;
}
});
var Sundays = 0;
DaysBetween.forEach((entry) => {
if (entry % Sunday == 0) {
Sundays++;
}
});
//Checks if the days between are a multiple of the first weekend
var DaysAbsent = 0;
DaysAbsent = DaysBetween.length - Holidays - Saturdays - Sundays;
event.value = DaysAbsent;
周六和周日的计算仍然存在缺陷,但我正在研究新的解决方案。如果您对该解决方案感兴趣,请 lmk。