1 16 package org.joda.time.chrono.gj; 17 18 import org.joda.time.DateTimeFieldType; 19 import org.joda.time.DurationField; 20 21 25 class TestGJYearField extends TestGJDateTimeField { 26 public TestGJYearField(TestGJChronology chrono) { 27 super(DateTimeFieldType.year(), chrono.millisPerYear(), chrono); 28 } 29 30 public int get(long millis) { 31 return iChronology.gjYearFromMillis(millis); 32 } 33 34 public long set(long millis, int value) { 35 int[] ymd = iChronology.gjFromMillis(millis); 36 millis = iChronology.getTimeOnlyMillis(millis) 37 + iChronology.millisFromGJ(value, ymd[1], ymd[2]); 38 if (ymd[1] == 2 && ymd[2] == 29 && !iChronology.isLeapYear(value)) { 39 millis = iChronology.dayOfYear().add(millis, -1); 40 } 41 return millis; 42 } 43 44 public long add(long millis, long value) { 45 return set(millis, (int)(get(millis) + value)); 46 } 47 48 public boolean isLeap(long millis) { 49 return iChronology.isLeapYear(get(millis)); 50 } 51 52 public int getLeapAmount(long millis) { 53 return isLeap(millis) ? 1 : 0; 54 } 55 56 public DurationField getLeapDurationField() { 57 return iChronology.days(); 58 } 59 60 public DurationField getRangeDurationField() { 61 return null; 62 } 63 64 public int getMinimumValue() { 65 return -100000000; 66 } 67 68 public int getMaximumValue() { 69 return 100000000; 70 } 71 72 public long roundFloor(long millis) { 73 return iChronology.millisFromGJ(get(millis), 1, 1); 74 } 75 } 76 | Popular Tags |