Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2001-2005 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;
 
Generic offset adjusting datetime field.

OffsetDateTimeField is thread-safe and immutable.

Author(s):
Brian S O'Neill
Since:
1.0
 
 public class OffsetDateTimeField extends DecoratedDateTimeField {
     private static final long serialVersionUID = 3145790132623583142L;
 
     private final int iOffset;
 
     private final int iMin;
     private final int iMax;

    
Constructor.

Parameters:
field the field to wrap, like "year()".
offset offset to add to field values
Throws:
java.lang.IllegalArgumentException if offset is zero
 
     public OffsetDateTimeField(DateTimeField fieldint offset) {
         this(field, (field == null ? null : field.getType()), offset..);
     }

    
Constructor.

Parameters:
field the field to wrap, like "year()".
type the field type this field actually uses
offset offset to add to field values
Throws:
java.lang.IllegalArgumentException if offset is zero
 
     public OffsetDateTimeField(DateTimeField fieldDateTimeFieldType typeint offset) {
         this(fieldtypeoffset..);
     }

    
Constructor.

Parameters:
field the field to wrap, like "year()".
type the field type this field actually uses
offset offset to add to field values
minValue minimum allowed value
maxValue maximum allowed value
Throws:
java.lang.IllegalArgumentException if offset is zero
 
     public OffsetDateTimeField(DateTimeField fieldDateTimeFieldType typeint offset,
                                int minValueint maxValue) {
         super(fieldtype);
                 
         if (offset == 0) {
             throw new IllegalArgumentException("The offset cannot be zero");
         }
 
          = offset;
 
         if (minValue < (field.getMinimumValue() + offset)) {
              = field.getMinimumValue() + offset;
         } else {
              = minValue;
         }
         if (maxValue > (field.getMaximumValue() + offset)) {
              = field.getMaximumValue() + offset;
         } else {
              = maxValue;
         }
     }

    
Get the amount of offset units from the specified time instant.

Parameters:
instant the time instant in millis to query.
Returns:
the amount of units extracted from the input.
 
     public int get(long instant) {
        return super.get(instant) + ;
    }

    
Add the specified amount of offset units to the specified time instant. The amount added may be negative.

Parameters:
instant the time instant in millis to update.
amount the amount of units to add (can be negative).
Returns:
the updated time instant.
    public long add(long instantint amount) {
        instant = super.add(instantamount);
        FieldUtils.verifyValueBounds(thisget(instant), );
        return instant;
    }

    
Add the specified amount of offset units to the specified time instant. The amount added may be negative.

Parameters:
instant the time instant in millis to update.
amount the amount of units to add (can be negative).
Returns:
the updated time instant.
    public long add(long instantlong amount) {
        instant = super.add(instantamount);
        FieldUtils.verifyValueBounds(thisget(instant), );
        return instant;
    }

    
Add to the offset component of the specified time instant, wrapping around within that component if necessary.

Parameters:
instant the time instant in millis to update.
amount the amount of units to add (can be negative).
Returns:
the updated time instant.
    public long addWrapField(long instantint amount) {
        return set(instant, FieldUtils.getWrappedValue(get(instant), amount));
    }

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

Parameters:
instant the time instant in millis to update.
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(thisvalue);
        return super.set(instant, value - );
    }
    public boolean isLeap(long instant) {
        return getWrappedField().isLeap(instant);
    }
    public int getLeapAmount(long instant) {
        return getWrappedField().getLeapAmount(instant);
    }
        return getWrappedField().getLeapDurationField();
    }

    
Get the minimum value for the field.

Returns:
the minimum value
    public int getMinimumValue() {
        return ;
    }

    
Get the maximum value for the field.

Returns:
the maximum value
    public int getMaximumValue() {
        return ;
    }
    
    public long roundFloor(long instant) {
        return getWrappedField().roundFloor(instant);
    }
    public long roundCeiling(long instant) {
        return getWrappedField().roundCeiling(instant);
    }
    public long roundHalfFloor(long instant) {
        return getWrappedField().roundHalfFloor(instant);
    }
    public long roundHalfCeiling(long instant) {
        return getWrappedField().roundHalfCeiling(instant);
    }
    public long roundHalfEven(long instant) {
        return getWrappedField().roundHalfEven(instant);
    }
    public long remainder(long instant) {
        return getWrappedField().remainder(instant);
    }

    
Returns the offset added to the field values.

Returns:
the offset
    public int getOffset() {
        return ;
    }
New to GrepCode? Check out our FAQ X