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 TestGJMonthOfYearField extends TestGJDateTimeField { 26 public TestGJMonthOfYearField(TestGJChronology chrono) { 27 super(DateTimeFieldType.monthOfYear(), chrono.millisPerMonth(), chrono); 28 } 29 30 public int get(long millis) { 31 return iChronology.gjFromMillis(millis)[1]; 32 } 33 34 public long set(long millis, int value) { 35 long timeOnlyMillis = iChronology.getTimeOnlyMillis(millis); 36 int[] ymd = iChronology.gjFromMillis(millis); 37 millis = iChronology.millisFromGJ(ymd[0], value, 1); 39 int maxDay = iChronology.dayOfMonth().getMaximumValue(millis); 41 if (ymd[2] > maxDay) { 42 ymd[2] = maxDay; 43 } 44 return timeOnlyMillis + iChronology.millisFromGJ(ymd[0], value, ymd[2]); 45 } 46 47 public long add(long millis, long value) { 48 int newYear = iChronology.year().get(millis) 49 + (int)TestGJChronology.div(value, 12); 50 int newMonth = get(millis) + (int)TestGJChronology.mod(value, 12); 51 if (newMonth > 12) { 52 newYear++; 53 newMonth -= 12; 54 } 55 int newDay = iChronology.dayOfMonth().get(millis); 56 millis = iChronology.getTimeOnlyMillis(millis) 57 + iChronology.millisFromGJ(newYear, newMonth, newDay); 58 while (get(millis) != newMonth) { 59 millis = iChronology.dayOfYear().add(millis, -1); 60 } 61 return millis; 62 } 63 64 public boolean isLeap(long millis) { 65 int[] ymd = iChronology.gjFromMillis(millis); 66 return ymd[1] == 2 && iChronology.isLeapYear(ymd[0]); 67 } 68 69 public int getLeapAmount(long millis) { 70 return isLeap(millis) ? 1 : 0; 71 } 72 73 public DurationField getLeapDurationField() { 74 return iChronology.days(); 75 } 76 77 public DurationField getRangeDurationField() { 78 return iChronology.years(); 79 } 80 81 public int getMinimumValue() { 82 return 1; 83 } 84 85 public int getMaximumValue() { 86 return 12; 87 } 88 89 public long roundFloor(long millis) { 90 int[] ymd = iChronology.gjFromMillis(millis); 91 return iChronology.millisFromGJ(ymd[0], ymd[1], 1); 92 } 93 } 94 | Popular Tags |