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.goda.time.chrono;
 
A year field suitable for many calendars.

Author(s):
Guy Allard
Stephen Colebourne
Brian S O'Neill
Since:
1.1, refactored from GJYearDateTimeField
 
 class BasicYearDateTimeField extends ImpreciseDateTimeField {

    
Serialization version.
 
     private static final long serialVersionUID = -98628754872287L;

    
The underlying basic chronology.
 
     protected final BasicChronology iChronology;

    
Restricted constructor.

Parameters:
chronology the chronology this field belogs to
 
     BasicYearDateTimeField(BasicChronology chronology) {
         super(DateTimeFieldType.year(), chronology.getAverageMillisPerYear());
          = chronology;
     }
 
     public boolean isLenient() {
         return false;
     }
 
     public int get(long instant) {
         return .getYear(instant);
     }
 
     public long add(long instantint years) {
         if (years == 0) {
             return instant;
         }
         int thisYear = get(instant);
         int newYear = FieldUtils.safeAdd(thisYearyears);
         return set(instantnewYear);
     }
 
     public long add(long instantlong years) {
         return add(instant, FieldUtils.safeToInt(years));
     }
 
     public long addWrapField(long instantint years) {
         if (years == 0) {
             return instant;
         }
         // Return newly calculated millis value
         int thisYear = .getYear(instant);
         int wrappedYear = FieldUtils.getWrappedValue
             (thisYearyears.getMinYear(), .getMaxYear());
         return set(instantwrappedYear);
     }
 
     public long set(long instantint year) {
         FieldUtils.verifyValueBounds
             (thisyear.getMinYear(), .getMaxYear());
         return .setYear(instantyear);
     }
 
     public long getDifferenceAsLong(long minuendInstantlong subtrahendInstant) {
         if (minuendInstant < subtrahendInstant) {
             return -.getYearDifference(subtrahendInstantminuendInstant);
         }
         return .getYearDifference(minuendInstantsubtrahendInstant);
     }
 
     public DurationField getRangeDurationField() {
         return null;
     }
 
     public boolean isLeap(long instant) {
         return .isLeapYear(get(instant));
    }
    public int getLeapAmount(long instant) {
        if (.isLeapYear(get(instant))) {
            return 1;
        } else {
            return 0;
        }
    }
        return .days();
    }
    public int getMinimumValue() {
        return .getMinYear();
    }
    public int getMaximumValue() {
        return .getMaxYear();
    }
    public long roundFloor(long instant) {
        return .getYearMillis(get(instant));
    }
    public long roundCeiling(long instant) {
        int year = get(instant);
        long yearStartMillis = .getYearMillis(year);
        if (instant != yearStartMillis) {
            // Bump up to start of next year.
            instant = .getYearMillis(year + 1);
        }
        return instant;
    }
    public long remainder(long instant) {
        return instant - roundFloor(instant);
    }

    
Serialization singleton
    private Object readResolve() {
        return .year();
    }
New to GrepCode? Check out our FAQ X