class ScriptAddedFunctions {

  @SuppressWarnings( "fallthrough" )
  public static Object truncDate( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    // 2 arguments: truncation of dates to a certain precision
    //
    if ( ArgList.length == 2 ) {
      if ( isNull( ArgList[0] ) ) {
        return null;
      } else if ( isUndefined( ArgList[0] ) ) {
        return undefinedValue;
      }

      // This is the truncation of a date...
      // The second argument specifies the level: ms, s, min, hour, day, month, year
      //
      java.util.Date dArg1 = null;
      Integer level = null;
      try {
        dArg1 = (java.util.Date) ArgList[0];
        level = (Integer) ArgList[1];
      } catch ( Exception e ) {
        throw new RuntimeException( e.toString() );
      }
      return ScriptAddedFunctions.truncDate( dArg1, level );
    } else {
      throw new RuntimeException( "The function call truncDate requires 2 arguments: a date and a level (int)" );
    }
  }

}