Parsing date javascript alfresco
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2013 06:40 AM
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:
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
I get the error above my js script is in /share/js/script.js can someone help where we do import of javascript modules ?
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 ?
Labels:
- Labels:
-
Archive
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2013 09:32 AM
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 :
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.
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2013 10:22 AM
Hi,
as reported here http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPI-JS-Ut... the date should be in this format
Other info here http://stackoverflow.com/questions/13198492/alfresco-tomcat6-and-javascript-handling-of-iso-date-str...
Take also a look to this scirpt https://init.mpg.de/share/service/script/org/alfresco/components/dashlets/activity-list.get
Regards,
Andrea
as reported here http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FAPI-JS-Ut... the date should be in this format
2011-11-28T17:06:51.477Z
to be successfully convertedOther info here http://stackoverflow.com/questions/13198492/alfresco-tomcat6-and-javascript-handling-of-iso-date-str...
Take also a look to this scirpt https://init.mpg.de/share/service/script/org/alfresco/components/dashlets/activity-list.get
Regards,
Andrea
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2013 11:29 AM
Thanks for answer i tried this
When i debug it, it treat (utils.utils.fromISO8601()) as an unknown expression !!
var origDate = utils.fromISO8601(str_expiryDate); console.log("nouvelle conversion"+origDate);
When i debug it, it treat (utils.utils.fromISO8601()) as an unknown expression !!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2013 11:45 AM
Resolved it like this, i created a function
and then i call it to parse my date like this :
And then the result gives :
Wish that can help others thanks.
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.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2013 02:24 PM
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2013 06:02 AM
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.
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.
