Search in sources :

Example 56 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarExtensionStrategyTest method testCalendarDateSelectiveExtension.

@Test
public void testCalendarDateSelectiveExtension() throws IOException {
    /**
     * Tuesday is only partially active for sid0
     */
    _gtfs.putCalendarDates("sid0=20121210,20121211,20121212,20121213,20121214," + "20121217,20121219,20121220,20121221," + "20121224,20121226,20121227,20121228", "sid1=20121208,20121209,20121215,20121216");
    GtfsMutableRelationalDao dao = _gtfs.read();
    ServiceDate endDate = new ServiceDate(2013, 01, 06);
    _strategy.setEndDate(endDate);
    _strategy.run(_context, dao);
    CalendarService service = CalendarServiceDataFactoryImpl.createService(dao);
    {
        Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid0"));
        assertEquals(17, dates.size());
        assertTrue(dates.contains(new ServiceDate(2012, 12, 31)));
        assertFalse(dates.contains(new ServiceDate(2013, 01, 01)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 02)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 03)));
        assertTrue(dates.contains(new ServiceDate(2013, 01, 04)));
    }
    {
        Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("a0", "sid1"));
        assertEquals(4, dates.size());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Set(java.util.Set) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) Test(org.junit.Test)

Example 57 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarExtensionStrategyTest method setup.

@Before
public void setup() throws IOException {
    _gtfs = MockGtfs.create();
    _gtfs.putAgencies(1);
    _gtfs.putStops(2);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimes("t0", "s0,s1");
    _strategy.setInactiveCalendarCutoff(new ServiceDate(2012, 12, 17));
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Before(org.junit.Before)

Example 58 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarSimplicationStrategyTest method testBasicSimplification.

@Test
public void testBasicSimplification() {
    _gtfs.putAgencies(1);
    _gtfs.putStops(1);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimes("t0", "s0");
    _gtfs.putCalendars(1, "start_date=20120903", "end_date=20120916");
    _gtfs.putCalendarDates("sid0=20120917,20120918,20120919,20120920,20120921,20120922,20120923");
    GtfsRelationalDao dao = transform();
    AgencyAndId serviceId = new AgencyAndId("a0", "sid0");
    ServiceCalendar c = dao.getCalendarForServiceId(serviceId);
    assertEquals(new ServiceDate(2012, 9, 3), c.getStartDate());
    assertEquals(new ServiceDate(2012, 9, 23), c.getEndDate());
    List<ServiceCalendarDate> serviceDates = dao.getCalendarDatesForServiceId(serviceId);
    assertEquals(0, serviceDates.size());
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 59 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class VerifyBusService method createServiceDate.

private ServiceDate createServiceDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    return new ServiceDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH));
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Calendar(java.util.Calendar)

Example 60 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class DeferredValueConverterTest method testCsvFieldMappingServiceDate.

@Test
public void testCsvFieldMappingServiceDate() {
    Object value = convert(new ServiceCalendar(), "startDate", "20130105");
    assertEquals(new ServiceDate(2013, 1, 5), value);
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Aggregations

ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)134 Test (org.junit.Test)49 Date (java.util.Date)46 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)45 ArrayList (java.util.ArrayList)23 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)23 Calendar (java.util.Calendar)22 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)22 HashSet (java.util.HashSet)17 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)14 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)13 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)13 Set (java.util.Set)11 Trip (org.onebusaway.gtfs.model.Trip)11 TimeZone (java.util.TimeZone)10 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)10 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)9 Agency (org.onebusaway.gtfs.model.Agency)8 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)7