Planet PDF Forum Planet PDF Forum
  New Posts New Posts RSS Feed - Add 5 years
  FAQ FAQ  Forum Search   Register Register  Login Login

Hi, welcome to the Foxit Planet PDF Forum. If you have PDF or Adobe Acrobat questions then the right place to ask them is here, in this forum.

Add 5 years

 Post Reply Post Reply Page  12>
Author
dan View Drop Down
New Member
New Member


Joined: 05 Feb 2016
Points: 8
Post Options Post Options   Quote dan Quote  Post ReplyReply Direct Link To This Post Topic: Add 5 years
    Posted: 12 Feb 2016 at 8:56pm
Because the Great State of Oregon legislatively told us we had to.Unhappy



Edited by dan - 12 Feb 2016 at 9:02pm
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4111
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 12 Feb 2016 at 5:23pm
Why are you adjusting the date back one day?

You are cutting the 5 years one days short.

Anyone with a birthday of February 29 celebrates on March 1.

The year is determined by the Earth's orbit around the Sun and to get to the same position in the orbit 5 years later will be April 1st with our calendar system.


Back to Top
try67 View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Points: 634
Post Options Post Options   Quote try67 Quote  Post ReplyReply Direct Link To This Post Posted: 12 Feb 2016 at 1:35pm
There are several errors in this part of the code:

if (d.getMonth == 2) && (d.getDate == 29);{
d.setDate(28)
}
(f.getMonth == 2) && (f.getDate == 29);{
f.setDate(28)
}

But I don't think this code is necessary at all. You can't create a Date object that points to an invalid date (like 29/09 on a non-leap year). You need to test it before converting the string to a Date object.

- Acrobat Expert - Contact me personally at try6767@gmail.com
Check out my custom-made scripts website: http://try67.blogspot.com
Back to Top
dan View Drop Down
New Member
New Member


Joined: 05 Feb 2016
Points: 8
Post Options Post Options   Quote dan Quote  Post ReplyReply Direct Link To This Post Posted: 11 Feb 2016 at 10:41pm
Ok, gave it a try but getting an error at line 9. Do you see whats causing the error?

// regarding check box
var a = this.getField("agg.revise");
// get date of injury
var d = util.scand("mm/dd/yyyy",this.getField("worker.doi").value);
// get date of first closure
var f = util.scand("mm/dd/yyyy",this.getField("date.firstclosure").value);
// analyze both dates for "Feb 29" (leap year); subtract one day when true
if (d.getMonth == 2) && (d.getDate == 29);{
d.setDate(28)
}
(f.getMonth == 2) && (f.getDate == 29);{
f.setDate(28)
}
// add 5 years to the date objects;
d.setFullYear(d.getFullYear() + 5)}
f.setFullYear(f.getFullYear() + 5)}
// place result in current field
// when agg box IS checked
if (a.value == "Yes") {
event.value = util.printd("mm/dd/yyyy", d)
}
// when agg box NOT checked
else{
event.value = util.printd("mm/dd/yyyy", f)
}
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4111
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 10 Feb 2016 at 6:31pm
I would test the month and date for the date object and if equal to 229 then change the date object by deducting 1 day for the date value for the date object.
Back to Top
dan View Drop Down
New Member
New Member


Joined: 05 Feb 2016
Points: 8
Post Options Post Options   Quote dan Quote  Post ReplyReply Direct Link To This Post Posted: 10 Feb 2016 at 5:42pm
Thanks. That works too. Now I have a new problem related to leap years. I need the script to subtract 1 day if the value of a is 02/29.

Example:

02/29/2016 + 5 - 1 = 02/28/2021

Is there an easy way to make that adjustment to the current script?

Thanks for any assistance.
Back to Top
gkaiseril View Drop Down
Senior Member
Senior Member


Joined: 15 Jul 2011
Location: USA
Points: 4111
Post Options Post Options   Quote gkaiseril Quote  Post ReplyReply Direct Link To This Post Posted: 06 Feb 2016 at 11:19pm
I would just adjust the fullYear for the "a" object using the "setFullYear()" method

