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: import org.joda.time.DateTimeFieldType;
19: import org.joda.time.DurationField;
20:
21: /**
22: *
23: * @author Brian S O'Neill
24: */
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
39: && !iChronology.isLeapYear(value)) {
40: millis = iChronology.dayOfYear().add(millis, -1);
41: }
42: return millis;
43: }
44:
45: public long add(long millis, long value) {
46: return set(millis, (int) (get(millis) + value));
47: }
48:
49: public boolean isLeap(long millis) {
50: return iChronology.isLeapYear(get(millis));
51: }
52:
53: public int getLeapAmount(long millis) {
54: return isLeap(millis) ? 1 : 0;
55: }
56:
57: public DurationField getLeapDurationField() {
58: return iChronology.days();
59: }
60:
61: public DurationField getRangeDurationField() {
62: return null;
63: }
64:
65: public int getMinimumValue() {
66: return -100000000;
67: }
68:
69: public int getMaximumValue() {
70: return 100000000;
71: }
72:
73: public long roundFloor(long millis) {
74: return iChronology.millisFromGJ(get(millis), 1, 1);
75: }
76: }
|