Example usage for org.joda.time.field FieldUtils safeToInt

List of usage examples for org.joda.time.field FieldUtils safeToInt

Introduction

In this page you can find the example usage for org.joda.time.field FieldUtils safeToInt.

Prototype

public static int safeToInt(long value) 

Source Link

Document

Casts to an int throwing an exception if overflow occurs.

Usage

From source file:com.facebook.util.TimeIntervalType.java

License:Apache License

/**
 * Gets the start instant given the event instant, interval length 
 * and the time zone for this interval type.
 * /*w ww. java  2  s .  co  m*/
 * @param instant the event time instant.
 * @param length the interval length
 * 
 * @return the start instant of the interval of given length that contains 
 * the supplied time instant in the supplied time zone 
 */
public DateTime getTimeIntervalStart(DateTime instant, long length) {
    validateValue(instant.getZone(), length);
    // Get the time in the specified timezone
    DateTime periodStart = instant;
    // Clear all the fields for this intervalType and its subtypes
    TimeIntervalType timeIntervalType = this;
    while (timeIntervalType != null) {
        periodStart = timeIntervalType.clearField(periodStart);
        timeIntervalType = timeIntervalType.subType;
    }
    // figure out the which time interval does the instant lie in
    Period period = new Period(periodStart, instant, periodType);
    DurationField durationField = fieldType.getField(instant.getChronology()).getDurationField();
    int diff = period.get(durationField.getType());
    long startDelta = (diff / length) * length;
    return periodStart.withFieldAdded(durationField.getType(), FieldUtils.safeToInt(startDelta));
}

From source file:net.sourceforge.fenixedu.domain.time.chronologies.durationFields.AcademicSemestersDurationField.java

License:Open Source License

@Override
public long add(long instant, long value) {
    return add(instant, FieldUtils.safeToInt(value));
}

From source file:net.sourceforge.fenixedu.domain.time.chronologies.durationFields.AcademicSemestersDurationField.java

License:Open Source License

@Override
public long getMillis(long value, long instant) {
    return getMillis(FieldUtils.safeToInt(value), instant);
}