use of org.joda.time.LocalTime in project joda-time-android by dlew.
the class TestDateUtils method testGetRelativeDateTimeString.
public void testGetRelativeDateTimeString() {
Context ctx = getInstrumentation().getContext();
assertEquals("0 seconds ago, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow, null, 0));
assertEquals("in 30 seconds, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusSeconds(30), null, 0));
assertEquals("30 seconds ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, 0));
assertEquals("in 30 minutes, 13:05", DateUtils.getRelativeDateTimeString(ctx, mNow.plusMinutes(30), null, 0));
assertEquals("30 minutes ago, 12:05", DateUtils.getRelativeDateTimeString(ctx, mNow.minusMinutes(30), null, 0));
assertEquals("in 3 hours, 15:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusHours(3), null, 0));
assertEquals("3 hours ago, 09:35", DateUtils.getRelativeDateTimeString(ctx, mNow.minusHours(3), null, 0));
assertEquals("Oct 25, 1995, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusDays(3), null, 0));
assertEquals("Oct 19, 1995, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.minusDays(3), null, 0));
// Test abbreviation
assertEquals("in 30 secs, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusSeconds(30), null, DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("30 secs ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, DateUtils.FORMAT_ABBREV_RELATIVE));
// Test transition resolution
DateTime dt = DateTime.now().plusDays(2);
assertEquals("in 2 days, 12:35", DateUtils.getRelativeDateTimeString(ctx, dt, Days.TWO, 0));
assertEquals("Oct 24, 1995, 12:35", DateUtils.getRelativeDateTimeString(ctx, dt.plusSeconds(1), Days.TWO, 0));
assertEquals("in 2 days, 12:35", DateUtils.getRelativeDateTimeString(ctx, dt, Days.THREE, 0));
// Test partial input
LocalTime lt = LocalTime.now();
assertEquals("in 30 seconds, 12:35", DateUtils.getRelativeDateTimeString(ctx, lt.plusSeconds(30), null, 0));
assertEquals("30 seconds ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, lt.minusSeconds(30), null, 0));
assertEquals("in 30 minutes, 13:05", DateUtils.getRelativeDateTimeString(ctx, lt.plusMinutes(30), null, 0));
assertEquals("30 minutes ago, 12:05", DateUtils.getRelativeDateTimeString(ctx, lt.minusMinutes(30), null, 0));
// Test bad partial input
try {
assertEquals("Oct 24, 1995, 12:35", DateUtils.getRelativeDateTimeString(ctx, LocalDate.now(), null, 0));
fail("DateUtils.getRelativeDateTimeString() should have thrown an error since LocalDate has no time.");
} catch (Exception e) {
}
}
use of org.joda.time.LocalTime in project gerrit by GerritCodeReview.
the class ScheduleConfig method initialDelay.
private static long initialDelay(Config rc, String section, String subsection, String keyStartTime, DateTime now, long interval) {
long delay = MISSING_CONFIG;
String start = rc.getString(section, subsection, keyStartTime);
try {
if (start != null) {
DateTimeFormatter formatter;
MutableDateTime startTime = now.toMutableDateTime();
try {
formatter = ISODateTimeFormat.hourMinute();
LocalTime firstStartTime = formatter.parseLocalTime(start);
startTime.hourOfDay().set(firstStartTime.getHourOfDay());
startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour());
} catch (IllegalArgumentException e1) {
formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US);
LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start);
startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek());
startTime.hourOfDay().set(firstStartDateTime.getHourOfDay());
startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour());
}
startTime.secondOfMinute().set(0);
startTime.millisOfSecond().set(0);
long s = startTime.getMillis();
long n = now.getMillis();
delay = (s - n) % interval;
if (delay <= 0) {
delay += interval;
}
} else {
log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section, keyStartTime));
}
} catch (IllegalArgumentException e2) {
log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime), e2);
delay = INVALID_CONFIG;
}
return delay;
}
use of org.joda.time.LocalTime in project joda-time by JodaOrg.
the class TestDateTimeFormatter method testParseLocalTime_simple.
//-----------------------------------------------------------------------
public void testParseLocalTime_simple() {
assertEquals(new LocalTime(10, 20, 30), g.parseLocalTime("2004-06-09T10:20:30Z"));
assertEquals(new LocalTime(10, 20, 30), g.parseLocalTime("2004-06-09T10:20:30+18:00"));
assertEquals(new LocalTime(10, 20, 30), g.parseLocalTime("2004-06-09T10:20:30-18:00"));
assertEquals(new LocalTime(10, 20, 30, 0, BUDDHIST_PARIS), g.withChronology(BUDDHIST_PARIS).parseLocalTime("2004-06-09T10:20:30Z"));
try {
g.parseDateTime("ABC");
fail();
} catch (IllegalArgumentException ex) {
}
}
use of org.joda.time.LocalTime in project SimpleFlatMapper by arnaudroger.
the class CellValueReaderFactoryImplTest method testJodaLocalTime.
@Test
public void testJodaLocalTime() {
String date = "20150128";
LocalTime localTime = DateTimeFormat.forPattern("yyyyMMdd").parseLocalTime(date);
CellValueReader<?> reader = cellValueReaderFactory.getReader(LocalTime.class, 0, CsvColumnDefinition.dateFormatDefinition("yyyyMMdd"), null);
assertEquals(localTime, reader.read(date.toCharArray(), 0, date.length(), null));
}
use of org.joda.time.LocalTime in project serenity-jbehave by serenity-bdd.
the class WhenConvertingJodaDateTimes method should_convert_time_string_to_LocalTimes.
@Test
public void should_convert_time_string_to_LocalTimes() {
TimeConverter converter = new TimeConverter();
LocalTime convertedTime = (LocalTime) converter.convertValue("18:12", LocalTime.class);
assertThat(convertedTime.getHourOfDay()).isEqualTo(18);
assertThat(convertedTime.getMinuteOfHour()).isEqualTo(12);
}
Aggregations