Package ch.pollet.jzic.datetime

Examples of ch.pollet.jzic.datetime.DateTime


        assertEquals(dt1.hashCode(), dt2.hashCode());
    }

    @Test
    public void testHas() {
        DateTime dt = new DateTime();
        assertFalse(dt.hasYear());
        assertFalse(dt.hasMonth());
        assertFalse(dt.hasDay());
        assertFalse(dt.hasHour());
        assertFalse(dt.hasMinute());
        assertFalse(dt.hasSecond());

        dt.setYear(1);
        assertTrue(dt.hasYear());

        dt.setMonth(1);
        assertTrue(dt.hasMonth());

        dt.setDay(1);
        assertTrue(dt.hasDay());

        dt.setHour(1);
        assertTrue(dt.hasHour());

        dt.setMinute(1);
        assertTrue(dt.hasMinute());

        dt.setSecond(1);
        assertTrue(dt.hasSecond());

        dt = new DateTime();

        assertFalse(dt.hasYear());
        assertFalse(dt.hasMonth());
        assertFalse(dt.hasDay());

        dt.setDayBase(1);
        assertFalse(dt.hasDay());

        dt.setDayPosition(DateTime.DayPosition.GE);
        assertFalse(dt.hasDay());

        dt.setDayOfWeek(1);
        assertFalse(dt.hasDay());

        dt.setMonth(1);
        assertFalse(dt.hasDay());

        dt.setYear(1);
        assertTrue(dt.hasDay());
    }
View Full Code Here


        assertTrue(dt.hasDay());
    }

    @Test
    public void testToString() {
        DateTime dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(1);
        dt.setDay(2);
        dt.setHour(3);
        dt.setMinute(4);
        dt.setSecond(5);
        dt.setType(DateTime.Type.WALL);
        assertEquals("2009-01-02T03:04:05W", dt.toString());

        dt.setMonth(10);
        dt.setDay(20);
        dt.setHour(30);
        dt.setMinute(40);
        dt.setSecond(50);
        dt.setType(DateTime.Type.STD);
        assertEquals("2009-10-20T30:40:50S", dt.toString());
    }
View Full Code Here

        assertEquals("2009-10-20T30:40:50S", dt.toString());
    }

    @Test
    public void testToUtc() throws DateTimeException {
        DateTime dt = new DateTime();
        DateTime dtExp = new DateTime();

        // 2009-06-14T12:30:30W --> 2009-06-14T12:30:29U
        dt.setYear(2009);
        dt.setMonth(6);
        dt.setDay(14);
        dt.setHour(12);
        dt.setMinute(30);
        dt.setSecond(30);
        dt.setType(DateTime.Type.WALL);
        dt.toUtc(0, 61);
        dtExp.setYear(2009);
        dtExp.setMonth(6);
        dtExp.setDay(14);
        dtExp.setHour(12);
        dtExp.setMinute(29);
        dtExp.setSecond(29);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);

        // 2009-06-30T23:59:59W --> 2009-07-01T00:00:00U
        dt.setYear(2009);
        dt.setMonth(6);
        dt.setDay(30);
        dt.setHour(23);
        dt.setMinute(59);
        dt.setSecond(59);
        dt.setType(DateTime.Type.WALL);
        dt.toUtc(0, -1);
        dtExp.setYear(2009);
        dtExp.setMonth(7);
        dtExp.setDay(1);
        dtExp.setHour(0);
        dtExp.setMinute(0);
        dtExp.setSecond(0);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);

        // 2009-03-01T00:00:00W --> 2009-02-28T23:59:59Z
        dt.setYear(2009);
        dt.setMonth(3);
        dt.setDay(1);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);
        dt.toUtc(0, 1);
        dtExp.setYear(2009);
        dtExp.setMonth(2);
        dtExp.setDay(28);
        dtExp.setHour(23);
        dtExp.setMinute(59);
        dtExp.setSecond(59);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);

        // 2008-03-01T00:00:00W --> 2008-02-28T23:59:59Z
        dt.setYear(2008);
        dt.setMonth(3);
        dt.setDay(1);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);
        dt.toUtc(0, 1);
        dtExp.setYear(2008);
        dtExp.setMonth(2);
        dtExp.setDay(29);
        dtExp.setHour(23);
        dtExp.setMinute(59);
        dtExp.setSecond(59);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);

        // 2000-03-01T00:00:00W --> 2000-02-28T23:59:59Z
        dt.setYear(2000);
        dt.setMonth(3);
        dt.setDay(1);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);
        dt.toUtc(0, 1);
        dtExp.setYear(2000);
        dtExp.setMonth(2);
        dtExp.setDay(29);
        dtExp.setHour(23);
        dtExp.setMinute(59);
        dtExp.setSecond(59);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);

        // 1900-03-01T00:00:00W --> 1900-02-28T23:59:59Z
        dt.setYear(1900);
        dt.setMonth(3);
        dt.setDay(1);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);
        dt.toUtc(0, 1);
        dtExp.setYear(1900);
        dtExp.setMonth(2);
        dtExp.setDay(28);
        dtExp.setHour(23);
        dtExp.setMinute(59);
        dtExp.setSecond(59);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);

        // 2000-03-30T23:59:59S --> 2000-03-31T00:00:00Z
        dt.setYear(2000);
        dt.setMonth(3);
        dt.setDay(30);
        dt.setHour(23);
        dt.setMinute(59);
        dt.setSecond(59);
        dt.setType(DateTime.Type.STD);
        dt.toUtc(-1, 0);
        dtExp.setYear(2000);
        dtExp.setMonth(3);
        dtExp.setDay(31);
        dtExp.setHour(0);
        dtExp.setMinute(0);
        dtExp.setSecond(0);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);

        // 2000-12-29T12:00:00W --> 2001-01-01T12:00:00Z
        dt.setYear(2000);
        dt.setMonth(12);
        dt.setDay(29);
        dt.setHour(12);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.STD);
        dt.toUtc(-259200, 0);
        dtExp.setYear(2001);
        dtExp.setMonth(1);
        dtExp.setDay(1);
        dtExp.setHour(12);
        dtExp.setMinute(0);
        dtExp.setSecond(0);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);

        // 2000-01-01T00:00:00W --> 1999-12-12T23:59:59Z
        dt.setYear(2000);
        dt.setMonth(1);
        dt.setDay(1);
        dt.setHour(0);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.STD);
        dt.toUtc(1, 0);
        dtExp.setYear(1999);
        dtExp.setMonth(12);
        dtExp.setDay(31);
        dtExp.setHour(23);
        dtExp.setMinute(59);
        dtExp.setSecond(59);
        dtExp.setType(DateTime.Type.UTC);
        assertEquals(dtExp, dt);
    }
View Full Code Here

        assertEquals(dtExp, dt);
    }

    @Test
    public void testComputeDayOfMonth() throws DateTimeException {
        DateTime dt = new DateTime();

        // first monday >= 2009-09-01
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDayOfWeek(1);
        dt.setDayPosition(DateTime.DayPosition.GE);
        dt.setDayBase(1);
        assertEquals(7, dt.getDay().intValue());

        // first monday >= 2009-09-07
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDayOfWeek(1);
        dt.setDayPosition(DateTime.DayPosition.GE);
        dt.setDayBase(7);
        assertEquals(7, dt.getDay().intValue());

        // first monday <= 2009-09-31
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDayOfWeek(1);
        dt.setDayPosition(DateTime.DayPosition.LE);
        dt.setDayBase(31);
        assertEquals(28, dt.getDay().intValue());

        // first monday <= 2009-09-28
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDayOfWeek(1);
        dt.setDayPosition(DateTime.DayPosition.LE);
        dt.setDayBase(31);
        assertEquals(28, dt.getDay().intValue());

        // last sun of sept
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDayOfWeek(7);
        dt.setDayPosition(DateTime.DayPosition.LE);
        dt.setDayBase(31);
        assertEquals(27, dt.getDay().intValue());
    }
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());
View Full Code Here

    }

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

    }

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

        assertEquals(27, dt.getDay().intValue());
    }

    @Test
    public void testClone() {
        DateTime dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(1);
        dt.setDay(2);
        dt.setHour(3);
        dt.setMinute(4);
        dt.setSecond(5);
        dt.setType(DateTime.Type.WALL);

        DateTime dtCloned = dt.clone();

        assertFalse(dt == dtCloned);
        assertEquals(dt, dtCloned);
    }
View Full Code Here

    }

    @Test
    public void testAddMetazone() {
        Period p = new Period();
        DateTime from = new DateTime();
        DateTime to = new DateTime();
        TreeSet<Period> metazone = new TreeSet<Period>();

        from.setYear(1);
        from.setMonth(1);
        from.setDay(1);
View Full Code Here

        return dt;
    }

    public static DateTime parseDateTime(Tokenizer st) throws ParserException {
        DateTime dt = new DateTime(st.getFileName(), st.getLineNumber());
        return parseDateTime(st, dt);
    }
View Full Code Here

TOP

Related Classes of ch.pollet.jzic.datetime.DateTime

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.