Genesys CTI User Forum > Genesys-related Development
Problem with JS function at Composer
cavagnaro:
Hi guys,
Having a headache here...hope someone already come with similar stuff.
Lets see. I have a WS which returns a date in format
AppState.dataWS_Detalhe.dataEntrega = "2016-05-30T18:00:00.000-0300"
Now I call a JS function I declared
[code]
PassouDate(AppState.dataWS_Detalhe.dataEntrega.toString())
[/code]
The JS function is:
[code]
function PassouDate(date1)
{
var dataAtual = new Date();
var dataWS = new Date(date1);
if(dataWS > dataAtual)
return 1; //Ainda nao passou
else
return 0 + ' ' + dataAtual + ' vs ' + dataWS + ' from ' + date1; //Passou
}
[/code]
Nothing from the other world...
Function always return 0 because the output is:
[quote]
0 Mon May 30 2016 11:38:23 GMT-0300 vs Invalid Date from 2016-05-30T18:00:00.000-0300
[/quote]
However if I execute the same exact logic and function from a browser it works as expected...returns 1 or 0 as date is treated as valid...
I already tried calling the function with
[code]
PassouDate(AppState.dataWS_Detalhe.dataEntrega)
[/code]
And have same exact problem...any clue why on earth??? Or a workaround?
hsujdik:
It seems that the AppState.dataWS_Detalhe.dataEntrega.toString() method has the following format:
YYYY-MM-DDTHH:mm:ss.sss-hhmm
Try to change to
YYYY-MM-DDTHH:mm:ss.sss-hh:mm (adding colon between hh and mm).
Seems the proper string notation for date as specified by ECMAScript Language (referenced on http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15 - section 15.9.1.15 [i]"Z is the time zone offset specified as “Z” (for UTC) or either “+” or “-” followed by a time expression [b]HH:mm[/b]"[/i])
Well, it is just a guess but I think that there's no harm to try it...
cavagnaro:
Tried:
2016-05-30T11:10:00.000
2016-05-30T11:10:00.000-03:00
Same problem...thanks for the idea
cavagnaro:
Have tried even simpler date formats and nothing, always get an Invalid Date message.
Funnier
Did this:
x = new Date().toISOString()
x = '2016-05-30T18:31:19.000Z'
Yay! yeah? I found the valid format...a Z you would say. So lets test!
y = new Date(x);
y = Invalid date
XD
This really sucks
again, testing all this on browser works without problems.
cavagnaro:
More news:
Found 3 valid formats so far:
2009,11,11
Fri Mar 25 2015 09:56:24 GMT+0100 (Tokyo Time)
Wed Mar 25 2015 09:56:24 GMT+0100
Can't find how to do the 2009,11,11 to include hh and mm
Navigation
[0] Message Index
[#] Next page
Go to full version