Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2013 Stephen Colebourne
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 package org.joda.time.field;
 
Precise datetime field, which has a precise unit duration field.

PreciseDurationDateTimeField is thread-safe and immutable, and its subclasses must be as well.

Author(s):
Brian S O'Neill
Since:
1.0
 
 public abstract class PreciseDurationDateTimeField extends BaseDateTimeField {
 
     @SuppressWarnings("unused")
     private static final long serialVersionUID = 5004523158306266035L;

    
The fractional unit in millis
 
     final long iUnitMillis;
 
     private final DurationField iUnitField;

    
Constructor.

Parameters:
type the field type
unit precise unit duration, like "days()".
Throws:
java.lang.IllegalArgumentException if duration field is imprecise
java.lang.IllegalArgumentException if unit milliseconds is less than one
 
         super(type);
 
         if (!unit.isPrecise()) {
             throw new IllegalArgumentException("Unit duration field must be precise");
         }
 
          = unit.getUnitMillis();
         if ( < 1) {
             throw new IllegalArgumentException("The unit milliseconds must be at least 1");
         }
 
          = unit;
     }

    
Returns false by default.
 
     public boolean isLenient() {
         return false;
     }

    
Set the specified amount of units to the specified time instant.

Parameters:
instant the milliseconds from 1970-01-01T00:00:00Z to set in
value value of units to set.
Returns:
the updated time instant.
Throws:
java.lang.IllegalArgumentException if value is too large or too small.
 
     public long set(long instantint value) {
         FieldUtils.verifyValueBounds(thisvaluegetMinimumValue(),
                                      getMaximumValueForSet(instantvalue));
         return instant + (value - get(instant)) * ;
     }

    
This method assumes that this field is properly rounded on 1970-01-01T00:00:00. If the rounding alignment differs, override this method as follows:
 return super.roundFloor(instant + ALIGNMENT_MILLIS) - ALIGNMENT_MILLIS;
 
 
     public long roundFloor(long instant) {
         if (instant >= 0) {
             return instant - instant % ;
         } else {
             instant += 1;
             return instant - instant %  - ;
         }
     }

    
This method assumes that this field is properly rounded on 1970-01-01T00:00:00. If the rounding alignment differs, override this method as follows:
 return super.roundCeiling(instant + ALIGNMENT_MILLIS) - ALIGNMENT_MILLIS;
 
    public long roundCeiling(long instant) {
        if (instant > 0) {
            instant -= 1;
            return instant - instant %  + ;
        } else {
            return instant - instant % ;
        }
    }

    
This method assumes that this field is properly rounded on 1970-01-01T00:00:00. If the rounding alignment differs, override this method as follows:
 return super.remainder(instant + ALIGNMENT_MILLIS);
 
    public long remainder(long instant) {
        if (instant >= 0) {
            return instant % ;
        } else {
            return (instant + 1) %  +  - 1;
        }
    }

    
Returns the duration per unit value of this field. For example, if this field represents "minute of hour", then the duration field is minutes.

Returns:
the duration of this field, or UnsupportedDurationField if field has no duration
    public DurationField getDurationField() {
        return ;
    }

    
Get the minimum value for the field.

Returns:
the minimum value
    public int getMinimumValue() {
        return 0;
    }
    public final long getUnitMillis() {
        return ;
    }

    
Called by the set method to get the maximum allowed value. By default, returns getMaximumValue(instant). Override to provide a faster implementation.
    protected int getMaximumValueForSet(long instantint value) {
        return getMaximumValue(instant);
    }
New to GrepCode? Check out our FAQ X