It's all about the answers!

Ask a question

How to convert an ISO string to the date object?


Aishwarya Sureban (33113) | asked Jul 13 '18, 6:08 a.m.
edited Jul 13 '18, 6:29 a.m. by Ralph Schoon (63.1k33645)

 How to convert an ISO string to the date object? 

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Jul 13 '18, 6:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Aishwarya Sureban selected this answer as the correct answer

Comments
Aishwarya Sureban commented Jul 13 '18, 6:47 a.m.

Thank you for the update. 

I tried to convert date object to string. 
Now, I want to convert this string '2014-11-03T19:38:34.203Z ', to the date object through coding. Can you assist me on this, as this part is not available on the link you had shared.? 

One other answer



permanent link
Ralph Schoon (63.1k33645) | answered Jul 13 '18, 7:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The api explains how to use the conversion to dojo.date/dojo.date/stamp

That is all you really need. For how to work with that I would suggest to search the web.

Conversion to other date see https://www.w3schools.com/jsref/jsref_obj_date.asp

Here an example how I use the dojo objects

/***********
  Licensed Materials - Property of IBM
 
(c) Copyright IBM Corporation 2011. All Rights Reserved.
 
 
Note to U.S. Government Users Restricted Rights:  
  Use, duplication or disclosure restricted by GSA ADP Schedule
 
Contract with IBM Corp.
 ***********
/
dojo.provide("org.example.DateValidator");

dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings

/
 

  You need to configure this script in the Process Configuration Source:
 
    <validator id="dateval" name="Date Validator" providerId="com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider">
          <script class="org.example.DateValidator" path="/workitem/scripts/common/DateValidator.js"/>
 
        <parameters beginDateAttributeId="startdate" message="The completion date can not be earlier than the start date" severity="ERROR"/>
      </validator>
 

 */
(function() {
var Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;

var DateValidator = dojo.declare("org.example.DateValidator", null, {

    validate: function(attributeId, workItem, configuration) {
    
        // Get the configuration parameters about the severity and error message of this validator
        var severity= configuration.getChild("parameters").getStringDefault("severity", Severity.ERROR.name);
        var message= configuration.getChild("parameters").getStringDefault("message", "");
        
        // Get the begin date attribute from the configuration and make a Date object from it
        var beginDateId = configuration.getChild("parameters").getStringDefault("beginDateAttributeId", "");
        var beginDate = dojo.date.stamp.fromISOString(workItem.getValue(beginDateId));
        
        // Get the current attribute's value and make a Date object from it
        var endDate= dojo.date.stamp.fromISOString(workItem.getValue(attributeId));
        
        // Compare the two dates and make sure endDate is not earlier than beginDate
        if (dojo.date.compare(endDate, beginDate) >= 0) {
            return Status.OK_STATUS;
        } else {
            return new Status(Severity[severity], message);
        }
    }
});
})();


Comments
Aishwarya Sureban commented Jul 13 '18, 7:33 a.m.

Thank you Ralph, for your support. 

Your answer


Register or to post your answer.