Package ch.pollet.jzic.timezone

Examples of ch.pollet.jzic.timezone.Zone


        this.db = db;
    }

    public void continueParsing(Tokenizer st) throws ParserException {
        if (currentZoneName != null) {
            Zone z = new Zone();
            z.setOffset(Parser.parseOffset(st.nextToken()));
            z.setRule(parseRuleName(st));
            z.setFormat(parseFormat(st));
            z.setUntil(parseUntil(st));
           
            db.addZone(currentZoneName, z);
        }
    }
View Full Code Here


    @Test
    public void testParse() throws Exception {
        String line;
        Tokenizer t;
        Zone z;
        DateTime dt;
       
        Database db = new Database();
        ZoneParser zp = new ZoneParser(db);

        //-- Test 1
        line = "Zone1 1:34:08 - LMT 2000";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

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

        assertTrue(db.getZones().containsKey("Zone1"));
        z = db.getZones().get("Zone1").first();
        assertEquals(5648, z.getOffset());
        assertEquals(null, z.getRule());
        assertEquals("LMT", z.getFormat());
        assertEquals(dt, z.getUntil());

        //-- Test 2
        line = "Zone2 1:34:08 Rule LMT 2000 Feb 12 1u";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2000);
        dt.setMonth(2);
        dt.setDay(12);
        dt.setHour(1);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.UTC);

        z = db.getZones().get("Zone2").first();
        assertEquals("Rule", z.getRule());
        assertEquals(dt, z.getUntil());

        //-- Test 3
        line = "Zone3 1:34:08 Rule LMT 2000 Mar 12 1:30s";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2000);
        dt.setMonth(3);
        dt.setDay(12);
        dt.setHour(1);
        dt.setMinute(30);
        dt.setSecond(0);
        dt.setType(DateTime.Type.STD);

        z = db.getZones().get("Zone3").first();
        assertEquals(dt, z.getUntil());

        //-- Test 4
        line = "Zone4 1:34:08 Rule LMT 2000 Apr 12 1:30:44u";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2000);
        dt.setMonth(4);
        dt.setDay(12);
        dt.setHour(1);
        dt.setMinute(30);
        dt.setSecond(44);
        dt.setType(DateTime.Type.UTC);

        z = db.getZones().get("Zone4").first();
        assertEquals(dt, z.getUntil());

        //-- Test 5
        line = "Zone5 -1:34:08 Rule LMT";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(Integer.MAX_VALUE);
        dt.setMonth(12);
        dt.setDay(31);
        dt.setHour(23);
        dt.setMinute(59);
        dt.setSecond(59);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone5").first();
        assertEquals(dt, z.getUntil());
        assertEquals(-5648, z.getOffset());

        //-- Test 6
        line = "Zone6 0 Rule LMT 2009 Sep lastSun";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

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

        z = db.getZones().get("Zone6").first();
        assertEquals(dt, z.getUntil());

        //-- Test 7
        line = "Zone7 0 Rule LMT 2009 Oct Mon>=3";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(10);
        dt.setDay(5);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone7").first();
        assertEquals(dt, z.getUntil());

        //-- Test 8
        line = "Zone8 0 Rule LMT 2009 Nov Mon>=5";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

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

        z = db.getZones().get("Zone8").first();
        assertEquals(dt, z.getUntil());

        //-- Test 9
        line = "Zone9 0 Rule LMT 2009 Dec Mon<=8";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(12);
        dt.setDay(7);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone9").first();
        assertEquals(dt, z.getUntil());

        //-- Test 10
        line = "Zone10 0 Rule LMT 2009 Dec Mon<=14";
        t = new Tokenizer(line, "\t ", null, 0);
        zp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(12);
        dt.setDay(14);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        z = db.getZones().get("Zone10").first();
        assertEquals(dt, z.getUntil());
    }
View Full Code Here

        assertTrue(db.getRules().get("rule_2").contains(r));
    }

    @Test
    public void testAddZone() {
        Zone z1, z2;
        DateTime dt;
       
        z1 = new Zone();
        z1.setOffset(1);
        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(10);
        dt.setDay(3);
        dt.setHour(16);
        dt.setMinute(44);
        dt.setSecond(33);
        dt.setType(DateTime.Type.UTC);
        z1.setUntil(dt);
       
        db.addZone("zone_1", z1);
        assertTrue(db.getZones().containsKey("zone_1"));
        assertEquals(1, db.getZones().size());
        assertEquals(1, db.getZones().get("zone_1").size());
        assertTrue(db.getZones().get("zone_1").contains(z1));
        assertEquals(z1, db.getZones().get("zone_1").first());

        z2 = new Zone();
        z2.setOffset(1);
        dt = new DateTime();
        dt.setYear(2008);
        dt.setMonth(10);
        dt.setDay(3);
        dt.setHour(16);
        dt.setMinute(44);
        dt.setSecond(33);
        dt.setType(DateTime.Type.UTC);
        z2.setUntil(dt);

        db.addZone("zone_1", z2);
        assertTrue(db.getZones().containsKey("zone_1"));
        assertEquals(db.getZones().size(), 1);
        assertEquals(db.getZones().get("zone_1").size(), 2);
        assertTrue(db.getZones().get("zone_1").contains(z1));
        assertEquals(db.getZones().get("zone_1").first(), z2);
        assertEquals(db.getZones().get("zone_1").last(), z1);

        z1 = new Zone();
        z1.setOffset(1);
        dt = new DateTime();
        dt.setYear(2008);
        dt.setMonth(10);
        dt.setDay(3);
        dt.setHour(16);
        dt.setMinute(44);
        dt.setSecond(33);
        dt.setType(DateTime.Type.UTC);
        z1.setUntil(dt);

        db.addZone("zone_2", z1);
        assertTrue(db.getZones().containsKey("zone_2"));
        assertEquals(db.getZones().size(), 2);
        assertEquals(db.getZones().get("zone_2").size(), 1);
View Full Code Here

        assertTrue(db.getZones().get("zone_2").contains(z2));
    }

    @Test
    public void testAddLink() {
        Zone z = new Zone();
        DateTime dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(5);
        dt.setDay(3);
        dt.setHour(3);
        dt.setMinute(6);
        dt.setSecond(45);
        dt.setType(DateTime.Type.UTC);
        z.setUntil(dt);

        db.addZone("zone", z);
       
        Link l = new Link();
        l.setFrom("zone");
View Full Code Here

TOP

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

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.