Hi all,
i'm having the strangest behaviour with one of my scripts, and i cannot figure out where the problem is.
Before showing the code, here's the principle.
My form has two time fields: "Injection Time" and "Post injection Time"
The script runs at the exit event of "injection time" and looks if the time of injection is before the "post injection time"
Here's my code:
//get the value of the field "Injection time"
var injection = this.formattedValue;
//create an new Date object
var injectionTime = new Date();//split the string to get the HH MM and SS values of the formattedValue (HH:MM:SS)
var injectionTimeHoursString = injection.substr(0,2);
var injectionTimeMinutesString = injection.substr(3,2);
var injectionTimeSecondsString = injection.substr(6,2);//parse the strings into integer
var injectionTimeHoursInt = parseInt(injectionTimeHoursString);
//set the integer values into my Date object
var injectionTimeMinutesInt = parseInt(injectionTimeMinutesString);
var injectionTimeSecondsInt = parseInt(injectionTimeSecondsString);
injectionTime.setHours(injectionTimeHoursInt, injectionTimeMinutesInt, injectionTimeSecondsInt,0);//do the same for the other time field "Post injection time"
var post = post_injection.post_time.formattedValue;
var postTime = new Date();
var postTimeHoursString = post.substr(0,2);
var postTimeMinutesString = post.substr(3,2);
var postTimeSecondsString = post.substr(6,2);
var postTimeHoursInt = parseInt(postTimeHoursString);
var postTimeMinutesInt = parseInt(postTimeMinutesString);
var postTimeSecondsInt = parseInt(postTimeSecondsString);
postTime.setHours(postTimeHoursInt, postTimeMinutesInt, postTimeSecondsInt,0);
//calculate the difference between both
var diff = postTime.getTime() - injectionTime.getTime();//if the difference gives a negative result, display a message, empty the fields and set focus
if(diff<0) {
xfa.host.messageBox("The time of injection should be sooner than the time of post-injection activity measure.\n\nPlease re-enter correct times.","Incompatibility of times");
this.rawValue = "";
post_injection.post_time.rawValue = "";
xfa.host.setFocus(post_injection.post_time);
}
The code seems to work quite well... except with some values!
if postTime is 12:00:00
and injetion is 12:04:00
I get the error message and everything, so that's OK
BUT
when postTime is 12:00:00
and injectionTime is 12:08:00
No message! as if the difference was not negative! (the difference is zero...)
when i display the times in a messagebox, 12:04:00 gives 12:04:00 GMT bla bla... but 12:08 gives 12:00:00 GMT etc...
same problem with 12:09, but not 12:10 for example...
Any thought??
Thank you.
Solved! Go to Solution.
Views
Replies
Total Likes
Thank you, but since i am used to javascript, i'll stick to it.
I did figure out the problem. It's a javascript bug with the ParseInt method !!
check out there: http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C85006A6604
parseInt("08") = 0 !!
how to waste 2 hours for a stupid bug...
Views
Replies
Total Likes
Hi,
Have you tried using FormCalc instead of JavaScript?
FormCalc comes with some very handy time (and date) functions. When using a time object, you can use Time2Num to convert the inputted time to a number from the epoch. Once you compare the two numbers you cn convert back to a time or take appropriate action.
Niall
Views
Replies
Total Likes
Hi,
Here are some examples:
https://acrobat.com/#d=EsWqBMBt3sgEXnMSsK5pRA
https://acrobat.com/#d=kCPIgVkd09qrx6h-WRXxbQ
Hope that helps,
Niall
Views
Replies
Total Likes
Thank you, but since i am used to javascript, i'll stick to it.
I did figure out the problem. It's a javascript bug with the ParseInt method !!
check out there: http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256C85006A6604
parseInt("08") = 0 !!
how to waste 2 hours for a stupid bug...
Views
Replies
Total Likes
Views
Likes
Replies