var a = util.scand("mm/dd/yyyy",this.getField("worker.doi").value);
// add 5 years to the date object;
a.setFullYear(a.getFullYear() + 5); 
// place result in current field
event.value = util.printd("mm/dd/yyyy", a);

and get rid of the unnecessary code.
Back to Top
dan View Drop Down
New Member
New Member


Joined: 05 Feb 2016
Points: 8
Post Options Post Options   Quote dan Quote  Post ReplyReply Direct Link To This Post Posted: 05 Feb 2016 at 8:28pm
We tested it, and it appears to work even for leap years.
Back to Top
dan View Drop Down
New Member
New Member


Joined: 05 Feb 2016
Points: 8
Post Options Post Options   Quote dan Quote  Post ReplyReply Direct Link To This Post Posted: 05 Feb 2016 at 7:49pm
How would you suggest I change the script to deal with leap years?
Back to Top
dan View Drop Down
New Member
New Member


Joined: 05 Feb 2016
Points: 8
Post Options Post Options   Quote dan Quote  Post ReplyReply Direct Link To This Post Posted: 05 Feb 2016 at 7:47pm
Ok you helped me fix it. This appears to work. I just changed getCheckBox to getField and b.target.value to b.value. Thanks.

var b = this.getField("agg.revise");

if (b.value == "Yes"){
// get first closure date
var a = util.scand("mm/dd/yyyy",this.getField("worker.doi").value);
// get the year value from date object
var yr = a.getFullYear();
// get the month value from date object
var mo = a.getMonth();
// get the date value from the date object
var da = a.getDate();
// add 5 years to the year value
yr += 5; 
// create new date object from year+5, month, and date
var d2 = new Date(yr,mo,da);
// place result in current field
event.value = util.printd("mm/dd/yyyy", d2)} 

else{
// get first closure date
var a = util.scand("mm/dd/yyyy",this.getField("date.firstclosure").value);
// get the year value from date object
var yr = a.getFullYear();
// get the month value from date object
var mo = a.getMonth();
// get the date value from the date object
var da = a.getDate();
// add 5 years to the year value
yr += 5; 
// create new date object from year+5, month, and date
var d2 = new Date(yr,mo,da);
// place result in current field
event.value = util.printd("mm/dd/yyyy", d2)}
Back to Top
dan View Drop Down
New Member
New Member


Joined: 05 Feb 2016
Points: 8
Post Options Post Options   Quote dan Quote  Post ReplyReply Direct Link To This Post Posted: 05 Feb 2016 at 7:31pm
Thanks for the reply. No I don't get any errors. I wasn't sure if you needed to change "getField" when you are dealing with a check box. If I add a similar JavaScript (see below) to the check box instead of the field it works. The only problem is it doesn't produce a value in the "date.aggravationend" field until the check box is checked and/or unchecked. I really need it to default without the user checking the box. I'll look into the leap year problem seperately, thanks for the heads up on that.

var b = this.getField("date.aggravationend");

if (event.target.value == "Yes"){
// get first closure date
var a = util.scand("mm/dd/yyyy",this.getField("worker.doi").value);
// get the year value from date object
var yr = a.getFullYear();
// get the month value from date object
var mo = a.getMonth();
// get the date value from the date object
var da = a.getDate();
// add 5 years to the year value
yr += 5; 
// create new date object from year+5, month, and date
var d2 = new Date(yr,mo,da);
// place result in current field
b.value = util.printd("mm/dd/yyyy", d2)} 

else{
// get first closure date
var a = util.scand("mm/dd/yyyy",this.getField("date.firstclosure").value);
// get the year value from date object
var yr = a.getFullYear();
// get the month value from date object
var mo = a.getMonth();
// get the date value from the date object
var da = a.getDate();
// add 5 years to the year value
yr += 5; 
// create new date object from year+5, month, and date
var d2 = new Date(yr,mo,da);
// place result in current field
b.value = util.printd("mm/dd/yyyy", d2)}
Back to Top
 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.10
Copyright ©2001-2017 Web Wiz Ltd.

This page was generated in 0.031 seconds.