Example usage for org.joda.time IllegalFieldValueException getUpperBound

List of usage examples for org.joda.time IllegalFieldValueException getUpperBound

Introduction

In this page you can find the example usage for org.joda.time IllegalFieldValueException getUpperBound.

Prototype

public Number getUpperBound() 

Source Link

Document

Returns the upper bound of the legal value range, or null if not applicable.

Usage

From source file:se.vgregion.webbisar.types.BirthTime.java

License:Open Source License

public BirthTime(int year, int month, int day, int hour, int minutes) {
    boolean error = true;
    int cnt = 0;//from w w w.  j a  v a2  s. c  om
    // FIX: This is kind of an hack to make this class kind of "fail safe"
    while (error && cnt++ < 10) {
        try {
            new DateTime(year, month, day, hour, minutes, 0, 0);
            error = false;
        } catch (IllegalFieldValueException e) {
            String s = e.getFieldName();
            LOGGER.error("Failed to create DateTime object.", e);
            if ("dayOfMonth".equals(s)) {
                day = (day > e.getUpperBound().intValue()) ? e.getUpperBound().intValue()
                        : e.getLowerBound().intValue();
            } else if ("monthOfYear".equals(s)) {
                month = (month > e.getUpperBound().intValue()) ? e.getUpperBound().intValue()
                        : e.getLowerBound().intValue();
            } else if ("hourOfDay".equals(s)) {
                hour = (hour > e.getUpperBound().intValue()) ? e.getUpperBound().intValue()
                        : e.getLowerBound().intValue();
            } else if ("minuteOfHour".equals(s)) {
                minutes = (minutes > e.getUpperBound().intValue()) ? e.getUpperBound().intValue()
                        : e.getLowerBound().intValue();
            }
        }
    }
    this.day = day;
    this.hour = hour;
    this.minutes = minutes;
    this.month = month;
    this.year = year;
}