cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing date javascript alfresco

aitbenmouh
Champ in-the-making
Champ in-the-making
Hello,

Im developping a custom validator of a date input in my workflow form and i get null after parsing a date this is what i done:

// check dates can be parsed i get succefully my dates in a format : 2013-07-14T00:00:00.000+01:00 

      str_expiryDate = field.form.prop_wfbxTestWorkFlow_NfDate.value;
      console.log("Non conformite"+str_expiryDate);

      str_reminderDate = field.form.prop_bpm_workflowDueDate.value;
       console.log("echeance"+str_reminderDate);

      Alfresco.logger.warn("Expiry Date: " + str_expiryDate + " | Reminder Date: " + str_reminderDate);
//parsing date to compare the two dates i get null with utils.fromIso.. and get the some with parse function
                var origDate = utils.fromISO8601(str_expiryDate);
      console.log("nouvelle conversion"+origDate);
      d_expiryDate = Date.parse(str_expiryDate);
      console.log("nfDate"+d_expiryDate);

      d_reminderDate = Date.parse(str_reminderDate);
      console.log("Date echéance"+d_reminderDate);
         

Waiting your help thanks.
Edited:

I found in mozilla api that i have to include the module where functions are defined so i want to include this module how i can do it because when i put this
Components.utils.import("resource://gre/modules/ISO8601DateUtils.jsm");Uncaught ReferenceError: Components is not defined

I get the error above my js script is in /share/js/script.js can someone help where we do import of javascript modules ?
6 REPLIES 6

aitbenmouh
Champ in-the-making
Champ in-the-making
Now i sure that it's not a problem of import, the problem is the format of date that i give as parameter to parse() function so the datepicker gives me this format :
2013-06-13T00:00:00.000+01:00 

and so when i pass it to parse() function it returns null. !
So how to format my date to be accepted by parse function Or if there is a good solution to compare two date show me it thanks all.

abarisone
Star Contributor
Star Contributor

aitbenmouh
Champ in-the-making
Champ in-the-making
Thanks for answer i tried this
var origDate = utils.fromISO8601(str_expiryDate); console.log("nouvelle conversion"+origDate);

When i debug it, it treat (utils.utils.fromISO8601()) as an unknown expression !!

aitbenmouh
Champ in-the-making
Champ in-the-making
Resolved it like this, i created a function


    function dateFromISO8601(isostr) {
       var parts = isostr.match(/\d+/g);
       return new Date(parts[0], parts[1] - 1, parts[2], parts[3], parts[4], parts[5]);
    }

and then i call it to parse my date like this :

    d_expiryDate = dateFromISO8601(str_expiryDate);
          console.log("nfDate"+d_expiryDate);
   
          d_reminderDate = dateFromISO8601(str_reminderDate);
          console.log("Date echéance"+d_reminderDate);

And then the result gives :

    nfDateSat Jun 29 2013 00:00:00 GMT+0100 (Afr. centrale Ouest) formValidation-min.js:51
    Date echéanceWed Jun 05 2013 00:00:00 GMT+0100 (Afr. centrale Ouest)

Wish that can help others thanks.

zladuric
Champ on-the-rise
Champ on-the-rise
Just for the record,
util
is part of Alfresco's Javascript API, so it's not available on the client side. On the client you can just include something like date.js and have it handle dates for you, or write a custom method like you did.

ddraper
World-Class Innovator
World-Class Innovator
FYI… the alfresco.js file (which is included on every page in Share) has a number of date/time helper functions including:

Alfresco.util.isDate
Alfresco.util.formatDate
Alfresco.util.fromISO8601
Alfresco.util.parseTime
Alfresco.util.toISO8601
Alfresco.util.fromExplodedJSONDate
Alfresco.util.toExplodedJSONDate
Alfresco.util.renderRelativeTime
Alfresco.util.relativeTime
Alfresco.util.relativeDate

These ARE available on the client side.