01: /*
02: * Copyright 2001-2005 Stephen Colebourne
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.joda.time.chrono.gj;
17:
18: /**
19: *
20: * @author Brian S O'Neill
21: */
22: class TestJulianMonthOfYearField extends TestGJMonthOfYearField {
23: public TestJulianMonthOfYearField(TestJulianChronology chrono) {
24: super (chrono);
25: }
26:
27: public int get(long millis) {
28: return iChronology.gjFromMillis(millis)[1];
29: }
30:
31: public long add(long millis, long value) {
32: int year = iChronology.year().get(millis);
33: int newYear = year + (int) TestGJChronology.div(value, 12);
34: if (year < 0) {
35: if (newYear >= 0) {
36: newYear++;
37: }
38: } else {
39: if (newYear <= 0) {
40: newYear--;
41: }
42: }
43: int newMonth = get(millis)
44: + (int) TestGJChronology.mod(value, 12);
45: if (newMonth > 12) {
46: if (newYear == -1) {
47: newYear = 1;
48: } else {
49: newYear++;
50: }
51: newMonth -= 12;
52: }
53: int newDay = iChronology.dayOfMonth().get(millis);
54: millis = iChronology.getTimeOnlyMillis(millis)
55: + iChronology.millisFromGJ(newYear, newMonth, newDay);
56: while (get(millis) != newMonth) {
57: millis = iChronology.dayOfYear().add(millis, -1);
58: }
59: return millis;
60: }
61: }
|