Genesys CTI User Forum > Genesys-related Development

Problem with JS function at Composer

<< < (3/3)

cavagnaro:
Using MCP 8.5
Had the hope that an upgrade would help too but no luck


Enviado de meu E6633 usando Tapatalk

hsujdik:
So, I'm far from being a good developer, but find below an attempt for a function that parses the date in ISO8601 (such as your WS return example).

[code]
function parseISO8601(strISO8601Date) {
var dateRegExp = /^([0-9]{4})-([0-9]{2})-([0-9]{2})(T([0-9]{2}):([0-9]{2}):([0-9]{2})\.([0-9]{3})(Z|[-+][0-9]{2}:?[0-9]{2}))?$/i;
var match = dateRegExp.exec(strISO8601Date);
var year = parseInt(match[1]);
var month = parseInt(match[2]);
var day = parseInt(match[3]);
var hasTime = match[4];
var hour;
var minute;
var second;
var mils;
var tz;
var mydate;
if (hasTime && (typeof hasTime != 'undefined')) {
  hour = parseInt(match[5]);
  minute = parseInt(match[6]);
  second = parseInt(match[7]);
  mils = parseInt(match[8]);
  tz = match[9];
  mydate = new Date(year, month-1, day, hour, minute, second, mils);
  if ("Z" === tz.toUpperCase()) {
  mydate.setTime(mydate.getTime() - mydate.getTimezoneOffset() * 60000);
  } else {
  tz = tz.replace(":","");
  var tzhour = parseInt(tz.substr(1,2));
  var tzmin = parseInt(tz.substr(3,2));
  var tzOffset = (tz.substr(0,1) === "+") ? ((tzhour * 3600000) + (tzmin * 60000)) : -((tzhour * 3600000) + (tzmin * 60000));
  var diff =  -tzOffset - (mydate.getTimezoneOffset() * 60000);
  mydate.setTime(mydate.getTime() + diff);
  }
} else {
  mydate = new Date(year, month-1, day);
}
return mydate;
}
[/code]

If you can try it out on MCP and post results that would be great as I don't have a lab ready for this kind of testing (although I have tested against FireFox without problems).

cavagnaro:
Nice ;) but I ended up doing something simpler, need to think on guys who will support this

[code]
function PassouDate(date1)
{
//06 09 2007 17:46:21 OK
//date1 = 2016-04-18T03:00:00.000+0000

var YYYY = date1.substr(0,4);
var MM = date1.substr(5,2);
var DD = date1.substr(8,2);
var HHMMSS = date1.substr(11,8);

date1 = YYYY + ' ' + MM + ' ' + DD + ' ' + HHMMSS;

var dataAtual = new Date();
var dataWS = new Date(date1);

if(dataWS > dataAtual)
return 1; //Ainda nao passou
else
return 0; //Passou

}
[/code]

Navigation

[0] Message Index

[*] Previous page

Go to full version