Time Calculations

421 views
Skip to first unread message

SmiffySan

unread,
Jan 13, 2012, 11:07:45 AM1/13/12
to Adobe LiveCycle Developers
Hi Everyone, I'm reasonably new to ES so I hope you'll bear with me. I
have created a timesheet and after some headaches I have worked out
how to calculate between times with the following code:


var EndTime = Time2Num(DateTimeField1.formattedValue, "HH:MM")
var StartTime = Time2Num(DateTimeField2.formattedValue, "HH:MM")
var Diff = EndTime - StartTime
Diff = Diff / 1000
var Minutes = Diff / 60
var Hours = Minutes / 60
Hours = Floor(Hours)
Minutes = Mod(Minutes, 60)
Concat(Hours, ":", Format("99", Minutes))

Where the two time fields are TimeDate and the calcuation runs from a
TextBox. And there's the issue. I really need to add a column up of
hours and minutes from the results, but, I cannot add texts, so if
anyone can assist, I would be very relieved.

Thanks

SmiffySan

Ed Mcallister

unread,
Jan 17, 2012, 3:49:45 AM1/17/12
to live...@googlegroups.com
Hi Fred, Thanks for answering. I do understand this is for developers
and I've been pressed into this work, so I really appreciate this.

Okay. I have created an on call claim form that the claimant puts in a
start time and and end time. These are in numeric fields. The result
however is shown in a text field, primarily because I couldn't figure
out any other way to do it. The claimant makes a series of claims and
the results are in a column. I simple do not know if it's possible to
add the results of text boxes to give a numerical answer, and if it is
possible, I don't know how to do it. Would it help if I sent the form
to your gmail.

Many thanks

SmiffySan

On 16/01/2012, fred.pantalone <fred.pa...@gmail.com> wrote:
> I think you need to clarify what your problem is. Why can't you add a
> column of text fields?
>
> Fred

> --
> You received this message because you are subscribed to the Google Groups
> "Adobe LiveCycle Developers" group.
> To post to this group, send email to live...@googlegroups.com.
> To unsubscribe from this group, send email to
> livecycle+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/livecycle?hl=en.
>
>

fred.pantalone

unread,
Jan 17, 2012, 3:07:49 PM1/17/12
to Adobe LiveCycle Developers
Ok, I get it: You've got a column of text fields that have the hours
and minutes (e.g. 1:30) for each line item (i.e. each "on call" claim)
and you need to add them up at the bottom for the total hours and
minutes. Here's what I would do:

-add a hidden column with numeric or text fields (it doesn't really
matter) and calculate and store the "diff" time in these fields, in ms
-the column that displays the hours:minutes uses this value
-for the grand total, add all of the "diff" values (stored in ms) and
then do the same as your code above to put it into hours and minutes
-there would be a quick way to do this with FormCalc instead of
JavaScript but I'm no FormCalc expert so I would do it the old-
fashioned way, in JavaScript, looping on the rows

Is this clear?

Fred



On Jan 17, 3:49 am, Ed Mcallister <eamy.sm...@gmail.com> wrote:
> Hi Fred, Thanks for answering. I do understand this is for developers
> and I've been pressed into this work, so I really appreciate this.
>
> Okay. I have created an on call claim form that the claimant puts in a
> start time and and end time. These are in numeric fields. The result
> however is shown in a text field, primarily because I couldn't figure
> out any other way to do it. The claimant makes a series of claims and
> the results are in a column. I simple do not know if it's possible to
> add the results of text boxes to give a numerical answer, and if it is
> possible, I don't know how to do it. Would it help if I sent the form
> to your gmail.
>
> Many thanks
>
> SmiffySan
>

Ed Mcallister

unread,
Jan 18, 2012, 5:29:55 AM1/18/12
to live...@googlegroups.com
Hi Fred,

Sort of clear, I'll do some research on 'diff' and give it a try.

Kind regards

Ed

fred.pantalone

unread,
Jan 19, 2012, 1:43:44 PM1/19/12
to Adobe LiveCycle Developers

Here's the calculate script the hidden field should have (let's call
it "rawClaimTime"):

var EndTime = Time2Num(DateTimeField1.formattedValue, "HH:MM")
var StartTime = Time2Num(DateTimeField2.formattedValue, "HH:MM")
EndTime - StartTime

Here's the calculate script the visible "HH:MM" field should have:

var claimTime = rawClaimTime.rawValue
claimTime = claimTime / 1000
var Minutes = claimTime / 60
var Hours = Minutes / 60
Hours = Floor(Hours)
Minutes = Mod(Minutes, 60)
Concat(Hours, ":", Format("99", Minutes))

For your grand total field, loop through each instance of
"rawClaimTime". Some pseudocode:

var totalClaimTime = 0;

for each ( rawClaimTime object )
{
totalClaimTime += rawClaimTime.rawValue
}

totalClaimTime = totalClaimTime / 1000
var Minutes = totalClaimTime / 60
var Hours = Minutes / 60
Hours = Floor(Hours)
Minutes = Mod(Minutes, 60)
Concat(Hours, ":", Format("99", Minutes))







On Jan 18, 5:29 am, Ed Mcallister <eamy.sm...@gmail.com> wrote:
> Hi Fred,
>
> Sort of clear, I'll do some research on 'diff' and give it a try.
>
> Kind regards
>
> Ed
>

Ed Mcallister

unread,
Jan 20, 2012, 5:04:20 AM1/20/12
to live...@googlegroups.com
Thanks Fred, you're a star. I'll get on at this afternoon.

Kind regards

Ed (Smiffysan)

rxa

unread,
May 20, 2013, 10:21:15 AM5/20/13
to live...@googlegroups.com
Any chance of a real-world example rather than the pseudocode?

I can't get my small mind around the loop :P trying hard!

fred.pantalone

unread,
Jan 16, 2012, 10:13:22 AM1/16/12
to Adobe LiveCycle Developers
I think you need to clarify what your problem is. Why can't you add a
column of text fields?

Fred




On Jan 13, 11:07 am, SmiffySan <eamy.sm...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages