My task is to create a form that will calculate all of the hours to be paid for a business trip. I have code written to calculate the hours between the departure and arrival times. The issue I am having is in order to make the form more user friendly, I have a drop down list of all major time zones with major cities that the user will be able to select because most itineraries have local time which makes travelling out of multiple time zones difficult. I want to write a code that will automatically set both times (internally and not displayed to the user) to UTC or GMT time based on the time and time zone input, make the calculations that I created in the script I have already written and then display the total hours. As you can see I have the plan in my head but am unsure how to put it to 'paper'.
I only need help with the time zones because I am in over my head but I don't need anyone to write the code for me just hopefully will explain how I can implement these tools into an existing program that will calculate hours between departure and arrival without consideration into time zones. I have a feeling I will need to utilize the Olson database and possible GeoNames or Earthtools.
I'm not sure but maybe if you were to set the timezone offset for the items in your dropdown list you could then use that value to correct to UTC or GMT or whatever. So on the Binding tab for your DDL you'd set the values under Specify Item Values, then you'd use the boundItem() method to retrieve the offset value.
That's just off the top of my head, I'm not sure I'd want to attempt writing something like this myself!
calculating times isn't trivial, especially when a form is used in another time zone that it was designed in.
Every timezone has a specific offset to the gmt time, which it the time zone XFA forms use as reference.
For Berlin it is for example -7200000 milliseconds (GMT+1) for New York its +14400000 milliseconds (GMT-5).
To avoid miscalculation you need to determine the time offset of your current lacation to gmt.
The easiest way is to use the locale property of your form ($template.#subform.locale), but this is not flexible enough as the template doesn't change at runtime anymore.
But better is to use the ambient locale of the host (Acrobat/Reader).
Here's a FormCalc script to calculate the time difference between two time considering the gmt offset of the current time zone of the host.
var fullTime = 0
var breakTime = 0
var result = 0
var msPerHr = 3600000
var gmtOffset = 1 - Replace(Num2Time(time(), "z", $host.language), "0", "") * msPerHr
var fullTime = 0
var breakTime = 0
if (amIn ne null and pmOut ne null) then
if (Time2Num(amIn.formattedValue, "HH:MM") lt Time2Num(pmOut.formattedValue, "HH:MM")) then
fullTime = Abs(Time2Num(amIn.formattedValue, "HH:MM") - Time2Num(pmOut.formattedValue, "HH:MM")) / msPerHr
fullTime = 24 - Abs(Time2Num(pmOut.formattedValue, "HH:MM") - Time2Num(amIn.formattedValue, "HH:MM")) / msPerHr
result = fullTime - breakTime
result = fullTime
$ = Num2Time(gmtOffset + (result * msPerHr + 1), "HH:MM")
Thanks Jono, the problem I was having was not understanding all of LiveCycle's capabilities. I used that method and assigned the UTC offset for all airports and had it convert both user inputted times to UTC, calculate the difference and return hours comped. Thanks for the help.
As for the code you sent me radzmar I appreciate it, I already had so much code and starting over sounded like a daunting task so I went for the integrated method of boundItem. I'm sure your method would work (and probably be better than mine).
Europe, Middle East and Africa