Example usage for org.joda.time.base AbstractPartial getFieldTypes

List of usage examples for org.joda.time.base AbstractPartial getFieldTypes

Introduction

In this page you can find the example usage for org.joda.time.base AbstractPartial getFieldTypes.

Prototype

public DateTimeFieldType[] getFieldTypes() 

Source Link

Document

Gets an array of the field types that this partial supports.

Usage

From source file:pt.ist.fenixWebFramework.rendererExtensions.PartialRenderer.java

License:Open Source License

private Calendar convertPartialToCalendar(AbstractPartial partial) {
    Calendar calendar = Calendar.getInstance();
    calendar.clear();//from  w ww.  j a  va2  s.c  o m

    DateTimeFieldType[] fieldTypes = partial.getFieldTypes();
    for (DateTimeFieldType fieldType : fieldTypes) {
        if (fieldType.equals(DateTimeFieldType.dayOfMonth())) {
            calendar.set(Calendar.DAY_OF_MONTH, partial.get(DateTimeFieldType.dayOfMonth()));
            continue;
        }

        if (fieldType.equals(DateTimeFieldType.monthOfYear())) {
            calendar.set(Calendar.MONTH, partial.get(DateTimeFieldType.monthOfYear()) - 1);
            continue;
        }

        if (fieldType.equals(DateTimeFieldType.year())) {
            calendar.set(Calendar.YEAR, partial.get(DateTimeFieldType.year()));
            continue;
        }

        if (fieldType.equals(DateTimeFieldType.hourOfDay())) {
            calendar.set(Calendar.HOUR_OF_DAY, partial.get(DateTimeFieldType.hourOfDay()));
            continue;
        }

        if (fieldType.equals(DateTimeFieldType.minuteOfHour())) {
            calendar.set(Calendar.MINUTE, partial.get(DateTimeFieldType.minuteOfHour()));
            continue;
        }

        if (fieldType.equals(DateTimeFieldType.secondOfMinute())) {
            calendar.set(Calendar.SECOND, partial.get(DateTimeFieldType.secondOfMinute()));
            continue;
        }
    }

    return calendar;
}