------------------------------------------------------------ revno: 17532 committer: Lars Helge Overland <larshe...@gmail.com> branch nick: dhis2 timestamp: Wed 2014-11-19 12:34:01 +0100 message: Date util method modified: dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java 2014-11-18 08:48:59 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java 2014-11-19 11:34:01 +0000 @@ -135,6 +135,24 @@ } /** + * Returns the latest of the given dates. + * + * @param date the dates. + * @return the latest of the given dates. + */ + public static Date max( Date... date ) + { + Date latest = null; + + for ( Date d : date ) + { + latest = max( d, latest ); + } + + return latest; + } + + /** * Formats a Date to the format YYYY-MM-DD. * * @param date the Date to parse. === modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java' --- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java 2014-11-18 08:48:59 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java 2014-11-19 11:34:01 +0000 @@ -84,4 +84,25 @@ assertNull( DateUtils.max( date3, date4 ) ); } + + @Test + public void testMaxArray() + { + Date date1 = new DateTime( 2014, 5, 15, 3, 3 ).toDate(); + Date date2 = new DateTime( 2014, 5, 18, 1, 1 ).toDate(); + Date date3 = new DateTime( 2014, 6, 10, 1, 1 ).toDate(); + Date date4 = null; + Date date5 = null; + Date date6 = null; + + assertEquals( date2, DateUtils.max( date1, date2, date4 ) ); + assertEquals( date2, DateUtils.max( date2, date1, date4 ) ); + assertEquals( date3, DateUtils.max( date1, date2, date3 ) ); + assertEquals( date3, DateUtils.max( date1, date2, date3 ) ); + assertEquals( date3, DateUtils.max( date3, date4, date5 ) ); + assertEquals( date4, DateUtils.max( date4, date5, date6 ) ); + assertEquals( date1, DateUtils.max( date1, date5, date4 ) ); + + assertNull( DateUtils.max( date4, date5, date6 ) ); + } }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp