Search in sources :

Example 6 with LocalTime

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) {
    }
}
Also used : Context(android.content.Context) LocalTime(org.joda.time.LocalTime) DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 7 with LocalTime

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;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) LocalTime(org.joda.time.LocalTime) MutableDateTime(org.joda.time.MutableDateTime) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 8 with LocalTime

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) {
    }
}
Also used : LocalTime(org.joda.time.LocalTime)

Example 9 with LocalTime

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));
}
Also used : LocalTime(org.joda.time.LocalTime) Test(org.junit.Test)

Example 10 with LocalTime

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);
}
Also used : LocalTime(org.joda.time.LocalTime) Test(org.junit.Test)

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