Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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: 


Code Block
languagejava
titleExample Drools Function
collapsetrue
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;

    }

 

...


    {
        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");

...

}

...


}


Most of the functions that we use for Drools were developed in the OpenCDS source code as java methods in the package opencds-guvnor-support/src/main/java/org/opencds/support/guvnor/GuvnorFunctionWorkup.java.