dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #18161
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7546: Impl iso dates (?) for financial years
------------------------------------------------------------
revno: 7546
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-07-09 17:34:16 +0200
message:
Impl iso dates (?) for financial years
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.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
--
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/FinancialAprilPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java 2012-07-09 15:34:16 +0000
@@ -40,6 +40,8 @@
*/
private static final long serialVersionUID = 8790198046182231889L;
+ private static final String ISO_FORMAT = "yyyyApril";
+
public static final String NAME = "FinancialApril";
@Override
@@ -53,4 +55,18 @@
{
return NAME;
}
+
+ @Override
+ public String getIsoDate( Period period )
+ {
+ Calendar cal = createCalendarInstance( period.getStartDate() );
+ int year = cal.get( Calendar.YEAR );
+ return String.valueOf( year ) + "April";
+ }
+
+ @Override
+ public String getIsoFormat()
+ {
+ return ISO_FORMAT;
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java 2012-07-09 15:34:16 +0000
@@ -40,6 +40,8 @@
*/
private static final long serialVersionUID = 5190072405972068226L;
+ private static final String ISO_FORMAT = "yyyyJuly";
+
public static final String NAME = "FinancialJuly";
@Override
@@ -53,4 +55,18 @@
{
return NAME;
}
+
+ @Override
+ public String getIsoDate( Period period )
+ {
+ Calendar cal = createCalendarInstance( period.getStartDate() );
+ int year = cal.get( Calendar.YEAR );
+ return String.valueOf( year ) + "July";
+ }
+
+ @Override
+ public String getIsoFormat()
+ {
+ return ISO_FORMAT;
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java 2012-07-09 15:34:16 +0000
@@ -40,6 +40,8 @@
*/
private static final long serialVersionUID = -1623576547899897811L;
+ private static final String ISO_FORMAT = "yyyyOct";
+
public static final String NAME = "FinancialOct";
@Override
@@ -53,4 +55,18 @@
{
return NAME;
}
+
+ @Override
+ public String getIsoDate( Period period )
+ {
+ Calendar cal = createCalendarInstance( period.getStartDate() );
+ int year = cal.get( Calendar.YEAR );
+ return String.valueOf( year ) + "Oct";
+ }
+
+ @Override
+ public String getIsoFormat()
+ {
+ return ISO_FORMAT;
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java 2012-05-04 16:36:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java 2012-07-09 15:34:16 +0000
@@ -72,7 +72,7 @@
{
boolean past = cal.get( Calendar.MONTH ) >= getBaseMonth();
- cal.set( Calendar.YEAR, past ? cal.get( Calendar.YEAR ) : cal.get( Calendar.YEAR ) - 1 );
+ cal.set( Calendar.YEAR, past ? ( cal.get( Calendar.YEAR ) + 1 ) : cal.get( Calendar.YEAR ) );
cal.set( Calendar.MONTH, getBaseMonth() );
cal.set( Calendar.DATE, 1 );
@@ -169,20 +169,12 @@
}
@Override
- public String getIsoDate( Period period )
- {
- return null; // TODO
- }
-
- @Override
public Period createPeriod( String isoDate )
{
- return null; // TODO
- }
-
- @Override
- public String getIsoFormat()
- {
- return null; // TODO
+ int year = Integer.parseInt( isoDate.substring( 0, 4 ) );
+ Calendar cal = createCalendarInstance();
+ cal.set( Calendar.YEAR, year );
+ cal.set( Calendar.DAY_OF_YEAR, 1 );
+ return createPeriod( cal );
}
}
=== 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-07-02 19:27:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2012-07-09 15:34:16 +0000
@@ -295,6 +295,18 @@
{
return new BiMonthlyPeriodType();
}
+ if ( isoPeriod.matches( "\\b\\d{4}April\\b" ) )
+ {
+ return new FinancialAprilPeriodType();
+ }
+ if ( isoPeriod.matches( "\\b\\d{4}July\\b" ) )
+ {
+ return new FinancialJulyPeriodType();
+ }
+ if ( isoPeriod.matches( "\\b\\d{4}Oct\\b" ) )
+ {
+ return new FinancialOctoberPeriodType();
+ }
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 2012-07-02 19:27:19 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java 2012-07-09 15:34:16 +0000
@@ -63,6 +63,9 @@
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 ) );
+ Period financialApril = new Period( new FinancialAprilPeriodType(), getDate( 2010, 4, 1 ), getDate( 2011, 3, 31 ) );
+ Period financialJuly = new Period( new FinancialJulyPeriodType(), getDate( 2010, 7, 1 ), getDate( 2011, 6, 30 ) );
+ Period financialOct = new Period( new FinancialOctoberPeriodType(), getDate( 2010, 10, 1 ), getDate( 2011, 9, 30 ) );
assertEquals( "Day format", "20100101", day1.getIsoDate() );
assertEquals( "Month format", "201001", month1.getIsoDate() );
@@ -70,6 +73,9 @@
assertEquals( "Quarter format", "2010Q1", quarter1.getIsoDate() );
assertEquals( "Semester format", "2010S1", semester1.getIsoDate() );
assertEquals( "Bimonth format", "201003B", biMonth1.getIsoDate() );
+ assertEquals( "Financial April", "2010April", financialApril.getIsoDate() );
+ assertEquals( "Financial July", "2010July", financialJuly.getIsoDate() );
+ assertEquals( "Financial Oct", "2010Oct", financialOct.getIsoDate() );
assertEquals( day1, PeriodType.getPeriodFromIsoString( "20100101" ) );
assertEquals( month1, PeriodType.getPeriodFromIsoString( "201001" ) );
@@ -77,5 +83,8 @@
assertEquals( quarter1, PeriodType.getPeriodFromIsoString( "2010Q1" ) );
assertEquals( semester1, PeriodType.getPeriodFromIsoString( "2010S1" ) );
assertEquals( biMonth1, PeriodType.getPeriodFromIsoString( "201003B" ) );
+ assertEquals( financialApril, PeriodType.getPeriodFromIsoString( "2010April" ) );
+ assertEquals( financialJuly, PeriodType.getPeriodFromIsoString( "2010July" ) );
+ assertEquals( financialOct, PeriodType.getPeriodFromIsoString( "2010Oct" ) );
}
}