Example usage for org.joda.time IllegalFieldValueException getMessage

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

Introduction

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

Prototype

public String getMessage() 

Source Link

Usage

From source file:org.filteredpush.qc.date.DateUtils.java

License:Apache License

/**
 * Compare two strings that should represent event dates (ingoring time, if not a date range)
 * /*from w  w w.  jav a 2  s  .com*/
 * @param eventDate to compare with second event date
 * @param secondEventDate to compare with
 * @return true if the two provided event dates represent the same interval.
 */
public static Boolean eventsAreSameInterval(String eventDate, String secondEventDate) {
    boolean result = false;
    try {
        Interval interval = null;
        Interval secondInterval = null;
        interval = DateUtils.extractDateInterval(eventDate);
        secondInterval = DateUtils.extractDateInterval(secondEventDate);
        logger.debug(interval.toString());
        logger.debug(secondInterval.toString());
        result = interval.equals(secondInterval);
    } catch (IllegalFieldValueException ex) {
        // field format error, can't parse as date, log at debug level.
        logger.debug(ex.getMessage());
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    return result;
}

From source file:org.jruby.RubyTime.java

License:LGPL

@JRubyMethod(meta = true)
public static IRubyObject at(ThreadContext context, IRubyObject recv, IRubyObject arg) {
    Ruby runtime = context.runtime;//from   w  w  w.  j a  v  a 2 s.co m
    final RubyTime time;

    if (arg instanceof RubyTime) {
        RubyTime other = (RubyTime) arg;
        time = new RubyTime(runtime, (RubyClass) recv, other.dt);
        time.setNSec(other.getNSec());
    } else {
        time = new RubyTime(runtime, (RubyClass) recv, new DateTime(0L, getLocalTimeZone(runtime)));

        long seconds = RubyNumeric.num2long(arg);
        long millisecs = 0;
        long nanosecs = 0;

        // In the case of two arguments, MRI will discard the portion of
        // the first argument after a decimal point (i.e., "floor").
        // However in the case of a single argument, any portion after
        // the decimal point is honored.
        if (arg instanceof RubyFloat || arg instanceof RubyRational) {
            double dbl = RubyNumeric.num2dbl(arg);
            long nano;

            nano = Math.round((dbl - seconds) * 1000000000);

            if (dbl < 0 && nano != 0) {
                nano += 1000000000;
            }
            millisecs = nano / 1000000;
            nanosecs = nano % 1000000;
        }
        time.setNSec(nanosecs);
        try {
            time.dt = time.dt.withMillis(seconds * 1000 + millisecs);
        }
        // joda-time 2.5 can throw this exception - seen locally
        catch (ArithmeticException e1) {
            throw runtime.newRangeError(e1.getMessage());
        }
        // joda-time 2.5 can throw this exception - seen on travis
        catch (IllegalFieldValueException e2) {
            throw runtime.newRangeError(e2.getMessage());
        }
    }

    time.getMetaClass().getBaseCallSite(RubyClass.CS_IDX_INITIALIZE).call(context, recv, time);

    return time;
}