cancel
Showing results for 
Search instead for 
Did you mean: 

ISODateFormat in .js Controller - Lucene Search not working

shikarishambu
Champ in-the-making
Champ in-the-making
I want to convert dates passed as arguments to webscript into ISO 8601 format that Lucene search understands.

I tried to leverage the toISO8601 in Alfresco.js under webapps\share\js (this script is same as the one mentioned here http://blog.stevenlevithan.com/archives/date-time-format).

I keep getting invalid date error. My code is
var myDate = new Date('11/10/2009');
var newDate = myDate.format("isoDateTime");

Has anyone used this javascript and gotten it to work.

I then decided to try a different one that I found online

function padzero(n) {  
return n < 10 ? '0' + n : n;  
}  
function pad2zeros(n) { 
  if (n < 100) {  
    n = '0' + n; 
  } 
   if (n < 10) {
      n = '0' + n; 
     }
  return n;    

function toISOString(d) {
    return d.getUTCFullYear() + '-' +  padzero(d.getUTCMonth() + 1) + '-' + padzero(d.getUTCDate()) + 'T' + padzero(d.getUTCHours()) + ':' +  padzero(d.getUTCMinutes()) + ':' + padzero(d.getUTCSeconds());
}
function fnToISO(dt) {
    var nDate = new Date(dt);
    return(toISOString(nDate));
}


This code works if I were to call it as shown fnToISO('11/10/2009');


However it fails if I were to get it from the args

var myDate = args.createdFrom;
fnToISO(myDate); // fails - NaN-NaN-NaN

Any suggestions on how toget either of these to work?

TIA
1 REPLY 1

shikarishambu
Champ in-the-making
Champ in-the-making
chalk this one to ID10T issue.

If you specify the date in the URL as '11/11/2009' (with quotes) I think goes into the function as ''11/11/2009'' and fails.
If you specify the date in the URL as 11/11/2009 (without quotes) it goes thru'.