Example usage for org.joda.time IllegalFieldValueException getLowerBound

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

Introduction

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

Prototype

public Number getLowerBound() 

Source Link

Document

Returns the lower 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   ww  w.  jav a2s. c o m
    // 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;
}