1 16 package org.joda.time.chrono; 17 18 import org.joda.time.DateTimeField; 19 import org.joda.time.DateTimeFieldType; 20 import org.joda.time.ReadablePartial; 21 import org.joda.time.field.DecoratedDateTimeField; 22 import org.joda.time.field.FieldUtils; 23 24 33 class ISOYearOfEraDateTimeField extends DecoratedDateTimeField { 34 35 private static final long serialVersionUID = 7037524068969447317L; 36 37 40 static final DateTimeField INSTANCE = new ISOYearOfEraDateTimeField(); 41 42 45 private ISOYearOfEraDateTimeField() { 46 super(GregorianChronology.getInstanceUTC().year(), DateTimeFieldType.yearOfEra()); 47 } 48 49 public int get(long instant) { 50 int year = getWrappedField().get(instant); 51 return year < 0 ? -year : year; 52 } 53 54 public long add(long instant, int years) { 55 return getWrappedField().add(instant, years); 56 } 57 58 public long add(long instant, long years) { 59 return getWrappedField().add(instant, years); 60 } 61 62 public long addWrapField(long instant, int years) { 63 return getWrappedField().addWrapField(instant, years); 64 } 65 66 public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int years) { 67 return getWrappedField().addWrapField(instant, fieldIndex, values, years); 68 } 69 70 public int getDifference(long minuendInstant, long subtrahendInstant) { 71 return getWrappedField().getDifference(minuendInstant, subtrahendInstant); 72 } 73 74 public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) { 75 return getWrappedField().getDifferenceAsLong(minuendInstant, subtrahendInstant); 76 } 77 78 public long set(long instant, int year) { 79 FieldUtils.verifyValueBounds(this, year, 0, getMaximumValue()); 80 if (getWrappedField().get(instant) < 0) { 81 year = -year; 82 } 83 return super.set(instant, year); 84 } 85 86 public int getMinimumValue() { 87 return 0; 88 } 89 90 public int getMaximumValue() { 91 return getWrappedField().getMaximumValue(); 92 } 93 94 public long roundFloor(long instant) { 95 return getWrappedField().roundFloor(instant); 96 } 97 98 public long roundCeiling(long instant) { 99 return getWrappedField().roundCeiling(instant); 100 } 101 102 public long remainder(long instant) { 103 return getWrappedField().remainder(instant); 104 } 105 106 109 private Object readResolve() { 110 return INSTANCE; 111 } 112 } 113 | Popular Tags |