Package ch.pollet.jzic.timezone

Source Code of ch.pollet.jzic.timezone.RuleTest

package ch.pollet.jzic.timezone;

import ch.pollet.jzic.timezone.Rule;
import ch.pollet.jzic.timezone.Period;
import ch.pollet.jzic.datetime.DateTime;
import java.util.TreeSet;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Christophe Pollet
*/
public class RuleTest {
    @Test
    public void testToPeriods() throws Exception {
        Period period = new Period();
        DateTime from = new DateTime();
        DateTime to = new DateTime();
        DateTime at = new DateTime();
        Rule r = new Rule();
        TreeSet<Period> periods;

        from.setYear(2000);
        from.setMonth(6);
        from.setDay(1);
        from.setHour(0);
        from.setMinute(0);
        from.setSecond(0);
        from.setType(DateTime.Type.UTC);

        to.setYear(2010);
        to.setMonth(6);
        to.setDay(1);
        to.setHour(0);
        to.setMinute(0);
        to.setSecond(0);
        to.setType(DateTime.Type.UTC);

        period.setFrom(from);
        period.setTo(to);
        period.setFormat("_%s");
        period.setOffset(3600);
        period.setPeriodName("PeriodName");

        r.setFormat("_");
        r.setFromYear(1999);
        r.setToYear(2011);
        r.setName("SomeRule");
        r.setOffset(3600);

        //-- Test 1
        at.setMonth(3);
        at.setDay(1);
        at.setHour(0);
        at.setMinute(0);
        at.setSecond(0);
        at.setType(DateTime.Type.UTC);

        r.setAt(at);

        periods = r.toPeriods(period);

        assertEquals(10, periods.size());
        assertEquals("__", periods.first().getPeriodName());
        assertEquals(7200, periods.first().getOffset());
        assertFalse(periods.first().isStdOffset());
        assertEquals(2001, periods.first().getFrom().getYear().intValue());
        assertEquals(2010, periods.last().getFrom().getYear().intValue());
        assertEquals(null, periods.first().getTo());
        assertEquals(null, periods.last().getTo());

        //-- Test 2
        at.setMonth(7);
        at.setDay(1);
        at.setHour(0);
        at.setMinute(0);
        at.setSecond(0);
        at.setType(DateTime.Type.UTC);

        r.setAt(at);

        periods = r.toPeriods(period);

        assertEquals(10, periods.size());
        assertEquals("__", periods.first().getPeriodName());
        assertEquals(7200, periods.first().getOffset());
        assertFalse(periods.first().isStdOffset());
        assertEquals(2000, periods.first().getFrom().getYear().intValue());
        assertEquals(2009, periods.last().getFrom().getYear().intValue());
        assertEquals(null, periods.first().getTo());
        assertEquals(null, periods.last().getTo());

        //-- Test 3
        at.setMonth(6);
        at.setDay(1);
        at.setHour(0);
        at.setMinute(0);
        at.setSecond(0);
        at.setType(DateTime.Type.UTC);

        r.setAt(at);

        periods = r.toPeriods(period);

        assertEquals(11, periods.size());
        assertEquals("__", periods.first().getPeriodName());
        assertEquals(7200, periods.first().getOffset());
        assertFalse(periods.first().isStdOffset());
        assertEquals(2000, periods.first().getFrom().getYear().intValue());
        assertEquals(2010, periods.last().getFrom().getYear().intValue());
        assertEquals(null, periods.first().getTo());
        assertEquals(null, periods.last().getTo());

        r.setOffset(0);
        periods = r.toPeriods(period);
        assertTrue(periods.first().isStdOffset());
    }
}
TOP

Related Classes of ch.pollet.jzic.timezone.RuleTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.