Example usage for org.joda.time DateTime getHourOfDay

List of usage examples for org.joda.time DateTime getHourOfDay

Introduction

In this page you can find the example usage for org.joda.time DateTime getHourOfDay.

Prototype

public int getHourOfDay() 

Source Link

Document

Get the hour of day field value.

Usage

From source file:org.richfaces.fragment.calendar.TimeEditor.java

License:Open Source License

public DateTime getTime() {
    int seconds = (getSecondsSpinner() != null ? getSecondsSpinner().getValue() : defaultSeconds);
    int minutes = (getMinutesSpinner() != null ? getMinutesSpinner().getValue() : defaultMinutes);
    int hours = (getHoursSpinner() != null ? getHoursSpinner().getValue() : defaultHours);
    DateTime result = new DateTime().withHourOfDay(hours).withMinuteOfHour(minutes).withSecondOfMinute(seconds);
    TimeSignSpinner tss = getTimeSignSpinner();
    if (tss != null) {
        switch (tss.getValue()) {
        case AM://from w ww.ja  va2  s.co  m
            if (result.getHourOfDay() == 12) {//12:xx am -> 00:xx
                result = result.minusHours(12);
            }
            break;
        case PM:
            if (result.getHourOfDay() != 12) {
                result = result.plusHours(12);
            }
            break;
        default:
            throw new IllegalArgumentException("Unknown switch");
        }
    }
    return result;
}

From source file:org.richfaces.fragment.calendar.TimeEditor.java

License:Open Source License

public TimeEditor setTime(DateTime time, SetValueBy inputType) {
    return setTime(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), inputType);
}

From source file:org.richfaces.tests.page.fragments.impl.calendar.common.editor.time.RichFacesTimeEditor.java

License:Open Source License

@Override
public DateTime getTime() {
    int seconds = (getSecondsSpinner() != null ? getSecondsSpinner().getValue() : defaultSeconds);
    int minutes = (getMinutesSpinner() != null ? getMinutesSpinner().getValue() : defaultMinutes);
    int hours = (getHoursSpinner() != null ? getHoursSpinner().getValue() : defaultHours);
    DateTime result = new DateTime().withHourOfDay(hours).withMinuteOfHour(minutes).withSecondOfMinute(seconds);
    RichFacesTimeSignSpinner tss = getTimeSignSpinner();
    if (tss != null) {
        switch (tss.getValue()) {
        case AM:/* w  w w. j a v  a  2  s  .co  m*/
            if (result.getHourOfDay() == 12) {//12:xx am -> 00:xx
                result = result.minusHours(12);
            }
            break;
        case PM:
            if (result.getHourOfDay() != 12) {
                result = result.plusHours(12);
            }
            break;
        default:
            throw new IllegalArgumentException("Unknown switch");
        }
    }
    return result;
}

From source file:org.richfaces.tests.page.fragments.impl.calendar.common.editor.time.RichFacesTimeEditor.java

License:Open Source License

@Override
public TimeEditor setTime(DateTime time, SetValueBy inputType) {
    return setTime(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), inputType);
}

From source file:org.rockholla.date.DateUtility.java

License:Open Source License

/**
 * Formats a datetime for use in a MySQL datetime field
 * /*from   w ww  . j  ava  2s. co m*/
 * @param dateTime   the org.joda.time.DateTime value to format
 * @param offset   offset the input datetime by this amount of hours
 * @return         the formatted datetime
 */
