[asterisk-users] Help with FUNC_MATH

John Kiniston
Thu, 13 Feb 2020 17:01:51 -0000

Try using the STRFIME function instead of doing this by hand.

https://wiki.asterisk.org/wiki/display/AST/Function_STRFTIME

*%H*

The hour as a decimal number using a 24-hour clock (range 00 to 23).

*%I*

The hour as a decimal number using a 12-hour clock (range 01 to 12).

On Thu, Feb 13, 2020 at 3:49 AM Dovid Bender <dovid at telecurve.com>
wrote:

> Hi,
>
> I have some dialplan code that is trying to convert 12 hour time with
> AM/PM to 24 hour format. The code has something like this:
> Exten =>
>
2,1,ExecIf(${MATH(${HOUR_SELECTED}<12)}?Set(HOUR_SELECTED=${MATH(${HOUR_SELECTED}+12,int)}))
>
> Earlier on in the dialplan HOUR_SELECTED is set to 12. When they press
> option 2 they are selecting PM. If the time is from 1PM to 11PM then I want
> to add 12 to the number (so if it's 1 make it 13 etc.). When I run the
> above the logs show the result as false yet if the user sets HOUR_SELECTED
> to 12 then after this line of dialplan code it gets switched to 24. What am
> I doing wrong here?
>
> The exact DP code is:
> Exten => 2,     1, Noop(BEFORE CHECK HOUR_SELECTED is ${HOUR_SELECTED})
>  same =>        n,
>
ExecIf(${MATH(${HOUR_SELECTED}<12)}?Set(HOUR_SELECTED=${MATH(${HOUR_SELECTED}+12,int)}))
>  same =>        n, Noop(AFTER CHECK HOUR_SELECTED IS ${HOUR_SELECTED})
>
> And the output of the logs is:
> [Feb 13 10:46:18] VERBOSE[1580][C-00007bc6] pbx.c: Executing
> [2 at am_pm_select:1] NoOp("SIP/204.145.219.31-000081c6",
"BEFORE CHECK
> HOUR_SELECTED is 12") in new stack
> [Feb 13 10:46:18] DEBUG[1580][C-00007bc6] pbx_variables.c: Result of
> 'HOUR_SELECTED' is '12'
> [Feb 13 10:46:18] DEBUG[1580][C-00007bc6] pbx_variables.c: Function
> MATH(12<12) result is 'FALSE'
> [Feb 13 10:46:18] DEBUG[1580][C-00007bc6] pbx_variables.c: Result of
> 'HOUR_SELECTED' is '12'
> [Feb 13 10:46:18] DEBUG[1580][C-00007bc6] pbx_variables.c: Function
> MATH(12+12,int) result is '24'
> [Feb 13 10:46:18] DEBUG[1580][C-00007bc6] pbx.c: Launching 'ExecIf'
> [Feb 13 10:46:18] VERBOSE[1580][C-00007bc6] pbx.c: Executing
> [2 at am_pm_select:2] ExecIf("SIP/204.145.219.31-000081c6",
> "FALSE?Set(HOUR_SELECTED=24)") in new stack
> [Feb 13 10:46:18] DEBUG[1580][C-00007bc6] pbx_variables.c: Result of
> 'HOUR_SELECTED' is '24'
> [Feb 13 10:46:18] DEBUG[1580][C-00007bc6] pbx.c: Launching 'NoOp'
> [Feb 13 10:46:18] VERBOSE[1580][C-00007bc6] pbx.c: Executing
> [2 at am_pm_select:3] NoOp("SIP/204.145.219.31-000081c6",
"AFTER CHECK
> HOUR_SELECTED IS 24") in new stack
>
>
> TIA.
>
> Dovid
>
> --
> _____________________________________________________________________
> -- Bandwidth and Colocation Provided by http://www.api-digital.com --
>
> Check out the new Asterisk community forum at:
> https://community.asterisk.org/
>
> New to Asterisk? Start here:
>       https://wiki.asterisk.org/wiki/display/AST/Getting+Started
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users



--
A human being should be able to change a diaper, plan an invasion, butcher
a hog, conn a ship, design a building, write a sonnet, balance accounts,
build a wall, set a bone, comfort the dying, take orders, give orders,
cooperate, act alone, solve equations, analyze a new problem, pitch manure,
program a computer, cook a tasty meal, fight efficiently, die gallantly.
Specialization is for insects.
---Heinlein
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.digium.com/pipermail/asterisk-users/attachments/20200213/765cb198/attachment.html>