Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

functions are used to implement logic using Java constructions.  We sometimes use functions in our DSLs to extend the Drools logic capability, or to perform calculations that are difficult to do directly in the Drools language.

Here is an example of a function that we use to logically remove the time portion of a date-time value, which is useful when you are doing things like counting the number of distinct dates when a particular event happened:

 

function java.util.Date stripTimeComponent (java.util.Date dateTime)

{

/*

Returns a new java.util.Date which contains only the year month day components of the submitted java.util.Date,

and sets the hours, minutes, seconds and milliseconds components to 0, which makes it reference midnight of that date.  

Returns null if sent in null.

*/

    if (dateTime == null)

    {

        return null;

    }

 

    org.opencds.common.utilities.DateUtility dateUtility = org.opencds.common.utilities.DateUtility.getInstance();

    String dateAsString = dateUtility.getDateAsString(dateTime, "yyyy-MM-dd");

    return dateUtility.getDateFromString(dateAsString, "yyyy-MM-dd");

}

 

  • No labels