public static String getMySqlDate(DateTime dateTime, int offset) {

    if (offset > 0 || offset < 0) {
        dateTime = dateTime.plusHours(offset);
    }

    String result = String.valueOf(dateTime.getYear()) + "-"
            + NumberUtility.format(dateTime.getMonthOfYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + "-"
            + NumberUtility.format(dateTime.getDayOfMonth(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + " "
            + NumberUtility.format(dateTime.getHourOfDay(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":"
            + NumberUtility.format(dateTime.getMinuteOfHour(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":"
            + NumberUtility.format(dateTime.getSecondOfMinute(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER);

    return result;

}

From source file:org.rockholla.date.DateUtility.java

License:Open Source License

/**
 * Returns a unique string based on a timestamp (DateTime must be precise to the second
 * to ensure uniqueness)/*www.j  av a  2 s . co  m*/
 * 
 * @param dateTime   the org.joda.time.DateTime to use to create the ID
 * @return         a unique string representation of the date
 */
public static String getTimestampId(DateTime dateTime) {

    String id = "";

    id = NumberUtility.format(dateTime.getYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getMonthOfYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getDayOfMonth(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getHourOfDay(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getMinuteOfHour(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getSecondOfMinute(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getMillisOfSecond(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER);

    return id;

}

From source file:org.shadowmask.core.mask.rules.generalizer.impl.TimestampGeneralizer.java

License:Apache License

@Override
public Long generalize(Long timestamp, int hierarchyLevel) {
    if (timestamp == null) {
        return null;
    }//  w  w  w  .  j a  v a  2  s.  c  o  m

    if (hierarchyLevel > ROOT_HIERARCHY_LEVEL || hierarchyLevel < 0) {
        throw new MaskRuntimeException("Root hierarchy level of MobileGeneralizer is " + ROOT_HIERARCHY_LEVEL
                + ", invalid input hierarchy level[" + hierarchyLevel + "]");
    }

    if (hierarchyLevel == 0) {
        return timestamp;
    }

    try {
        DateTime dateTime = new DateTime(timestamp);
        switch (hierarchyLevel) {
        // mask ms.
        case 1:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute());
            break;
        // mask second.
        case 2:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            break;
        // mask minute.
        case 3:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            break;
        // mask hour.
        case 4:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            dateTime = dateTime.hourOfDay().setCopy(0);
            break;
        // mask day.
        case 5:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            dateTime = dateTime.hourOfDay().setCopy(0);
            dateTime = dateTime.dayOfMonth().setCopy(1);
            break;
        // mask month.
        case 6:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            dateTime = dateTime.hourOfDay().setCopy(0);
            dateTime = dateTime.dayOfMonth().setCopy(1);
            dateTime = dateTime.monthOfYear().setCopy(1);
            break;
        // mask year.
        case 7:
            dateTime = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
                    dateTime.getHourOfDay(), dateTime.getMinuteOfHour());
            dateTime = dateTime.minuteOfHour().setCopy(0);
            dateTime = dateTime.hourOfDay().setCopy(0);
            dateTime = dateTime.dayOfMonth().setCopy(1);
            dateTime = dateTime.monthOfYear().setCopy(1);
            dateTime = dateTime.year().setCopy(1901);
            break;
        }

        return dateTime.getMillis();
    } catch (Throwable e) {
        throw new MaskRuntimeException("Invalid timestamp to generalize:" + timestamp, e);
    }
}

From source file:org.sonar.plugins.scmstats.measures.ChangeLogHandler.java

License:Open Source License

public void generateMeasures() {
    for (ChangeLogInfo changeLogInfo : changeLogs) {

        if (!ignoredAuthors.contains(changeLogInfo.getAuthor())) {
            commitsPerUser = updateAuthorActivity(commitsPerUser, changeLogInfo);

            DateTime dt = new DateTime(changeLogInfo.getCommitDate());

            commitsPerClockHour = MapUtils.updateMap(commitsPerClockHour,
                    String.format("%2d", dt.getHourOfDay()).replace(' ', '0'));
            commitsPerWeekDay = MapUtils.updateMap(commitsPerWeekDay, dt.dayOfWeek().getAsString());
            commitsPerMonth = MapUtils.updateMap(commitsPerMonth,
                    String.format("%2d", dt.getMonthOfYear()).replace(' ', '0'));
        }//from  w w  w. j a  v  a  2s  . c  o m
    }
}

From source file:org.springframework.analytics.metrics.memory.InMemoryAggregateCounter.java

License:Apache License

synchronized long increment(long amount, DateTime dateTime) {
    int year = dateTime.getYear();
    int month = dateTime.getMonthOfYear();
    int day = dateTime.getDayOfYear();
    int hour = dateTime.getHourOfDay();
    int minute = dateTime.getMinuteOfDay();

    long[] monthCounts = monthCountsByYear.get(year);
    long[] dayCounts = dayCountsByYear.get(year);

    if (monthCounts == null) {
        monthCounts = new long[12];
        monthCountsByYear.put(year, monthCounts);
        dayCounts = new long[daysInYear(year)];
        dayCountsByYear.put(year, dayCounts);
    }/*  www. j a  v  a2s.  c  om*/

    int countsByDayKey = year * 1000 + day;
    long[] hourCounts = hourCountsByDay.get(countsByDayKey);

    if (hourCounts == null) {
        hourCounts = new long[24];
        hourCountsByDay.put(countsByDayKey, hourCounts);
    }

    long[] minuteCounts = minuteCountsByDay.get(countsByDayKey);

    if (minuteCounts == null) {
        minuteCounts = new long[60 * 24];
        minuteCountsByDay.put(countsByDayKey, minuteCounts);
    }

    minuteCounts[minute] += amount;
    monthCounts[month - 1] += amount;
    dayCounts[day - 1] += amount;
    hourCounts[hour] += amount;

    return increment(amount);
}

From source file:org.talend.components.netsuite.AbstractNetSuiteTestBase.java

License:Open Source License

protected static XMLGregorianCalendar composeDateTime() throws Exception {
    DateTime dateTime = DateTime.now();

    XMLGregorianCalendar xts = datatypeFactory.newXMLGregorianCalendar();
    xts.setYear(dateTime.getYear());//  www .j  a v a  2 s .c  o m
    xts.setMonth(dateTime.getMonthOfYear());
    xts.setDay(dateTime.getDayOfMonth());
    xts.setHour(dateTime.getHourOfDay());
    xts.setMinute(dateTime.getMinuteOfHour());
    xts.setSecond(dateTime.getSecondOfMinute());
    xts.setMillisecond(dateTime.getMillisOfSecond());
    xts.setTimezone(dateTime.getZone().toTimeZone().getRawOffset() / 60000);

    return xts;

}