KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > chrono > gj > TestGJWeekyearField


1 /*
2  * Copyright 2001-2005 Stephen Colebourne
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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(), chrono);
28     }
29
30     public int get(long millis) {
31         return iChronology.isoFromMillis(millis)[0];
32     }
33
34     public long set(long millis, int value) {
35         int[] wwd = iChronology.isoFromMillis(millis);
36         millis = iChronology.getTimeOnlyMillis(millis)
37             + iChronology.millisFromISO(value, wwd[1], wwd[2]);
38         if (wwd[1] == 53) {
39             int[] wwd2 = iChronology.isoFromMillis(millis);
40             if (wwd2[0] != value) {
41                 // Set year doesn't have 53 weeks, so back off a week.
42
millis = iChronology.dayOfYear().add(millis, -7);
43             }
44         }
45         return millis;
46     }
47
48     public long add(long millis, long value) {
49         return set(millis, (int)(get(millis) + value));
50     }
51
52     public boolean isLeap(long millis) {
53         return iChronology.weekOfWeekyear().getMaximumValue(millis) > 52;
54     }
55
56     public int getLeapAmount(long millis) {
57         return iChronology.weekOfWeekyear().getMaximumValue(millis) - 52;
58     }
59
60     public DurationField getLeapDurationField() {
61         return iChronology.weeks();
62     }
63
64     public DurationField getRangeDurationField() {
65         return null;
66     }
67
68     public int getMinimumValue() {
69         return -100000000;
70     }
71
72     public int getMaximumValue() {
73         return 100000000;
74     }
75
76     public long roundFloor(long millis) {
77         return iChronology.millisFromISO(get(millis), 1, 1);
78     }
79 }
80
Popular Tags