Search in sources :

Example 41 with ServiceDate

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

the class ServiceCalendarDateComparator method compare.

@Override
public int compare(ServiceCalendarDate o1, ServiceCalendarDate o2) {
    AgencyAndId id1 = o1.getServiceId();
    AgencyAndId id2 = o2.getServiceId();
    int c = id1.compareTo(id2);
    if (c != 0)
        return c;
    ServiceDate d1 = o1.getDate();
    ServiceDate d2 = o2.getDate();
    return d1.compareTo(d2);
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId)

Example 42 with ServiceDate

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

the class CalendarServiceImplSyntheticTest method putServiceDatesForServiceId.

/**
 **
 * Private Methods
 ***
 */
private void putServiceDatesForServiceId(CalendarServiceData data, LocalizedServiceId lsid, List<ServiceDate> serviceDates) {
    data.putServiceDatesForServiceId(lsid.getId(), serviceDates);
    List<Date> dates = new ArrayList<Date>();
    for (ServiceDate serviceDate : serviceDates) dates.add(serviceDate.getAsDate(lsid.getTimeZone()));
    data.putDatesForLocalizedServiceId(lsid, dates);
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ArrayList(java.util.ArrayList) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date)

Example 43 with ServiceDate

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

the class GtfsReaderTest method testFeedInfo.

@Test
public void testFeedInfo() throws CsvEntityIOException, IOException {
    GtfsReader reader = new GtfsReader();
    StringBuilder b = new StringBuilder();
    b.append("feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date,feed_end_date,feed_version\n");
    b.append("Test,http://test/,en,20110928,20120131,1.0\n");
    reader.readEntities(FeedInfo.class, new StringReader(b.toString()));
    FeedInfo feedInfo = reader.getEntityStore().getEntityForId(FeedInfo.class, "1");
    assertEquals("Test", feedInfo.getPublisherName());
    assertEquals("http://test/", feedInfo.getPublisherUrl());
    assertEquals("en", feedInfo.getLang());
    assertEquals(new ServiceDate(2011, 9, 28), feedInfo.getStartDate());
    assertEquals(new ServiceDate(2012, 1, 31), feedInfo.getEndDate());
    assertEquals("1.0", feedInfo.getVersion());
    /**
     * Test with a missing "field_publisher_url" field
     */
    b = new StringBuilder();
    b.append("feed_publisher_name\n");
    b.append("Test\n");
    try {
        reader.readEntities(FeedInfo.class, new StringReader(b.toString()));
        fail();
    } catch (CsvEntityIOException ex) {
        MissingRequiredFieldException ex2 = (MissingRequiredFieldException) ex.getCause();
        assertEquals(FeedInfo.class, ex2.getEntityType());
        assertEquals("feed_publisher_url", ex2.getFieldName());
    }
    /**
     * Test with a missing "field_lang" field
     */
    b = new StringBuilder();
    b.append("feed_publisher_name,feed_publisher_url\n");
    b.append("Test,http://test/\n");
    try {
        reader.readEntities(FeedInfo.class, new StringReader(b.toString()));
        fail();
    } catch (CsvEntityIOException ex) {
        MissingRequiredFieldException ex2 = (MissingRequiredFieldException) ex.getCause();
        assertEquals(FeedInfo.class, ex2.getEntityType());
        assertEquals("feed_lang", ex2.getFieldName());
    }
    /**
     * Test with a malformed "feed_start_date" field
     */
    b = new StringBuilder();
    b.append("feed_publisher_name,feed_publisher_url,feed_lang,feed_start_date\n");
    b.append("Test,http://test/,en,2011XX01\n");
    try {
        reader.readEntities(FeedInfo.class, new StringReader(b.toString()));
        fail();
    } catch (CsvEntityIOException ex) {
        InvalidValueEntityException ex2 = (InvalidValueEntityException) ex.getCause();
        assertEquals(FeedInfo.class, ex2.getEntityType());
        assertEquals("feed_start_date", ex2.getFieldName());
        assertEquals("2011XX01", ex2.getFieldValue());
    }
    /**
     * Test with a malformed "feed_end_date" field
     */
    b = new StringBuilder();
    b.append("feed_publisher_name,feed_publisher_url,feed_lang,feed_end_date\n");
    b.append("Test,http://test/,en,2011XX01\n");
    try {
        reader.readEntities(FeedInfo.class, new StringReader(b.toString()));
        fail();
    } catch (CsvEntityIOException ex) {
        InvalidValueEntityException ex2 = (InvalidValueEntityException) ex.getCause();
        assertEquals(FeedInfo.class, ex2.getEntityType());
        assertEquals("feed_end_date", ex2.getFieldName());
        assertEquals("2011XX01", ex2.getFieldValue());
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) MissingRequiredFieldException(org.onebusaway.csv_entities.exceptions.MissingRequiredFieldException) CsvEntityIOException(org.onebusaway.csv_entities.exceptions.CsvEntityIOException) StringReader(java.io.StringReader) InvalidValueEntityException(org.onebusaway.csv_entities.exceptions.InvalidValueEntityException) Test(org.junit.Test)

Example 44 with ServiceDate

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

the class ServiceDateFieldMappingFactoryTest method test.

@Test
public void test() {
    ServiceDateFieldMappingFactory factory = new ServiceDateFieldMappingFactory();
    DefaultEntitySchemaFactory schemaFactory = new DefaultEntitySchemaFactory();
    String propName = "date";
    FieldMapping mapping = factory.createFieldMapping(schemaFactory, Dummy.class, propName, propName, ServiceDate.class, true);
    CsvEntityContext context = new CsvEntityContextImpl();
    Map<String, Object> csvValues = new HashMap<String, Object>();
    csvValues.put(propName, "20100212");
    Dummy obj = new Dummy();
    BeanWrapper wrapped = BeanWrapperFactory.wrap(obj);
    mapping.translateFromCSVToObject(context, csvValues, wrapped);
    assertEquals(new ServiceDate(2010, 2, 12), obj.getDate());
    csvValues.clear();
    mapping.translateFromObjectToCSV(context, wrapped, csvValues);
    assertEquals("20100212", csvValues.get(propName));
}
Also used : CsvEntityContextImpl(org.onebusaway.csv_entities.CsvEntityContextImpl) BeanWrapper(org.onebusaway.csv_entities.schema.BeanWrapper) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) HashMap(java.util.HashMap) FieldMapping(org.onebusaway.csv_entities.schema.FieldMapping) CsvEntityContext(org.onebusaway.csv_entities.CsvEntityContext) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) Test(org.junit.Test)

Example 45 with ServiceDate

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

the class ServiceDateTest method testGetAsDateWithTimezoneB.

@Test
public void testGetAsDateWithTimezoneB() {
    // DST Spring Forward
    ServiceDate serviceDateA = new ServiceDate(2010, 3, 14);
    TimeZone tzA = TimeZone.getTimeZone("America/Los_Angeles");
    Date dateA = serviceDateA.getAsDate(tzA);
    assertEquals(date("2010-03-13 23:00 Pacific Standard Time"), dateA);
    TimeZone tzB = TimeZone.getTimeZone("America/Denver");
    Date dateB = serviceDateA.getAsDate(tzB);
    assertEquals(date("2010-03-13 23:00 Mountain Standard Time"), dateB);
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) TimeZone(java.util.TimeZone) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) 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