Search in sources :

Example 36 with LocalTime

use of org.joda.time.LocalTime in project jsonschema2pojo by joelittlejohn.

the class JodaDatesIT method useJodaLocalTimesCausesLocalTimeDefaultValues.

@Test
public void useJodaLocalTimesCausesLocalTimeDefaultValues() throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, InvocationTargetException {
    ClassLoader classLoader = schemaRule.generateAndCompile("/schema/default/default.json", "com.example", config("useJodaLocalTimes", true));
    Class<?> classWithDefaults = classLoader.loadClass("com.example.Default");
    Object instance = classWithDefaults.newInstance();
    Method getter = classWithDefaults.getMethod("getTimeAsStringWithDefault");
    assertThat((LocalTime) getter.invoke(instance), is(equalTo(new LocalTime("16:15:00"))));
}
Also used : LocalTime(org.joda.time.LocalTime) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 37 with LocalTime

use of org.joda.time.LocalTime in project uPortal by Jasig.

the class PortalEventDimensionPopulatorImpl method doPopulateTimeDimensions.

/**
 * Populate the time dimensions
 */
final void doPopulateTimeDimensions() {
    final List<TimeDimension> timeDimensions = this.timeDimensionDao.getTimeDimensions();
    if (timeDimensions.isEmpty()) {
        logger.info("No TimeDimensions exist, creating them");
    } else if (timeDimensions.size() != (24 * 60)) {
        this.logger.info("There are only " + timeDimensions.size() + " time dimensions in the database, there should be " + (24 * 60) + " creating missing dimensions");
    } else {
        this.logger.debug("Found expected " + timeDimensions.size() + " time dimensions");
        return;
    }
    LocalTime nextTime = new LocalTime(0, 0);
    final LocalTime lastTime = new LocalTime(23, 59);
    for (final TimeDimension timeDimension : timeDimensions) {
        LocalTime dimensionTime = timeDimension.getTime();
        if (nextTime.isBefore(dimensionTime)) {
            do {
                checkShutdown();
                this.timeDimensionDao.createTimeDimension(nextTime);
                nextTime = nextTime.plusMinutes(1);
            } while (nextTime.isBefore(dimensionTime));
        } else if (nextTime.isAfter(dimensionTime)) {
            do {
                checkShutdown();
                this.timeDimensionDao.createTimeDimension(dimensionTime);
                dimensionTime = dimensionTime.plusMinutes(1);
            } while (nextTime.isAfter(dimensionTime));
        }
        nextTime = dimensionTime.plusMinutes(1);
    }
    // Add any missing times from the tail
    while (nextTime.isBefore(lastTime) || nextTime.equals(lastTime)) {
        checkShutdown();
        this.timeDimensionDao.createTimeDimension(nextTime);
        if (nextTime.equals(lastTime)) {
            break;
        }
        nextTime = nextTime.plusMinutes(1);
    }
}
Also used : LocalTime(org.joda.time.LocalTime)

Example 38 with LocalTime

use of org.joda.time.LocalTime in project uPortal by Jasig.

the class PortalEventDimensionPopulatorImplTest method populateSomeTimeDimensions.

@Test
public void populateSomeTimeDimensions() {
    final Builder<Object> existingTimeDimensionBuilder = ImmutableList.builder();
    TimeDimension td = mock(TimeDimension.class);
    when(td.getTime()).thenReturn(new LocalTime(0, 1));
    existingTimeDimensionBuilder.add(td);
    final List<TimeDimension> existingTimeDimensions = ImmutableList.of(createMockTimeDimension(new LocalTime(0, 1)), createMockTimeDimension(new LocalTime(0, 2)), createMockTimeDimension(new LocalTime(0, 3)), createMockTimeDimension(new LocalTime(0, 4)), createMockTimeDimension(new LocalTime(0, 7)), createMockTimeDimension(new LocalTime(0, 8)), createMockTimeDimension(new LocalTime(0, 9)), createMockTimeDimension(new LocalTime(1, 23)), createMockTimeDimension(new LocalTime(23, 58)));
    when(timeDimensionDao.getTimeDimensions()).thenReturn(existingTimeDimensions);
    this.portalEventDimensionPopulator.doPopulateTimeDimensions();
    verify(timeDimensionDao).getTimeDimensions();
    verify(timeDimensionDao, times((60 * 24) - existingTimeDimensions.size())).createTimeDimension(ArgumentMatchers.<LocalTime>any());
    verifyNoMoreInteractions(timeDimensionDao, dateDimensionDao);
}
Also used : LocalTime(org.joda.time.LocalTime) Test(org.junit.Test)

Example 39 with LocalTime

use of org.joda.time.LocalTime in project cayenne by apache.

the class LocalTimeTypeTest method testMaterializeObjectTimestamp.

public void testMaterializeObjectTimestamp() throws Exception {
    Object o = type.materializeObject(resultSet(new Timestamp(0)), 1, Types.TIMESTAMP);
    assertEquals(new LocalTime(0), o);
}
Also used : LocalTime(org.joda.time.LocalTime) Timestamp(java.sql.Timestamp)

Example 40 with LocalTime

use of org.joda.time.LocalTime in project cayenne by apache.

the class LocalTimeTypeTest method testSetJdbcObject.

public void testSetJdbcObject() throws Exception {
    PreparedStatement statement = new MockPreparedStatement(new MockConnection(), "update t set c = ?");
    LocalTime date = new LocalTime(0);
    type.setJdbcObject(statement, date, 1, Types.TIME, 0);
    Object object = ((MockPreparedStatement) statement).getParameter(1);
    assertEquals(Time.class, object.getClass());
    assertEquals(new LocalDate(0, DateTimeZone.UTC).toDateTime(date).getMillis(), ((Time) object).getTime());
    type.setJdbcObject(statement, date, 1, Types.TIMESTAMP, 0);
    object = ((MockPreparedStatement) statement).getParameter(1);
    assertEquals(Timestamp.class, object.getClass());
    assertEquals(new LocalDate(0, DateTimeZone.UTC).toDateTime(date).getMillis(), ((Timestamp) object).getTime());
    type.setJdbcObject(statement, null, 1, Types.TIMESTAMP, 0);
    object = ((MockPreparedStatement) statement).getParameter(1);
    assertNull(object);
}
Also used : LocalTime(org.joda.time.LocalTime) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockPreparedStatement(com.mockrunner.mock.jdbc.MockPreparedStatement) MockConnection(com.mockrunner.mock.jdbc.MockConnection) LocalDate(org.joda.time.LocalDate)

Aggregations

LocalTime (org.joda.time.LocalTime)81 Test (org.junit.Test)39 OpeningHours (io.jawg.osmcontributor.model.utils.OpeningHours)17 LocalDate (org.joda.time.LocalDate)14 DateTime (org.joda.time.DateTime)13 LocalDateTime (org.joda.time.LocalDateTime)13 Date (java.util.Date)11 DateTimeZone (org.joda.time.DateTimeZone)10 OpeningMonth (io.jawg.osmcontributor.model.utils.OpeningMonth)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)5 OpeningTime (io.jawg.osmcontributor.model.utils.OpeningTime)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 ContentValues (android.content.ContentValues)2 Time (java.sql.Time)2 EntityManager (javax.persistence.EntityManager)2 EntityTransaction (javax.persistence.EntityTransaction)2 JodaSample3 (org.datanucleus.samples.types.jodatime.JodaSample3)2 DatePickerDialog (android.app.DatePickerDialog)1 TimePickerDialog (android.app.TimePickerDialog)1