diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/calculator/StandardFunctions.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/calculator/StandardFunctions.java index 3f35039e5a26294a6359f0ec58a54bd85d4c0fbd..7fbf9aa85b8618f99bc5435c3826e5955eb2167d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/calculator/StandardFunctions.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/calculator/StandardFunctions.java @@ -17,6 +17,8 @@ package ch.systemsx.cisd.openbis.generic.shared.calculator; import java.io.StringReader; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -79,12 +81,10 @@ public final class StandardFunctions } /** - * Returns the specified value as an integer. Returns the smallest integer if <code>value</code> - * is <code>null</code> or its trimmed <code>toString()</code> representation is an empty - * string. + * Returns the specified value as an integer. Returns the smallest integer if <code>value</code> is <code>null</code> or its trimmed + * <code>toString()</code> representation is an empty string. * - * @throws NumberFormatException if <code>value.toString()</code> can not be parsed as an - * integer. + * @throws NumberFormatException if <code>value.toString()</code> can not be parsed as an integer. */ public static Integer toInt(Object value) { @@ -92,12 +92,10 @@ public final class StandardFunctions } /** - * Returns the specified value as an integer. Returns <code>defaultValue</code> if - * <code>value</code> is <code>null</code> or its trimmed <code>toString()</code> representation - * is an empty string. + * Returns the specified value as an integer. Returns <code>defaultValue</code> if <code>value</code> is <code>null</code> or its trimmed + * <code>toString()</code> representation is an empty string. * - * @throws NumberFormatException if <code>value.toString()</code> can not be parsed as an - * integer. + * @throws NumberFormatException if <code>value.toString()</code> can not be parsed as an integer. */ public static Integer toInt(Object value, Integer defaultValue) { @@ -110,12 +108,10 @@ public final class StandardFunctions } /** - * Returns the specified value as a floating-point number. Returns the smallest floating-point - * number if <code>value</code> is <code>null</code> or its trimmed <code>toString()</code> - * representation is an empty string. + * Returns the specified value as a floating-point number. Returns the smallest floating-point number if <code>value</code> is <code>null</code> + * or its trimmed <code>toString()</code> representation is an empty string. * - * @throws NumberFormatException if <code>value.toString()</code> can not be parsed as a - * floating-point number. + * @throws NumberFormatException if <code>value.toString()</code> can not be parsed as a floating-point number. */ public static Double toFloat(Object value) { @@ -123,12 +119,10 @@ public final class StandardFunctions } /** - * Returns the specified value as a floating-point number. Returns <code>defaultValue</code> if - * <code>value</code> is <code>null</code> or its trimmed <code>toString()</code> representation - * is an empty string. + * Returns the specified value as a floating-point number. Returns <code>defaultValue</code> if <code>value</code> is <code>null</code> or its + * trimmed <code>toString()</code> representation is an empty string. * - * @throws NumberFormatException if <code>value.toString()</code> can not be parsed as a - * floating-point number. + * @throws NumberFormatException if <code>value.toString()</code> can not be parsed as a floating-point number. */ public static Double toFloat(Object value, Double defaultValue) { @@ -141,8 +135,7 @@ public final class StandardFunctions } /** - * Returns <code>thenValue</code> if <code>condition == true</code> otherwise - * <code>elseValue</code> is returned. + * Returns <code>thenValue</code> if <code>condition == true</code> otherwise <code>elseValue</code> is returned. * * @return <code>elseValue</code> if <code>condition == null</code>. */ @@ -152,8 +145,7 @@ public final class StandardFunctions } /** - * Calculates the sum of the specified values. Blank strings or <code>null</code> values in the - * list are ignored. + * Calculates the sum of the specified values. Blank strings or <code>null</code> values in the list are ignored. * * @throws NumberFormatException if an element can not be parsed as a floating-point number. * @throws IllegalArgumentException if the list is empty. @@ -172,8 +164,7 @@ public final class StandardFunctions } /** - * Calculates the mean of the specified values. Blank strings or <code>null</code> values in the - * list are ignored. + * Calculates the mean of the specified values. Blank strings or <code>null</code> values in the list are ignored. * * @throws NumberFormatException if an element can not be parsed as a floating-point number. * @throws IllegalArgumentException if the list is empty. @@ -191,8 +182,7 @@ public final class StandardFunctions } /** - * Calculates the standard deviation of the specified values. Blank strings or <code>null</code> - * values in the list are ignored. + * Calculates the standard deviation of the specified values. Blank strings or <code>null</code> values in the list are ignored. * * @throws NumberFormatException if an element can not be parsed as a floating-point number. * @throws IllegalArgumentException if the list is empty. @@ -215,8 +205,7 @@ public final class StandardFunctions } /** - * Calculates the median of the specified values. Blank strings or <code>null</code> values in - * the list are ignored. + * Calculates the median of the specified values. Blank strings or <code>null</code> values in the list are ignored. * * @throws NumberFormatException if an element can not be parsed as a floating-point number. * @throws IllegalArgumentException if the list is empty. @@ -231,8 +220,7 @@ public final class StandardFunctions } /** - * Calculates the minimum of the specified values. Blank strings or <code>null</code> values in - * the list are ignored. + * Calculates the minimum of the specified values. Blank strings or <code>null</code> values in the list are ignored. * * @throws NumberFormatException if an element can not be parsed as a floating-point number. * @throws IllegalArgumentException if the list is empty. @@ -246,8 +234,7 @@ public final class StandardFunctions } /** - * Calculates the maximum of the specified values. Blank strings or <code>null</code> values in - * the list are ignored. + * Calculates the maximum of the specified values. Blank strings or <code>null</code> values in the list are ignored. * * @throws NumberFormatException if an element can not be parsed as a floating-point number. * @throws IllegalArgumentException if the list is empty. @@ -338,6 +325,13 @@ public final class StandardFunctions return new Date(); } + /** Returns the given date as a formatted String */ + public static String getDateAsString(Date date) + { + DateFormat d = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + return d.format(date); + } + public static String createLink(String linkText, String linkUrl) { CustomColumnJSONServerData data = new CustomColumnJSONServerData(CustomColumnMethod.LINK); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/calculator/StandardFunctionsTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/calculator/StandardFunctionsTest.java index fda3754bb1dfdbe92389553ad9e100e8b2414eb3..807219d0b010f4d64a94a4cf299fa12c9b54e097 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/calculator/StandardFunctionsTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/calculator/StandardFunctionsTest.java @@ -43,6 +43,13 @@ import org.testng.annotations.Test; */ public class StandardFunctionsTest extends AssertJUnit { + @Test + public void testGetDateAsString() + { + Date date = new Date(1382785041979L); + assertEquals("2013-10-26 12:57:21", StandardFunctions.getDateAsString(date)); + } + @Test public void testCurrentDate() {