← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6222: Impl dateutils method

 

------------------------------------------------------------
revno: 6222
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-03-08 15:30:26 +0100
message:
  Impl dateutils method
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedOrgUnitDataValueStore.java
  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-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedOrgUnitDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedOrgUnitDataValueStore.java	2012-02-29 12:26:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedOrgUnitDataValueStore.java	2012-03-08 14:30:26 +0000
@@ -228,7 +228,7 @@
                 "AND periodid IN ( " + getCommaDelimitedString( periodIds ) + " ) " +
                 "AND organisationunitid = " + organisationUnitId + " " +
                 "AND organisationunitgroupid IN ( " + getCommaDelimitedString( organisationUnitGroupIds ) + " )";
-            
+            System.out.println( sql );
             final ResultSet resultSet = holder.getStatement().executeQuery( sql );
             
             return mapper.getCollection( resultSet, new AggregatedOrgUnitIndicatorValueRowMapper() );

=== 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	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2012-03-08 14:30:26 +0000
@@ -36,6 +36,7 @@
 
 import org.apache.commons.validator.DateValidator;
 import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.period.PeriodType;
 import org.joda.time.DateTime;
 import org.joda.time.Days;
 
@@ -48,6 +49,7 @@
     public static final double DAYS_IN_YEAR = 365.0;
 
     private static final long MS_PER_DAY = 86400000;
+    private static final long MS_PER_S = 1000;
 
     /**
      * Formats a Date to the Access date format.
@@ -349,6 +351,19 @@
     }
 
     /**
+     * Returns the number of seconds until the next day at the given hour.
+     * @param hour the hour.
+     * @return number of seconds.
+     */
+    public static long getSecondsUntilTomorrow( int hour )
+    {
+        Calendar cal = PeriodType.createCalendarInstance();
+        cal.add( Calendar.DAY_OF_YEAR, 1 );
+        cal.set( Calendar.HOUR_OF_DAY, hour );
+        return ( cal.getTimeInMillis() - new Date().getTime() ) / MS_PER_S;        
+    }
+
+    /**
      * This method converts a string from the date format "yyyy-MM-dd" to
      * "dd-MMM-yyyy".
      * 

=== 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	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/DateUtilsTest.java	2012-03-08 14:30:26 +0000
@@ -58,4 +58,10 @@
         assertEquals( "10 mar 2010", convertDate( "2010-03-10" ).toLowerCase() );
         assertEquals( "Invalid", convertDate( "Invalid" ) );
     }
+    
+    @Test
+    public void testGetSecondsUntilTomorrow()
+    {
+        System.out.println( DateUtils.getSecondsUntilTomorrow( 3 ) );
+    }
 }