=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java 2014-04-24 17:18:03 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java 2014-04-25 12:25:39 +0000 @@ -37,6 +37,12 @@ public abstract class AbstractCalendar implements Calendar { @Override + public String name() + { + return getClass().getSimpleName(); + } + + @Override public DateUnit toIso( int year, int month, int day ) { return toIso( new DateUnit( year, month, day ) ); === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/BuddhistCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/BuddhistCalendar.java 2014-04-24 15:46:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/BuddhistCalendar.java 1970-01-01 00:00:00 +0000 @@ -1,49 +0,0 @@ -package org.hisp.dhis.calendar; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.joda.time.chrono.BuddhistChronology; - -/** - * @author Morten Olav Hansen - */ -public class BuddhistCalendar extends ChronologyBasedCalendar -{ - private static final Calendar self = new BuddhistCalendar(); - - public static Calendar getInstance() - { - return self; - } - - protected BuddhistCalendar() - { - super( BuddhistChronology.getInstance() ); - } -} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java 2014-04-25 07:33:35 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java 2014-04-25 12:25:39 +0000 @@ -33,6 +33,8 @@ */ public interface Calendar { + String name(); + DateUnit toIso( int year, int month, int day ); DateUnit toIso( DateUnit dateUnit ); === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CopticCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CopticCalendar.java 2014-04-24 15:46:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CopticCalendar.java 1970-01-01 00:00:00 +0000 @@ -1,49 +0,0 @@ -package org.hisp.dhis.calendar; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.joda.time.chrono.CopticChronology; - -/** - * @author Morten Olav Hansen - */ -public class CopticCalendar extends ChronologyBasedCalendar -{ - private static final Calendar self = new CopticCalendar(); - - public static Calendar getInstance() - { - return self; - } - - protected CopticCalendar() - { - super( CopticChronology.getInstance() ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/EthiopicCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/EthiopicCalendar.java 2014-04-24 15:46:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/EthiopicCalendar.java 1970-01-01 00:00:00 +0000 @@ -1,49 +0,0 @@ -package org.hisp.dhis.calendar; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.joda.time.chrono.EthiopicChronology; - -/** - * @author Morten Olav Hansen - */ -public class EthiopicCalendar extends ChronologyBasedCalendar -{ - private static final Calendar self = new EthiopicCalendar(); - - public static Calendar getInstance() - { - return self; - } - - protected EthiopicCalendar() - { - super( EthiopicChronology.getInstance() ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/GregorianCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/GregorianCalendar.java 2014-04-24 15:46:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/GregorianCalendar.java 1970-01-01 00:00:00 +0000 @@ -1,49 +0,0 @@ -package org.hisp.dhis.calendar; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.joda.time.chrono.GregorianChronology; - -/** - * @author Morten Olav Hansen - */ -public class GregorianCalendar extends ChronologyBasedCalendar -{ - private static final Calendar self = new GregorianCalendar(); - - public static Calendar getInstance() - { - return self; - } - - protected GregorianCalendar() - { - super( GregorianChronology.getInstance() ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/IslamicCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/IslamicCalendar.java 2014-04-24 15:46:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/IslamicCalendar.java 1970-01-01 00:00:00 +0000 @@ -1,49 +0,0 @@ -package org.hisp.dhis.calendar; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.joda.time.chrono.IslamicChronology; - -/** - * @author Morten Olav Hansen - */ -public class IslamicCalendar extends ChronologyBasedCalendar -{ - private static final Calendar self = new IslamicCalendar(); - - public static Calendar getInstance() - { - return self; - } - - protected IslamicCalendar() - { - super( IslamicChronology.getInstance() ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Iso8601Calendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Iso8601Calendar.java 2014-04-24 15:46:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Iso8601Calendar.java 1970-01-01 00:00:00 +0000 @@ -1,49 +0,0 @@ -package org.hisp.dhis.calendar; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.joda.time.chrono.ISOChronology; - -/** - * @author Morten Olav Hansen - */ -public class Iso8601Calendar extends ChronologyBasedCalendar -{ - private static final Calendar self = new Iso8601Calendar(); - - public static Calendar getInstance() - { - return self; - } - - protected Iso8601Calendar() - { - super( ISOChronology.getInstance() ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/JulianCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/JulianCalendar.java 2014-04-24 15:46:24 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/JulianCalendar.java 1970-01-01 00:00:00 +0000 @@ -1,49 +0,0 @@ -package org.hisp.dhis.calendar; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.joda.time.chrono.JulianChronology; - -/** - * @author Morten Olav Hansen - */ -public class JulianCalendar extends ChronologyBasedCalendar -{ - private static final Calendar self = new JulianCalendar(); - - public static Calendar getInstance() - { - return self; - } - - protected JulianCalendar() - { - super( JulianChronology.getInstance() ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/NepaliCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/NepaliCalendar.java 2014-04-25 07:33:35 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/NepaliCalendar.java 1970-01-01 00:00:00 +0000 @@ -1,313 +0,0 @@ -package org.hisp.dhis.calendar; - -/* - * Copyright (c) 2004-2014, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.joda.time.DateTime; -import org.joda.time.Days; -import org.joda.time.chrono.ISOChronology; - -import java.util.HashMap; -import java.util.Map; - -/** - * @author Morten Olav Hansen - */ -public class NepaliCalendar extends AbstractCalendar -{ - private final DateUnit startNepal = new DateUnit( 2000, 1, 1, java.util.Calendar.WEDNESDAY ); - - private final DateUnit startIso = new DateUnit( 1943, 4, 14, java.util.Calendar.WEDNESDAY ); - - private static final Calendar self = new NepaliCalendar(); - - public static Calendar getInstance() - { - return self; - } - - @Override - public DateUnit toIso( DateUnit dateUnit ) - { - DateTime dateTime = startIso.toDateTime(); - - int totalDays = 0; - - for ( int year = startNepal.getYear(); year < dateUnit.getYear(); year++ ) - { - totalDays += getYearTotal( year ); - } - - for ( int month = startNepal.getMonth(); month < dateUnit.getMonth(); month++ ) - { - totalDays += conversionMap.get( dateUnit.getYear() )[month]; - } - - totalDays += dateUnit.getDay() - startNepal.getDay(); - - dateTime = dateTime.plusDays( totalDays ); - - return DateUnit.fromDateTime( dateTime ); - } - - @Override - public DateUnit fromIso( DateUnit dateUnit ) - { - DateTime start = startIso.toDateTime(); - DateTime end = dateUnit.toDateTime(); - - int days = Days.daysBetween( start, end ).getDays(); - - int curYear = startNepal.getYear(); - int curMonth = startNepal.getMonth(); - int curDay = startNepal.getDay(); - int dayOfWeek = startNepal.getDayOfWeek(); - - while ( days != 0 ) - { - // days in month - int dm = conversionMap.get( curYear )[curMonth]; - - curDay++; - - if ( curDay > dm ) - { - curMonth++; - curDay = 1; - } - - if ( curMonth > 12 ) - { - curYear++; - curMonth = 1; - } - - dayOfWeek++; - - if ( dayOfWeek > 7 ) - { - dayOfWeek = 1; - } - - days--; - } - - return new DateUnit( curYear, curMonth, curDay, dayOfWeek ); - } - - @Override - public DateInterval toIsoInterval( int year ) - { - DateUnit from = new DateUnit( year, 1, 1 ); - DateUnit to = new DateUnit( year, monthsInYear(), daysInMonth( year, monthsInYear() ) ); - - from = toIso( from ); - to = toIso( to ); - - return new DateInterval( from, to ); - } - - @Override - public DateInterval toIsoInterval( int year, int month ) - { - DateUnit from = new DateUnit( year, month, 1 ); - DateUnit to = new DateUnit( year, month, daysInMonth( year, month ) ); - - from = toIso( from ); - to = toIso( to ); - - return new DateInterval( from, to ); - } - - @Override - public int daysInYear( int year ) - { - return getYearTotal( year ); - } - - @Override - public int daysInMonth( int year, int month ) - { - return conversionMap.get( year )[month]; - } - - @Override - public int isoWeek( DateUnit dateUnit ) - { - DateTime dateTime = toIso( dateUnit ).toDateTime( ISOChronology.getInstance() ); - return dateTime.getWeekyear(); - } - - @Override - public int week( DateUnit dateUnit ) - { - return isoWeek( dateUnit ); - } - - @Override - public int isoWeekday( DateUnit dateUnit ) - { - DateTime dateTime = toIso( dateUnit ).toDateTime( ISOChronology.getInstance() ); - return dateTime.getDayOfWeek(); - } - - @Override - public int weekday( DateUnit dateUnit ) - { - int dayOfWeek = (isoWeekday( dateUnit ) + 1); - - if ( dayOfWeek > 7 ) - { - return 1; - } - - return dayOfWeek; - } - - private int getYearTotal( int year ) - { - // if year total index is uninitialized, calculate and set in array - if ( conversionMap.get( year )[0] == 0 ) - { - for ( int j = 1; j <= 12; j++ ) - { - conversionMap.get( year )[0] += conversionMap.get( year )[j]; - } - } - - return conversionMap.get( year )[0]; - } - - //------------------------------------------------------------------------------------------------------------ - // Conversion map for Nepali calendar - // - // Based on map from: - // http://forjavaprogrammers.blogspot.com/2012/06/how-to-convert-english-date-to-nepali.html - //------------------------------------------------------------------------------------------------------------ - - /** - * Map that gives an array of month lengths based on Nepali year lookup. - * Index 1 - 12 is used for months, index 0 is used to give year total (lazy calculated). - */ - private final static Map conversionMap = new HashMap(); - - static - { - conversionMap.put( 2000, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2001, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2002, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2003, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2004, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2005, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2006, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2007, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2008, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 } ); - conversionMap.put( 2009, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2010, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2011, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2012, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); - conversionMap.put( 2013, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2014, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2015, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2016, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); - conversionMap.put( 2017, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2018, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2019, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2020, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2021, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2022, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); - conversionMap.put( 2023, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2024, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2025, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2026, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2027, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2028, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2029, new int[]{ 0, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2030, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2031, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2032, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2033, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2034, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2035, new int[]{ 0, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 } ); - conversionMap.put( 2036, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2037, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2038, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2039, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); - conversionMap.put( 2040, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2041, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2042, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2043, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); - conversionMap.put( 2044, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2045, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2046, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2047, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2048, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2049, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); - conversionMap.put( 2050, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2051, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2052, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2053, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); - conversionMap.put( 2054, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2055, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2056, new int[]{ 0, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2057, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2058, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2059, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2060, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2061, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2062, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2063, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2064, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2065, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2066, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 } ); - conversionMap.put( 2067, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2068, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2069, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2070, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); - conversionMap.put( 2071, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2072, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2073, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); - conversionMap.put( 2074, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2075, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2076, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); - conversionMap.put( 2077, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); - conversionMap.put( 2078, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2079, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); - conversionMap.put( 2080, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); - conversionMap.put( 2081, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2082, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2083, new int[]{ 0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2084, new int[]{ 0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2085, new int[]{ 0, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2086, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2087, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2088, new int[]{ 0, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2089, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); - conversionMap.put( 2090, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); - } -} === added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl' === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/BuddhistCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/BuddhistCalendar.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/BuddhistCalendar.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,59 @@ +package org.hisp.dhis.calendar.impl; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.calendar.Calendar; +import org.hisp.dhis.calendar.ChronologyBasedCalendar; +import org.joda.time.chrono.BuddhistChronology; +import org.springframework.stereotype.Component; + +/** + * @author Morten Olav Hansen + */ +@Component +public class BuddhistCalendar extends ChronologyBasedCalendar +{ + private static final Calendar self = new BuddhistCalendar(); + + public static Calendar getInstance() + { + return self; + } + + protected BuddhistCalendar() + { + super( BuddhistChronology.getInstance() ); + } + + @Override + public String name() + { + return "buddhist"; + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/CopticCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/CopticCalendar.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/CopticCalendar.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,59 @@ +package org.hisp.dhis.calendar.impl; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.calendar.Calendar; +import org.hisp.dhis.calendar.ChronologyBasedCalendar; +import org.joda.time.chrono.CopticChronology; +import org.springframework.stereotype.Component; + +/** + * @author Morten Olav Hansen + */ +@Component +public class CopticCalendar extends ChronologyBasedCalendar +{ + private static final Calendar self = new CopticCalendar(); + + public static Calendar getInstance() + { + return self; + } + + protected CopticCalendar() + { + super( CopticChronology.getInstance() ); + } + + @Override + public String name() + { + return "coptic"; + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopicCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopicCalendar.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopicCalendar.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,59 @@ +package org.hisp.dhis.calendar.impl; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.calendar.Calendar; +import org.hisp.dhis.calendar.ChronologyBasedCalendar; +import org.joda.time.chrono.EthiopicChronology; +import org.springframework.stereotype.Component; + +/** + * @author Morten Olav Hansen + */ +@Component +public class EthiopicCalendar extends ChronologyBasedCalendar +{ + private static final Calendar self = new EthiopicCalendar(); + + public static Calendar getInstance() + { + return self; + } + + protected EthiopicCalendar() + { + super( EthiopicChronology.getInstance() ); + } + + @Override + public String name() + { + return "ethiopic"; + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/GregorianCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/GregorianCalendar.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/GregorianCalendar.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,59 @@ +package org.hisp.dhis.calendar.impl; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.calendar.Calendar; +import org.hisp.dhis.calendar.ChronologyBasedCalendar; +import org.joda.time.chrono.GregorianChronology; +import org.springframework.stereotype.Component; + +/** + * @author Morten Olav Hansen + */ +@Component +public class GregorianCalendar extends ChronologyBasedCalendar +{ + private static final Calendar self = new GregorianCalendar(); + + public static Calendar getInstance() + { + return self; + } + + protected GregorianCalendar() + { + super( GregorianChronology.getInstance() ); + } + + @Override + public String name() + { + return "gregorian"; + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/IslamicCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/IslamicCalendar.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/IslamicCalendar.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,59 @@ +package org.hisp.dhis.calendar.impl; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.calendar.Calendar; +import org.hisp.dhis.calendar.ChronologyBasedCalendar; +import org.joda.time.chrono.IslamicChronology; +import org.springframework.stereotype.Component; + +/** + * @author Morten Olav Hansen + */ +@Component +public class IslamicCalendar extends ChronologyBasedCalendar +{ + private static final Calendar self = new IslamicCalendar(); + + public static Calendar getInstance() + { + return self; + } + + protected IslamicCalendar() + { + super( IslamicChronology.getInstance() ); + } + + @Override + public String name() + { + return "islamic"; + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/Iso8601Calendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/Iso8601Calendar.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/Iso8601Calendar.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,59 @@ +package org.hisp.dhis.calendar.impl; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.calendar.Calendar; +import org.hisp.dhis.calendar.ChronologyBasedCalendar; +import org.joda.time.chrono.ISOChronology; +import org.springframework.stereotype.Component; + +/** + * @author Morten Olav Hansen + */ +@Component +public class Iso8601Calendar extends ChronologyBasedCalendar +{ + private static final Calendar self = new Iso8601Calendar(); + + public static Calendar getInstance() + { + return self; + } + + protected Iso8601Calendar() + { + super( ISOChronology.getInstance() ); + } + + @Override + public String name() + { + return "iso8601"; + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/JulianCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/JulianCalendar.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/JulianCalendar.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,59 @@ +package org.hisp.dhis.calendar.impl; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.calendar.Calendar; +import org.hisp.dhis.calendar.ChronologyBasedCalendar; +import org.joda.time.chrono.JulianChronology; +import org.springframework.stereotype.Component; + +/** + * @author Morten Olav Hansen + */ +@Component +public class JulianCalendar extends ChronologyBasedCalendar +{ + private static final Calendar self = new JulianCalendar(); + + public static Calendar getInstance() + { + return self; + } + + protected JulianCalendar() + { + super( JulianChronology.getInstance() ); + } + + @Override + public String name() + { + return "julian"; + } +} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,325 @@ +package org.hisp.dhis.calendar.impl; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.calendar.AbstractCalendar; +import org.hisp.dhis.calendar.Calendar; +import org.hisp.dhis.calendar.DateInterval; +import org.hisp.dhis.calendar.DateUnit; +import org.joda.time.DateTime; +import org.joda.time.Days; +import org.joda.time.chrono.ISOChronology; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Morten Olav Hansen + */ +@Component +public class NepaliCalendar extends AbstractCalendar +{ + private final DateUnit startNepal = new DateUnit( 2000, 1, 1, java.util.Calendar.WEDNESDAY ); + + private final DateUnit startIso = new DateUnit( 1943, 4, 14, java.util.Calendar.WEDNESDAY ); + + private static final Calendar self = new NepaliCalendar(); + + public static Calendar getInstance() + { + return self; + } + + @Override + public DateUnit toIso( DateUnit dateUnit ) + { + DateTime dateTime = startIso.toDateTime(); + + int totalDays = 0; + + for ( int year = startNepal.getYear(); year < dateUnit.getYear(); year++ ) + { + totalDays += getYearTotal( year ); + } + + for ( int month = startNepal.getMonth(); month < dateUnit.getMonth(); month++ ) + { + totalDays += conversionMap.get( dateUnit.getYear() )[month]; + } + + totalDays += dateUnit.getDay() - startNepal.getDay(); + + dateTime = dateTime.plusDays( totalDays ); + + return DateUnit.fromDateTime( dateTime ); + } + + @Override + public DateUnit fromIso( DateUnit dateUnit ) + { + DateTime start = startIso.toDateTime(); + DateTime end = dateUnit.toDateTime(); + + int days = Days.daysBetween( start, end ).getDays(); + + int curYear = startNepal.getYear(); + int curMonth = startNepal.getMonth(); + int curDay = startNepal.getDay(); + int dayOfWeek = startNepal.getDayOfWeek(); + + while ( days != 0 ) + { + // days in month + int dm = conversionMap.get( curYear )[curMonth]; + + curDay++; + + if ( curDay > dm ) + { + curMonth++; + curDay = 1; + } + + if ( curMonth > 12 ) + { + curYear++; + curMonth = 1; + } + + dayOfWeek++; + + if ( dayOfWeek > 7 ) + { + dayOfWeek = 1; + } + + days--; + } + + return new DateUnit( curYear, curMonth, curDay, dayOfWeek ); + } + + @Override + public DateInterval toIsoInterval( int year ) + { + DateUnit from = new DateUnit( year, 1, 1 ); + DateUnit to = new DateUnit( year, monthsInYear(), daysInMonth( year, monthsInYear() ) ); + + from = toIso( from ); + to = toIso( to ); + + return new DateInterval( from, to ); + } + + @Override + public DateInterval toIsoInterval( int year, int month ) + { + DateUnit from = new DateUnit( year, month, 1 ); + DateUnit to = new DateUnit( year, month, daysInMonth( year, month ) ); + + from = toIso( from ); + to = toIso( to ); + + return new DateInterval( from, to ); + } + + @Override + public int daysInYear( int year ) + { + return getYearTotal( year ); + } + + @Override + public int daysInMonth( int year, int month ) + { + return conversionMap.get( year )[month]; + } + + @Override + public int isoWeek( DateUnit dateUnit ) + { + DateTime dateTime = toIso( dateUnit ).toDateTime( ISOChronology.getInstance() ); + return dateTime.getWeekyear(); + } + + @Override + public int week( DateUnit dateUnit ) + { + return isoWeek( dateUnit ); + } + + @Override + public int isoWeekday( DateUnit dateUnit ) + { + DateTime dateTime = toIso( dateUnit ).toDateTime( ISOChronology.getInstance() ); + return dateTime.getDayOfWeek(); + } + + @Override + public int weekday( DateUnit dateUnit ) + { + int dayOfWeek = (isoWeekday( dateUnit ) + 1); + + if ( dayOfWeek > 7 ) + { + return 1; + } + + return dayOfWeek; + } + + @Override + public String name() + { + return "nepali"; + } + + private int getYearTotal( int year ) + { + // if year total index is uninitialized, calculate and set in array + if ( conversionMap.get( year )[0] == 0 ) + { + for ( int j = 1; j <= 12; j++ ) + { + conversionMap.get( year )[0] += conversionMap.get( year )[j]; + } + } + + return conversionMap.get( year )[0]; + } + + //------------------------------------------------------------------------------------------------------------ + // Conversion map for Nepali calendar + // + // Based on map from: + // http://forjavaprogrammers.blogspot.com/2012/06/how-to-convert-english-date-to-nepali.html + //------------------------------------------------------------------------------------------------------------ + + /** + * Map that gives an array of month lengths based on Nepali year lookup. + * Index 1 - 12 is used for months, index 0 is used to give year total (lazy calculated). + */ + private final static Map conversionMap = new HashMap(); + + static + { + conversionMap.put( 2000, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2001, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2002, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2003, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2004, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2005, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2006, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2007, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2008, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 } ); + conversionMap.put( 2009, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2010, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2011, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2012, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); + conversionMap.put( 2013, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2014, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2015, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2016, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); + conversionMap.put( 2017, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2018, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2019, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2020, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2021, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2022, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); + conversionMap.put( 2023, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2024, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2025, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2026, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2027, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2028, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2029, new int[]{ 0, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2030, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2031, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2032, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2033, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2034, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2035, new int[]{ 0, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 } ); + conversionMap.put( 2036, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2037, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2038, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2039, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); + conversionMap.put( 2040, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2041, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2042, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2043, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); + conversionMap.put( 2044, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2045, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2046, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2047, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2048, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2049, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); + conversionMap.put( 2050, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2051, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2052, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2053, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); + conversionMap.put( 2054, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2055, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2056, new int[]{ 0, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2057, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2058, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2059, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2060, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2061, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2062, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2063, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2064, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2065, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2066, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 } ); + conversionMap.put( 2067, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2068, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2069, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2070, new int[]{ 0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 } ); + conversionMap.put( 2071, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2072, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2073, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 } ); + conversionMap.put( 2074, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2075, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2076, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); + conversionMap.put( 2077, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 } ); + conversionMap.put( 2078, new int[]{ 0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2079, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 } ); + conversionMap.put( 2080, new int[]{ 0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 } ); + conversionMap.put( 2081, new int[]{ 0, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2082, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2083, new int[]{ 0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2084, new int[]{ 0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2085, new int[]{ 0, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2086, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2087, new int[]{ 0, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2088, new int[]{ 0, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2089, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); + conversionMap.put( 2090, new int[]{ 0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 } ); + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-04-09 04:27:35 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java 2014-04-25 12:25:39 +0000 @@ -49,6 +49,7 @@ final String KEY_APPLICATION_INTRO = "keyApplicationIntro"; final String KEY_APPLICATION_NOTIFICATION = "keyApplicationNotification"; final String KEY_APPLICATION_FOOTER = "keyApplicationFooter"; + final String KEY_CALENDAR = "keyCalendar"; final String KEY_FLAG = "keyFlag"; final String KEY_FLAG_IMAGE = "keyFlagImage"; final String KEY_START_MODULE = "startModule"; @@ -91,6 +92,7 @@ final String DEFAULT_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY = "lastMonth"; final String DEFAULT_FLAG = "dhis2"; + final String DEFAULT_CALENDAR = "iso8601"; final int DEFAULT_MAX_NUMBER_OF_ATTEMPTS = 20; final int DEFAULT_TIMEFRAME_MINUTES = 1; final double DEFAULT_FACTOR_OF_DEVIATION = 2.0; === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/CalendarFactory.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/CalendarFactory.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/CalendarFactory.java 2014-04-25 12:25:39 +0000 @@ -0,0 +1,63 @@ +package org.hisp.dhis.calendar; + +/* + * Copyright (c) 2004-2014, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.google.common.collect.Lists; +import org.hisp.dhis.calendar.impl.Iso8601Calendar; +import org.hisp.dhis.setting.SystemSettingManager; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +public class CalendarFactory +{ + @Autowired + private SystemSettingManager settingManager; + + @Autowired + private List calendars = Lists.newArrayList(); + + public Calendar createCalendar() + { + String setting = (String) settingManager.getSystemSetting( SystemSettingManager.KEY_CALENDAR, SystemSettingManager.DEFAULT_CALENDAR ); + + for ( Calendar calendar : calendars ) + { + if ( setting.equals( calendar.name() ) ) + { + return calendar; + } + } + + return Iso8601Calendar.getInstance(); + } +} === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-04-07 10:18:57 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2014-04-25 12:25:39 +0000 @@ -7,6 +7,13 @@ + + + + + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemController.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SystemController.java 2014-04-25 12:25:39 +0000 @@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletResponse; import org.hisp.dhis.api.utils.ContextUtils; +import org.hisp.dhis.calendar.Calendar; import org.hisp.dhis.common.CodeGenerator; import org.hisp.dhis.dxf2.metadata.ImportSummary; import org.hisp.dhis.dxf2.utils.JacksonUtils; @@ -76,7 +77,7 @@ @Autowired private Notifier notifier; - + //-------------------------------------------------------------------------- // UID Generator //-------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java 2014-03-23 18:26:50 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java 2014-04-25 12:25:39 +0000 @@ -81,6 +81,7 @@ { Map map = new HashMap(); + map.put( KEY_CALENDAR, systemSettingManager.getSystemSetting( KEY_CALENDAR, DEFAULT_CALENDAR ) ); map.put( KEY_CACHE_STRATEGY, systemSettingManager.getSystemSetting( KEY_CACHE_STRATEGY, DEFAULT_CACHE_STRATEGY ) ); map.put( KEY_APPLICATION_TITLE, systemSettingManager.getSystemSetting( KEY_APPLICATION_TITLE, DEFAULT_APPLICATION_TITLE ) ); map.put( KEY_APPLICATION_INTRO, systemSettingManager.getSystemSetting( KEY_APPLICATION_INTRO ) ); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetGeneralSettingsAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetGeneralSettingsAction.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetGeneralSettingsAction.java 2014-04-25 12:25:39 +0000 @@ -29,6 +29,7 @@ */ import com.opensymphony.xwork2.Action; +import org.hisp.dhis.calendar.AbstractCalendar; import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; import org.hisp.dhis.configuration.Configuration; import org.hisp.dhis.configuration.ConfigurationService; @@ -42,6 +43,7 @@ import org.hisp.dhis.user.UserGroup; import org.hisp.dhis.user.UserGroupService; import org.hisp.dhis.user.comparator.UserGroupComparator; +import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; import java.util.Collection; @@ -159,6 +161,14 @@ return configuration; } + @Autowired + private List calendars; + + public List getCalendars() + { + return calendars; + } + // ------------------------------------------------------------------------- // Action implementation // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java 2014-03-18 08:10:10 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java 2014-04-25 12:25:39 +0000 @@ -148,7 +148,7 @@ } private String phoneNumberAreaCode; - + public void setPhoneNumberAreaCode( String phoneNumberAreaCode ) { this.phoneNumberAreaCode = phoneNumberAreaCode; @@ -168,6 +168,13 @@ this.multiOrganisationUnitForms = multiOrganisationUnitForms; } + private String calendar; + + public void setCalendar( String calendar ) + { + this.calendar = calendar; + } + private String message; public String getMessage() @@ -188,6 +195,7 @@ public String execute() { + systemSettingManager.saveSystemSetting( KEY_CALENDAR, calendar ); systemSettingManager.saveSystemSetting( KEY_CACHE_STRATEGY, cacheStrategy ); systemSettingManager.saveSystemSetting( KEY_OMIT_INDICATORS_ZERO_NUMERATOR_DATAMART, omitIndicatorsZeroNumeratorDataMart ); systemSettingManager.saveSystemSetting( KEY_FACTOR_OF_DEVIATION, factorDeviation ); === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2014-04-10 17:36:33 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2014-04-25 12:25:39 +0000 @@ -63,6 +63,7 @@ no_completeness_recipients=No completeness recipients system_overview=System overview cache_strategy=Cache strategy +calendar=Calendar no_cache=No cache cache_until_6am_tomorrow=Cache until 6 AM tomorrow cache_for_two_weeks=Cache for two weeks === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm 2013-12-25 15:01:48 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm 2014-04-25 12:25:39 +0000 @@ -3,6 +3,7 @@ jQuery("input[type=button]").click(function() { jQuery.postUTF8('setSystemGeneralSettings.action', { cacheStrategy: getFieldValue('cacheStrategy'), + calendar: getFieldValue('calendar'), infrastructuralDataElements: getFieldValue('infrastructuralDataElements'), infrastructuralPeriodType: getFieldValue('infrastructuralPeriodType'), feedbackRecipients: getFieldValue('feedbackRecipients'), @@ -33,6 +34,16 @@ +
$i18n.getString( "calendar" )
+ +
+ +
+
$i18n.getString( "infrastructural_data_elements" )