Java Code Examples for org.joda.time.MutableDateTime#setHourOfDay()

The following examples show how to use org.joda.time.MutableDateTime#setHourOfDay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLGregorianCalendarToDateTimeConverter.java    From components with Apache License 2.0 6 votes vote down vote up
@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
    if (xts == null) {
        return null;
    }

    MutableDateTime dateTime = new MutableDateTime();
    try {
        dateTime.setYear(xts.getYear());
        dateTime.setMonthOfYear(xts.getMonth());
        dateTime.setDayOfMonth(xts.getDay());
        dateTime.setHourOfDay(xts.getHour());
        dateTime.setMinuteOfHour(xts.getMinute());
        dateTime.setSecondOfMinute(xts.getSecond());
        dateTime.setMillisOfSecond(xts.getMillisecond());

        DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
        if (tz != null) {
            dateTime.setZoneRetainFields(tz);
        }

        return Long.valueOf(dateTime.getMillis());
    } catch (IllegalArgumentException e) {
        throw new ComponentException(e);
    }
}
 
Example 2
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJodaSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 3
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJISOSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 4
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJodaSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 5
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJISOSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 6
Source File: TestTextFields.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testHalfdayNames() {
    DateTimeFormatter printer = DateTimeFormat.forPattern("a");
    for (int i=0; i<ZONES.length; i++) {
        Chronology chrono = ISOChronology.getInstance(ZONES[i]);
        MutableDateTime mdt = new MutableDateTime(2004, 5, 30, 0, 20, 30, 40, chrono);
        for (int hour=0; hour<24; hour++) {
            mdt.setHourOfDay(hour);
            int halfday = mdt.get(chrono.halfdayOfDay());
            String halfdayText = printer.print(mdt);
            assertEquals(HALFDAYS[halfday], halfdayText);
        }
    }
}
 
