Java Code Examples for org.joda.time.DateTime#toGregorianCalendar()

The following examples show how to use org.joda.time.DateTime#toGregorianCalendar() . 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: JodaTimeConverters.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Calendar convert(DateTime source) {
	return source.toGregorianCalendar();
}
 
Example 2
Source File: JodaTimeConverters.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Calendar convert(DateTime source) {
	return source.toGregorianCalendar();
}
 
Example 3
Source File: JodaTimeConverters.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Calendar convert(DateTime source) {
	return source.toGregorianCalendar();
}
 
Example 4
Source File: JodaTimeConverters.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Calendar convert(DateTime source) {
	return source.toGregorianCalendar();
}
 
Example 5
Source File: AbstractMetricsAccessor.java    From apiman with Apache License 2.0 4 votes vote down vote up
/**
 * Generate the histogram buckets based on the time frame requested and the interval.  This will
 * add an entry for each 'slot' or 'bucket' in the histogram, setting the count to 0.
 * @param rval
 * @param from
 * @param to
 * @param interval
 */
public static <T extends HistogramDataPoint, K> Map<K, T> generateHistogramSkeleton(HistogramBean<T> rval, DateTime from, DateTime to,
        HistogramIntervalType interval, Class<T> dataType, Class<K> keyType) {
    Map<K, T> index = new HashMap<>();

    Calendar fromCal = from.toGregorianCalendar();
    Calendar toCal = to.toGregorianCalendar();

    switch(interval) {
        case day:
            fromCal.set(Calendar.HOUR_OF_DAY, 0);
            fromCal.set(Calendar.MINUTE, 0);
            fromCal.set(Calendar.SECOND, 0);
            fromCal.set(Calendar.MILLISECOND, 0);
            break;
        case hour:
            fromCal.set(Calendar.MINUTE, 0);
            fromCal.set(Calendar.SECOND, 0);
            fromCal.set(Calendar.MILLISECOND, 0);
            break;
        case minute:
            fromCal.set(Calendar.SECOND, 0);
            fromCal.set(Calendar.MILLISECOND, 0);
            break;
        case month:
            fromCal.set(Calendar.DAY_OF_MONTH, 1);
            fromCal.set(Calendar.HOUR_OF_DAY, 0);
            fromCal.set(Calendar.MINUTE, 0);
            fromCal.set(Calendar.SECOND, 0);
            fromCal.set(Calendar.MILLISECOND, 0);
            break;
        case week:
            fromCal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
            fromCal.set(Calendar.HOUR_OF_DAY, 0);
            fromCal.set(Calendar.MINUTE, 0);
            fromCal.set(Calendar.SECOND, 0);
            fromCal.set(Calendar.MILLISECOND, 0);
            break;
        default:
            break;
    }

    while (fromCal.before(toCal)) {
        String label = formatDateWithMillis(fromCal);
        T point;
        try {
            point = dataType.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        point.setLabel(label);
        rval.addDataPoint(point);
        if (keyType == String.class ) {
            index.put((K) label, point);
        } else {
            index.put((K) new Long(fromCal.getTimeInMillis()), point);
        }
        switch (interval) {
            case day:
                fromCal.add(Calendar.DAY_OF_YEAR, 1);
                break;
            case hour:
                fromCal.add(Calendar.HOUR_OF_DAY, 1);
                break;
            case minute:
                fromCal.add(Calendar.MINUTE, 1);
                break;
            case month:
                fromCal.add(Calendar.MONTH, 1);
                break;
            case week:
                fromCal.add(Calendar.WEEK_OF_YEAR, 1);
                break;
            default:
                break;
        }
    }

    return index;

}