I think that the answer of this question should be obvious to me, but unfortunately it is not. Hopefully it’s only because it’s late and I’m a bit tired already.
It’s a macro for rounding a time value (hh:mm) to the next or last full quarter hour, depending on a modifier. The time value is being read form a field and the rounded value should be written back into the same field.
Here’s the protoype (with lots of debugging information for me):
\define RoundQHtest(Which Modifier)
<$set name="TimeStr" filter="[[$Which$]match[B]then{!!begin-time}else{!!end-time}]">
<$let Hours={{{ [<TimeStr>split[:]nth[1]] }}} Mins={{{ [<TimeStr>split[:]nth[2]] }}} MinsC={{{ [<Mins>subtract[1]] }}}>
Which: [$Which$]<br>
Modifier: [$Modifier$]<br>
<br>
~TimeStr: <<TimeStr>><br>
Hours: <<Hours>><br>
Minutes: <<Mins>><br>
Minutes-Calc: <<MinsC>><br>
<$let rest={{{ [<MinsC>remainder[15]] }}}>
Remainder: <<rest>><br>
<$let term1={{{ [<MinsC>subtract<rest>] }}} term1={{{ [<term1>compare:number:lt[10]addprefix[0]else<term1>] }}}>
term1: <<term1>><br>
<$let resultplus={{{ [<term1>add[15]] }}}>
result[+]: <<resultplus>><br>
result[-]: <<term1>><br>
<$let result={{{ [[$Modifier$]match[-]then<term1>else<resultplus>] }}}>
result: <<Hours>>:<<result>><br>
\end
This works basically. But after stripping out the debugging information, warpping it into this construct …
<$button><$action-setfield $field="begin-time" $value=<<RoundQHtemp Which:"E" Modifier:"-">> /> Begin-Time ~ ¼</$button>
… it fills the field with macro source code?
Here’s the stripped down version:
\define RoundQHtest(Which Modifier)
<$set name="TimeStr" filter="[[$Which$]match[B]then{!!begin-time}else{!!end-time}]">
<$let Hours={{{ [<TimeStr>split[:]nth[1]] }}} Mins={{{ [<TimeStr>split[:]nth[2]] }}} MinsC={{{ [<Mins>subtract[1]] }}}>
<$let rest={{{ [<MinsC>remainder[15]] }}}>
<$let term1={{{ [<MinsC>subtract<rest>] }}} term1={{{ [<term1>compare:number:lt[10]addprefix[0]else<term1>] }}}>
<$let resultplus={{{ [<term1>add[15]] }}}>
<$let result={{{ [[$Modifier$]match[-]then<term1>else<resultplus>] }}}>
<<Hours>>:<<result>>
\end
And the input-field:
Start:<$edit-text field="begin-time" size="2" tag="input" />
Maybe some of you could spot the mistake easily and please tell me what I’m doing wrong here? Thank you in advance.