Package ch.pollet.jzic.timezone

Examples of ch.pollet.jzic.timezone.Rule


    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());
    }
View Full Code Here


    public void testDump() {
    }

    @Test
    public void testAddRule() {
        Rule r;

        r = new Rule();
        r.setName("rule_1");
        r.setOffset(1);
        db.addRule(r);
       
        assertTrue(db.getRules().containsKey("rule_1"));
        assertEquals(1, db.getRules().size());
        assertEquals(1, db.getRules().get("rule_1").size());
        assertTrue(db.getRules().get("rule_1").contains(r));

        r = new Rule();
        r.setName("rule_1");
        r.setOffset(2);
        db.addRule(r);
       
        assertTrue(db.getRules().containsKey("rule_1"));
        assertEquals(1, db.getRules().size());
        assertEquals(2, db.getRules().get("rule_1").size());
        assertTrue(db.getRules().get("rule_1").contains(r));

        r = new Rule();
        r.setName("rule_2");
        r.setOffset(3);
        db.addRule(r);

        assertTrue(db.getRules().containsKey("rule_2"));
        assertEquals(2, db.getRules().size());
        assertEquals(1, db.getRules().get("rule_2").size());
View Full Code Here

    @Test
    public void testParse() throws Exception {
        String line;
        Tokenizer t;
        Rule r;
        DateTime dt;

        Database db = new Database();
        RuleParser rp = new RuleParser(db);

        //-- Test 1
        line = "Rule1 2009 2010 - Sep lastSun 2:00w 1:30 -";
        t = new Tokenizer(line, "\t ", null, 0);
        rp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDay(27);
        dt.setHour(2);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        assertTrue(db.getRules().containsKey("Rule1"));
        assertEquals(1, db.getRules().get("Rule1").size());
        r = db.getRules().get("Rule1").get(0);
        assertEquals(2009, r.getFromYear());
        assertEquals(2010, r.getToYear());
        assertEquals(null, r.getType());
        r.getAt().setYear(2009);
        assertEquals(dt, r.getAt());
        assertEquals(5400, r.getOffset());
        assertEquals("", r.getFormat());

        //-- Test 2
        line = "Rule2 2009 2010 - Sep 1 2:00w 1:30:30 S";
        t = new Tokenizer(line, "\t ", null, 0);
        rp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDay(1);
        dt.setHour(2);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        assertTrue(db.getRules().containsKey("Rule2"));
        assertEquals(1, db.getRules().get("Rule2").size());
        r = db.getRules().get("Rule2").get(0);
        assertEquals(2009, r.getFromYear());
        assertEquals(2010, r.getToYear());
        assertEquals(null, r.getType());
        r.getAt().setYear(2009);
        assertEquals(dt, r.getAt());
        assertEquals(5430, r.getOffset());
        assertEquals("S", r.getFormat());

    }
View Full Code Here

    public RuleParser(Database db) {
        this.db = db;
    }

    public void parse(Tokenizer st) throws ParserException {
        Rule r = new Rule();
        r.setName(st.nextToken());
        r.setFromYear(parseFromYear(st));
        r.setToYear(parseToYear(st, r.getFromYear()));
        r.setType(parseType(st));
        r.setAt(Parser.parseDateTime(st));
        r.setOffset(Parser.parseOffset(st.nextToken()));
        r.setFormat(parseFormat(st));

        db.addRule(r);
    }
View Full Code Here

TOP

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

Copyright © 2018 www.massapicom. 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.