简体   繁体   English

Acrobat中的日期计算器

[英]Date Calculator in Acrobat

I am making a fillable PDF form in Acrobat, and in one field I require a piece of script to calculate days between the dates in two other fields. 我正在Acrobat中制作一个可填写的PDF表单,并且在一个字段中我需要一段脚本来计算其他两个字段中的日期之间的日期。 Basically one field will be start date, one field will be end date and the calculation field will count the days, including the both the start and end day (inclusive). 基本上,一个字段是开始日期,一个字段是结束日期,计算字段将计算天数,包括开始日期和结束日期(包括首尾两天)。 ie: Start: 1/11/14 End: 3/11/14 Days: 3 即:开始:14年1月11日结束:14年3月11日;天数:3

The more tricky (I think) bit is that I need it to only count business days (not Saturday or Sunday) and also to disregard public holidays from the count. (我认为)比较棘手的一点是,我需要它只计算工作日(而不是周六或周日),并且不考虑公众假期。 For the holidays part, I will need the ability to input a list of dates manually into the script, so that it can be updated year on year. 对于假期部分,我将需要能够在脚本中手动输入日期列表,以便可以逐年更新。

I have already attempted this myself by reading endless posts etc, and managed to get a correct day count, but then fell down on the weekend and holiday hurdle. 我已经通过阅读无尽的帖子等来尝试这种方法,并设法获得正确的日数,但随后在周末和假期中跌倒了。

Anyone who could help me out by writing a script would be doing me a massive favour. 任何可以通过编写脚本帮助我的人都会对我大有帮助。

Here's what I have so far: 这是我到目前为止的内容:

var sDate1=this.getField("First Day of Leave").value;
var sDate2=this.getField("Last Day of Leave").value;
var oDate1 = util.scand("dd/mm/yy", sDate1);
var oDate2 = util.scand("dd/mm/yy", sDate2);
var nDay = 1000 * 60 * 60 * 24;
var eDays=Math.abs(oDate1-oDate2)/nDay;
var addDay = 1;
event.value=Math.round(eDays + addDay)+" days";

如果您需要确切的天数并照顾假期,那么最终将枚举从开始日期到结束日期的每一天,并评估它是周末(getDay()是0(星期日)还是6(星期六) )。但是,对于假期,您将查看您/您的组织计算的假期列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM