aboutsummaryrefslogtreecommitdiff
path: root/test/org/traccar/calendar/CalendarTest.java
blob: 44fc9539b3b250c479c8802eb326f4e89debde5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.traccar.calendar;

import java.io.IOException;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Assert;
import org.junit.Test;
import org.traccar.model.Calendar;

import net.fortuna.ical4j.data.ParserException;

public class CalendarTest {
    
    @Test
    public void testCalendar() throws IOException, ParserException, ParseException, SQLException {
        String calendarString = "BEGIN:VCALENDAR\n" + 
                "PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n" + 
                "VERSION:2.0\n" + 
                "BEGIN:VTIMEZONE\n" + 
                "TZID:Asia/Yekaterinburg\n" + 
                "BEGIN:STANDARD\n" + 
                "TZOFFSETFROM:+0500\n" + 
                "TZOFFSETTO:+0500\n" + 
                "TZNAME:YEKT\n" + 
                "DTSTART:19700101T000000\n" + 
                "END:STANDARD\n" + 
                "END:VTIMEZONE\n" + 
                "BEGIN:VEVENT\n" + 
                "CREATED:20161213T045151Z\n" + 
                "LAST-MODIFIED:20161213T045242Z\n" + 
                "DTSTAMP:20161213T045242Z\n" + 
                "UID:9d000df0-6354-479d-a407-218dac62c7c9\n" + 
                "SUMMARY:Every night\n" + 
                "RRULE:FREQ=DAILY\n" + 
                "DTSTART;TZID=Asia/Yekaterinburg:20161130T230000\n" + 
                "DTEND;TZID=Asia/Yekaterinburg:20161201T070000\n" + 
                "TRANSP:OPAQUE\n" + 
                "END:VEVENT\n" + 
                "END:VCALENDAR";
        Calendar calendar = new Calendar();
        calendar.setCalendar(calendarString.getBytes());
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ssX");
        
        Date date = format.parse("2016-12-13 23:01:00+05");
        Assert.assertTrue(calendar.checkMoment(date));
        
        date = format.parse("2016-12-13 07:01:00+05");
        Assert.assertTrue(!calendar.checkMoment(date));
    }
}