Example 7
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJodaSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 8
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJISOSetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 9
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJodaSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime(GJChronology.getInstance());
    for (int i = 0; i < AVERAGE; i++) {
        start("Joda", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 10
Source File: DateTimePerformance.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void checkJISOSetGetHour() {
    int COUNT = COUNT_VERY_FAST;
    // Is it fair to use only MutableDateTime here? You decide.
    MutableDateTime dt = new MutableDateTime();
    for (int i = 0; i < AVERAGE; i++) {
        start("JISO", "setGetHour");
        for (int j = 0; j < COUNT; j++) {
            dt.setHourOfDay(13);
            int val = dt.getHourOfDay();
            if (dt == null) {System.out.println("Anti optimise");}
        }
        end(COUNT);
    }
}
 
Example 11
Source File: TestTextFields.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testHalfdayNames() {
    DateTimeFormatter printer = DateTimeFormat.forPattern("a");
    for (int i=0; i<ZONES.length; i++) {
        Chronology chrono = ISOChronology.getInstance(ZONES[i]);
        MutableDateTime mdt = new MutableDateTime(2004, 5, 30, 0, 20, 30, 40, chrono);
        for (int hour=0; hour<24; hour++) {
            mdt.setHourOfDay(hour);
            int halfday = mdt.get(chrono.halfdayOfDay());
            String halfdayText = printer.print(mdt);
            assertEquals(HALFDAYS[halfday], halfdayText);
        }
    }
}
 
Example 12
Source File: AlarmScheduler.java    From BaldPhone with Apache License 2.0 4 votes vote down vote up
static long nextTimeAlarmWillWorkInMs(@NonNull Alarm alarm) {
    final MutableDateTime mDateTime = MutableDateTime.now();
    {   //creating a date of today with the hours and minutes of the alarm
        mDateTime.setMillisOfSecond(0);
        mDateTime.setSecondOfMinute(0);
        mDateTime.setHourOfDay(alarm.getHour());
        mDateTime.setMinuteOfHour(alarm.getMinute());
    }

    final int baldDay = getBaldDay();

    {   //today or one time
        if ((alarm.getDays() & baldDay) == baldDay) {//today may have an alarm
            if ((alarm.getDays() == baldDay)) {
                if (mDateTime.isBeforeNow())
                    mDateTime.addWeeks(1);  //next week if today's time already passed
                return mDateTime.getMillis();
            } else {
                if (mDateTime.isAfterNow())
                    return mDateTime.getMillis();
            }
        } else if (alarm.getDays() == -1) {
            if (mDateTime.isBeforeNow())
                mDateTime.addDays(1);
            return mDateTime.getMillis();
        }
    }
    int selectedBaldDay = baldDay;

    {   //find next day
        for (int i = baldDay << 1; i != baldDay; i <<= 1) {
            if (i > D.Days.SATURDAY)
                i = D.Days.SUNDAY;

            if ((alarm.getDays() & i) == i) {
                selectedBaldDay = i;
                break;
            }

        }
    }

    int day = baldDayToJodaDay(selectedBaldDay);
    mDateTime.setDayOfWeek(day);
    if (mDateTime.isBeforeNow()) {
        mDateTime.addWeeks(1);
    }
    return mDateTime.getMillis();
}
 
Example 13
Source File: ReminderScheduler.java    From BaldPhone with Apache License 2.0 4 votes vote down vote up
private static long nextTimeReminderWillWorkInMs(@NonNull Reminder reminder, Context context) {
    final MutableDateTime mDateTime = MutableDateTime.now();

    {   //creating a date of today with the hours and minutes of the alarm
        mDateTime.setMillisOfSecond(0);
        mDateTime.setSecondOfMinute(0);

        mDateTime.setHourOfDay(BPrefs.getHour(reminder.getStartingTime(), context));
        mDateTime.setMinuteOfHour(BPrefs.getMinute(reminder.getStartingTime(), context));
    }

    final int baldDay = getBaldDay();
    final int days = reminder.getDays();
    {   //today or one time
        if ((days & baldDay) == baldDay) {//today may have an alarm
            if ((days == baldDay)) {
                if (mDateTime.isBeforeNow())
                    mDateTime.addWeeks(1);  //next week if today's time already passed
                return mDateTime.getMillis();
            } else {
                if (mDateTime.isAfterNow())
                    return mDateTime.getMillis();
            }
        } else if (days == -1) {
            if (mDateTime.isBeforeNow())
                mDateTime.addDays(1);
            return mDateTime.getMillis();
        }
    }

    int selectedBaldDay = baldDay;

    {   //find next day
        for (int i = baldDay << 1; i != baldDay; i <<= 1) {
            if (i > D.Days.SATURDAY)
                i = D.Days.SUNDAY;

            if ((days & i) == i) {
                selectedBaldDay = i;
                break;
            }

        }
    }

    int day = baldDayToJodaDay(selectedBaldDay);
    mDateTime.setDayOfWeek(day);
    if (mDateTime.isBeforeNow()) {
        mDateTime.addWeeks(1);
    }
    return mDateTime.getMillis();
}
 
Example 14
Source File: SearchQueryTest.java    From components with Apache License 2.0 4 votes vote down vote up
@Test
public void testSearchDateField() throws Exception {
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss");

    Instant now = Instant.now();
    String currentDateFormatted = dateFormatter.print(now.getMillis());

    SearchQuery s1 = clientService.newSearch();
    s1.target("Check");
    s1.condition(new SearchCondition("TranDate", "Date.onOrAfter", Arrays.asList("2017-01-01 12:00:00")));
    s1.condition(new SearchCondition("CustomDateField1", "Date.onOrAfter", Arrays.asList("14:00:00")));

    SearchRecord sr1 = (SearchRecord) s1.toNativeQuery();
    assertNotNull(sr1);
    Assert.assertEquals(TransactionSearch.class, sr1.getClass());

    TransactionSearch search = (TransactionSearch) sr1;
    assertNotNull(search.getBasic());

    TransactionSearchBasic searchBasic = search.getBasic();
    assertNotNull(searchBasic.getTranDate());

    SearchDateField field1 = searchBasic.getTranDate();
    Assert.assertEquals(SearchDateFieldOperator.ON_OR_AFTER, field1.getOperator());
    assertNotNull(field1.getSearchValue());
    assertNull(field1.getSearchValue2());
    assertEquals("2017-01-01 12:00:00",
            dateTimeFormatter.print((Long) calendarValueConverter.convertToAvro(field1.getSearchValue())));

    SearchCustomFieldList customFieldList = searchBasic.getCustomFieldList();
    assertNotNull(customFieldList);
    assertNotNull(customFieldList.getCustomField());
    Assert.assertEquals(1, customFieldList.getCustomField().size());

    MutableDateTime controlDateTime = new MutableDateTime();
    controlDateTime.setHourOfDay(14);
    controlDateTime.setMinuteOfHour(0);
    controlDateTime.setSecondOfMinute(0);
    controlDateTime.setMillisOfSecond(0);
    String controlTimeFormatted = timeFormatter.print(controlDateTime);

    SearchDateCustomField customField1 = (SearchDateCustomField) customFieldList.getCustomField().get(0);
    Assert.assertEquals(SearchDateFieldOperator.ON_OR_AFTER, customField1.getOperator());
    assertNotNull(customField1.getSearchValue());
    assertNull(customField1.getSearchValue2());
    assertEquals(currentDateFormatted + " " + controlTimeFormatted,
            dateTimeFormatter.print((Long) calendarValueConverter.convertToAvro(customField1.getSearchValue())));
}