dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18098
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7490: Impl iso dates in periodType.js lib
------------------------------------------------------------
revno: 7490
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-07-02 21:27:19 +0200
message:
Impl iso dates in periodType.js lib
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/login.css
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js
dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.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-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java 2012-05-04 16:36:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java 2012-07-02 19:27:19 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -38,6 +40,8 @@
public class BiMonthlyPeriodType
extends CalendarPeriodType
{
+ private static final String ISO_FORMAT = "yyyyMMB";
+
/**
* The name of the BiMonthlyPeriodType, which is "BiMonthly".
*/
@@ -154,18 +158,26 @@
@Override
public String getIsoDate( Period period )
{
- return null; // TODO
+ return new SimpleDateFormat( "yyyyMM" ).format( period.getStartDate() ) + "B";
}
@Override
public Period createPeriod( String isoDate )
{
- return null; // TODO
+ try
+ {
+ Date date = new SimpleDateFormat( "yyyyMM" ).parse( isoDate.substring( 0, 6 ) );
+ return createPeriod( date );
+ }
+ catch ( ParseException ex )
+ {
+ throw new RuntimeException( ex );
+ }
}
@Override
public String getIsoFormat()
{
- return null; // TODO
+ return ISO_FORMAT;
}
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2012-04-01 12:04:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2012-07-02 19:27:19 +0000
@@ -291,6 +291,10 @@
{
return new SixMonthlyPeriodType();
}
+ if ( isoPeriod.matches( "\\b\\d{6}B\\b" ) )
+ {
+ return new BiMonthlyPeriodType();
+ }
return null;
}
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java 2012-07-02 19:27:19 +0000
@@ -34,17 +34,18 @@
import static junit.framework.Assert.assertEquals;
/**
- *
+ *
* @author bobj
*/
-public class StringFormatTest {
+public class StringFormatTest
+{
private static Date getDate( int year, int month, int day )
{
final Calendar calendar = Calendar.getInstance();
// override locale settings for weeks
- calendar.setFirstDayOfWeek( Calendar.MONDAY);
+ calendar.setFirstDayOfWeek( Calendar.MONDAY );
calendar.setMinimalDaysInFirstWeek( 4 );
calendar.clear();
@@ -56,22 +57,25 @@
@Test
public void testStringFormat()
{
- Period day1 = new Period(new DailyPeriodType(),getDate(2010,1,1), getDate(2010,1,1));
- //Period week52 = new Period(new WeeklyPeriodType(),getDate(2009,12,21), getDate(2009,12,27));
- //Period week53 = new Period(new WeeklyPeriodType(),getDate(2009,12,28), getDate(2010,1,3));
- //Period week1 = new Period(new WeeklyPeriodType(),getDate(2010,1,4), getDate(2010,1,11));
- Period month1 = new Period(new MonthlyPeriodType(),getDate(2010,1,1), getDate(2010,1,1));
- Period year1 = new Period(new YearlyPeriodType(),getDate(2010,1,1), getDate(2010,1,1));
- Period quarter1 = new Period(new QuarterlyPeriodType(),getDate(2010,1,1), getDate(2010,1,1));
- Period semester1 = new Period(new SixMonthlyPeriodType(),getDate(2010,1,1), getDate(2010,1,1));
+ Period day1 = new Period( new DailyPeriodType(), getDate( 2010, 1, 1 ), getDate( 2010, 1, 1 ) );
+ Period month1 = new Period( new MonthlyPeriodType(), getDate( 2010, 1, 1 ), getDate( 2010, 1, 31 ) );
+ Period year1 = new Period( new YearlyPeriodType(), getDate( 2010, 1, 1 ), getDate( 2010, 12, 31 ) );
+ Period quarter1 = new Period( new QuarterlyPeriodType(), getDate( 2010, 1, 1 ), getDate( 2010, 3, 31 ) );
+ Period semester1 = new Period( new SixMonthlyPeriodType(), getDate( 2010, 1, 1 ), getDate( 2010, 6, 30 ) );
+ Period biMonth1 = new Period( new BiMonthlyPeriodType(), getDate( 2010, 3, 1 ), getDate( 2010, 4, 30 ) );
- assertEquals("Day format", "20100101", day1.getIsoDate());
- //assertEquals("Week format", "2009W52", week52.getIsoDate());
- //assertEquals("Week format", "2009W53", week53.getIsoDate());
- //assertEquals("Week format", "2010W1", week1.getIsoDate());
- assertEquals("Month format", "201001", month1.getIsoDate());
- assertEquals("Year format", "2010", year1.getIsoDate());
- assertEquals("Quarter format", "2010Q1", quarter1.getIsoDate());
- assertEquals("Semester format", "2010S1", semester1.getIsoDate());
+ assertEquals( "Day format", "20100101", day1.getIsoDate() );
+ assertEquals( "Month format", "201001", month1.getIsoDate() );
+ assertEquals( "Year format", "2010", year1.getIsoDate() );
+ assertEquals( "Quarter format", "2010Q1", quarter1.getIsoDate() );
+ assertEquals( "Semester format", "2010S1", semester1.getIsoDate() );
+ assertEquals( "Bimonth format", "201003B", biMonth1.getIsoDate() );
+
+ assertEquals( day1, PeriodType.getPeriodFromIsoString( "20100101" ) );
+ assertEquals( month1, PeriodType.getPeriodFromIsoString( "201001" ) );
+ assertEquals( year1, PeriodType.getPeriodFromIsoString( "2010" ) );
+ assertEquals( quarter1, PeriodType.getPeriodFromIsoString( "2010Q1" ) );
+ assertEquals( semester1, PeriodType.getPeriodFromIsoString( "2010S1" ) );
+ assertEquals( biMonth1, PeriodType.getPeriodFromIsoString( "201003B" ) );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/login.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/login.css 2012-07-02 10:21:54 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/login.css 2012-07-02 19:27:19 +0000
@@ -68,7 +68,7 @@
border-width: 1px;
border-color: #D0D0D0;
padding: 11px;
- margin-top: 20px;
+ margin: 20px 15px 0 15px;
display: block;
width: 280px;
border-radius: 2px;
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js 2012-06-30 11:46:08 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/periodType.js 2012-07-02 19:27:19 +0000
@@ -67,6 +67,7 @@
period['endDate'] = startDate.format( dateFormat );
period['name'] = startDate.format( dateFormat );
period['id'] = 'Daily_' + period['startDate'];
+ period['iso'] = startDate.format( 'yyyyMMdd' );
periods[i] = period;
startDate.adjust( 'D', +1 );
@@ -110,6 +111,7 @@
period['endDate'] = endDate.format( dateFormat );
period['name'] = 'W' + ( i + 1 ) + ' - ' + startDate.format( dateFormat ) + " - " + endDate.format( dateFormat );
period['id'] = 'Weekly_' + period['startDate'];
+ period['iso'] = year + 'W' + ( i + 1 );
periods[i] = period;
startDate.adjust( 'D', +7 );
@@ -138,6 +140,7 @@
period['endDate'] = endDate.format( dateFormat );
period['name'] = monthNames[i] + ' ' + year;
period['id'] = 'Monthly_' + period['startDate'];
+ period['iso'] = startDate.format( 'yyyyMM' );
periods[i] = period;
startDate.adjust( 'M', +1 );
@@ -167,6 +170,7 @@
period['endDate'] = endDate.format( dateFormat );
period['name'] = monthNames[i] + ' - ' + monthNames[i + 1] + ' ' + year;
period['id'] = 'BiMonthly_' + period['startDate'];
+ period['iso'] = startDate.format( 'yyyyMM' ) + 'B';
periods[j] = period;
startDate.adjust( 'M', +2 );
@@ -197,6 +201,7 @@
period['endDate'] = endDate.format( dateFormat );
period['name'] = monthNames[i] + ' - ' + monthNames[i + 2] + ' ' + year;
period['id'] = 'Quarterly_' + period['startDate'];
+ period['iso'] = year + 'Q' + ( j + 1 );
periods[j] = period;
startDate.adjust( 'M', +3 );
@@ -221,6 +226,7 @@
period['endDate'] = year + '-06-30';
period['name'] = monthNames[0] + ' - ' + monthNames[5] + ' ' + year;
period['id'] = 'SixMonthly_' + period['startDate'];
+ period['iso'] = year + 'S1';
periods[0] = period;
period = [];
@@ -228,6 +234,7 @@
period['endDate'] = year + '-12-31';
period['name'] = monthNames[6] + ' - ' + monthNames[11] + ' ' + year;
period['id'] = 'SixMonthly_' + period['startDate'];
+ period['iso'] = year + 'S2';
periods[1] = period;
return periods;
@@ -250,6 +257,7 @@
period['endDate'] = endDate.format( dateFormat );
period['name'] = startDate.date().getFullYear();
period['id'] = 'Yearly_' + period['startDate'];
+ period['iso'] = year;
periods[i] = period;
startDate.adjust( 'Y', +1 );
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java 2012-06-28 21:14:29 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ExportTableAction.java 2012-07-02 19:27:19 +0000
@@ -166,6 +166,8 @@
params.putAll( reportTable.getOrganisationUnitGroupMap( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() ) );
}
+ //TODO stop putting in memory, too expensive
+
if ( useLast )
{
grid = (Grid) SessionUtils.getSessionVar( SessionUtils.KEY_REPORT_TABLE_GRID );