I think I did it after all. It turns out taking a break for 30 minutes can help when (psydo)coding. Sorry for polluting this list and here's the code that did it:<br><br><action application="javascript" data="unixtocal.js ${created_time}"/><br>
<br>var date = new Date(argv/1000);<br>var hours = date.getHours();<br>hours = hours.toString();<br>var minutes = date.getMinutes();<br>minutes = minutes.toString();<br>var seconds = date.getSeconds();<br>seconds = seconds.toString();<br>
var ms = date.getMilliseconds();<br>ms = ms.toString();<br>var year = date.getFullYear();<br>year = year.toString();<br>var day = date.getDate();<br>day = day.toString();<br>var month = date.getMonth() +1;<br>month = month.toString();<br>
<br>the rest was OK<br><br><div class="gmail_quote">On Thu, Oct 25, 2012 at 6:48 AM, George Diamantopoulos <span dir="ltr"><<a href="mailto:georgediam@gmail.com" target="_blank">georgediam@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br><br>I've been trying to write a simple JS script, which is called from within the XML dialplan, in order to convert the value of ${created_time} to something more meaningful than UNIX time in ms. The problem is when I try to print something to the console (see log application below), I get NaN (not a number) for variable ${created_date}, even though I don't want a number (a string is fine, I tried enforcing this with toString()). Moreover, you'll notice I've left out var month = date.getMonth();, because if I don't I get the following error: TypeError: date.getMonth is not a function. I can't figure out why, it's documented in JS in the date object, and the syntax is identical to other functions I use to acquire object values. Any hints would be greatly appreciated, I've been trying different code variations for over two hours now and I'm stuck. Thanks.<br>
<br>Here's the call in the dialplan:<br><br><action application="javascript" data="unixtocal.js $created_time"/><br><br>And here's the JS script itself:<br><br>var date = new Date(argv);<br>
var hours = date.getHours();<br>hours = hours.toString();<br>var minutes = date.getMinutes();<br>minutes = minutes.toString();<br>var seconds = date.getSeconds();<br>seconds = seconds.toString();<br>var ms = date.getMilliseconds();<br>
ms = ms.toString();<br>var year = date.getFullYear();<br>year = year.toString();<br>var day = date.getDate();<br>day = day.toString();<br><br>session.execute("set", "created_year="+year);<br>session.execute("set", "created_date="+day);<br>
session.execute("set", "created_hours="+hours);<br>session.execute("set", "created_minutes="+minutes);<br>session.execute("set", "created_seconds="+seconds);<br>
session.execute("set", "created_ms="+ms);<br><br>Then the dialplan takes over again, for example:<br><br><action application="log" data="INFO Date is ${created_date}"/><br>
</blockquote></div><br>