Is HOUR_SELECTED a floating-point number (e.g. 11.99999999999)? If so, you need 
to account for that in your comparison.

 

  --Don

 

 

From: asterisk-users [mailto:asterisk-users-boun...@lists.digium.com] On Behalf 
Of Dovid Bender
Sent: Thursday, February 13, 2020 4:47 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: [asterisk-users] Help with FUNC_MATH

 

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@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@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@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

Reply via email to