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 TestGJWeekyearField extends TestGJDateTimeField {
26: public TestGJWeekyearField(TestGJChronology chrono) {
27: super (DateTimeFieldType.weekyear(), chrono.millisPerYear(),
28: chrono);
29: }
30:
31: public int get(long millis) {
32: return iChronology.isoFromMillis(millis)[0];
33: }
34:
35: public long set(long millis, int value) {
36: int[] wwd = iChronology.isoFromMillis(millis);
37: millis = iChronology.getTimeOnlyMillis(millis)
38: + iChronology.millisFromISO(value, wwd[1], wwd[2]);
39: if (wwd[1] == 53) {
40: int[] wwd2 = iChronology.isoFromMillis(millis);
41: if (wwd2[0] != value) {
42: // Set year doesn't have 53 weeks, so back off a week.
43: millis = iChronology.dayOfYear().add(millis, -7);
44: }
45: }
46: return millis;
47: }
48:
49: public long add(long millis, long value) {
50: return set(millis, (int) (get(millis) + value));
51: }
52:
53: public boolean isLeap(long millis) {
54: return iChronology.weekOfWeekyear().getMaximumValue(millis) > 52;
55: }
56:
57: public int getLeapAmount(long millis) {
58: return iChronology.weekOfWeekyear().getMaximumValue(millis) - 52;
59: }
60:
61: public DurationField getLeapDurationField() {
62: return iChronology.weeks();
63: }
64:
65: public DurationField getRangeDurationField() {
66: return null;
67: }
68:
69: public int getMinimumValue() {
70: return -100000000;
71: }
72:
73: public int getMaximumValue() {
74: return 100000000;
75: }
76:
77: public long roundFloor(long millis) {
78: return iChronology.millisFromISO(get(millis), 1, 1);
79: }
80: }
|