dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30047
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15239: minor bugfixes, and more tests for DateUnit
------------------------------------------------------------
revno: 15239
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-05-12 18:57:48 +0200
message:
minor bugfixes, and more tests for DateUnit
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/DateUnitTest.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/calendar/DateUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java 2014-05-12 16:41:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java 2014-05-12 16:57:48 +0000
@@ -147,6 +147,11 @@
return new GregorianCalendar( year, month - 1, day );
}
+ public Date toJdkDate()
+ {
+ return toJdkCalendar().getTime();
+ }
+
public static DateUnit fromDateTime( DateTime dateTime )
{
return new DateUnit( dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getDayOfWeek() );
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/DateUnitTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/DateUnitTest.java 2014-05-12 16:41:54 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/DateUnitTest.java 2014-05-12 16:57:48 +0000
@@ -28,9 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.joda.time.DateTime;
import org.junit.Test;
+import sun.util.resources.cldr.ar.CalendarData_ar_YE;
import java.util.*;
+import java.util.Calendar;
import static org.junit.Assert.assertEquals;
@@ -40,12 +43,23 @@
public class DateUnitTest
{
@Test
+ public void fromDateTimeTest()
+ {
+ DateTime dateTime = new DateTime( 2014, 3, 20, 0, 0 );
+ DateUnit dateUnit = DateUnit.fromDateTime( dateTime );
+
+ assertEquals( 2014, dateUnit.getYear() );
+ assertEquals( 3, dateUnit.getMonth() );
+ assertEquals( 20, dateUnit.getDay() );
+ }
+
+ @Test
public void fromJdkDateTest()
{
java.util.Calendar cal = new GregorianCalendar( 2014, 2, 20 );
Date date = cal.getTime();
-
DateUnit dateUnit = DateUnit.fromJdkDate( date );
+
assertEquals( 2014, dateUnit.getYear() );
assertEquals( 3, dateUnit.getMonth() );
assertEquals( 20, dateUnit.getDay() );
@@ -55,8 +69,44 @@
public void fromJdkCalendarTest()
{
java.util.Calendar cal = new GregorianCalendar( 2014, 2, 20 );
-
DateUnit dateUnit = DateUnit.fromJdkCalendar( cal );
+
+ assertEquals( 2014, dateUnit.getYear() );
+ assertEquals( 3, dateUnit.getMonth() );
+ assertEquals( 20, dateUnit.getDay() );
+ }
+
+ @Test
+ public void toDateTimeTest()
+ {
+ DateUnit dateUnit = new DateUnit( 2014, 3, 20 );
+ DateTime dateTime = dateUnit.toDateTime();
+
+ assertEquals( 2014, dateTime.getYear() );
+ assertEquals( 3, dateTime.getMonthOfYear() );
+ assertEquals( 20, dateTime.getDayOfMonth() );
+ }
+
+ @Test
+ public void toJdkCalendarTest()
+ {
+ DateUnit dateUnit = new DateUnit( 2014, 3, 20 );
+ Calendar calendar = dateUnit.toJdkCalendar();
+
+ assertEquals( 2014, calendar.get( Calendar.YEAR ) );
+ assertEquals( 2, calendar.get( Calendar.MONTH ) );
+ assertEquals( 20, calendar.get( Calendar.DAY_OF_MONTH ) );
+ }
+
+ @Test
+ public void toJdkDateTest()
+ {
+ DateUnit dateUnit = new DateUnit( 2014, 3, 20 );
+ Date date = dateUnit.toJdkDate();
+
+ // use dateTime for testing
+ DateTime dateTime = new DateTime( date.getTime() );
+
assertEquals( 2014, dateUnit.getYear() );
assertEquals( 3, dateUnit.getMonth() );
assertEquals( 20, dateUnit.getDay() );