1 16 package org.joda.time.chrono; 17 18 import org.joda.time.DateTimeFieldType; 19 import org.joda.time.DurationField; 20 import org.joda.time.ReadablePartial; 21 import org.joda.time.field.PreciseDurationDateTimeField; 22 23 31 final class BasicDayOfYearDateTimeField extends PreciseDurationDateTimeField { 32 33 private static final long serialVersionUID = -6821236822336841037L; 34 35 private final BasicChronology iChronology; 36 37 40 BasicDayOfYearDateTimeField(BasicChronology chronology, DurationField days) { 41 super(DateTimeFieldType.dayOfYear(), days); 42 iChronology = chronology; 43 } 44 45 51 public int get(long instant) { 52 return iChronology.getDayOfYear(instant); 53 } 54 55 public DurationField getRangeDurationField() { 56 return iChronology.years(); 57 } 58 59 public int getMinimumValue() { 60 return 1; 61 } 62 63 public int getMaximumValue() { 64 return iChronology.getDaysInYearMax(); 65 } 66 67 public int getMaximumValue(long instant) { 68 int year = iChronology.getYear(instant); 69 return iChronology.getDaysInYear(year); 70 } 71 72 public int getMaximumValue(ReadablePartial partial) { 73 if (partial.isSupported(DateTimeFieldType.year())) { 74 int year = partial.get(DateTimeFieldType.year()); 75 return iChronology.getDaysInYear(year); 76 } 77 return iChronology.getDaysInYearMax(); 78 } 79 80 public int getMaximumValue(ReadablePartial partial, int[] values) { 81 int size = partial.size(); 82 for (int i = 0; i < size; i++) { 83 if (partial.getFieldType(i) == DateTimeFieldType.year()) { 84 int year = values[i]; 85 return iChronology.getDaysInYear(year); 86 } 87 } 88 return iChronology.getDaysInYearMax(); 89 } 90 91 protected int getMaximumValueForSet(long instant, int value) { 92 int maxLessOne = iChronology.getDaysInYearMax() - 1; 93 return (value > maxLessOne || value < 1) ? getMaximumValue(instant) : maxLessOne; 94 } 95 96 99 private Object readResolve() { 100 return iChronology.dayOfYear(); 101 } 102 } 103 | Popular Tags |