KickJava   Java API By Example, From Geeks To Geeks.

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


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.field.FieldUtils;
19
20 /**
21  *
22  * @author Brian S O'Neill
23  */

24 class TestJulianYearField extends TestGJYearField {
25     public TestJulianYearField(TestJulianChronology chrono) {
26         super(chrono);
27     }
28
29     public long addWrapField(long millis, int value) {
30         int year = get(millis);
31         int wrapped = FieldUtils.getWrappedValue
32             (year, value, getMinimumValue(), getMaximumValue());
33         return add(millis, (long) wrapped - year);
34     }
35
36     public long add(long millis, long value) {
37         int year = get(millis);
38         int newYear = year + FieldUtils.safeToInt(value);
39         if (year < 0) {
40             if (newYear >= 0) {
41                 newYear++;
42             }
43         } else {
44             if (newYear <= 0) {
45                 newYear--;
46             }
47         }
48         return set(millis, newYear);
49     }
50
51     public int getMinimumValue() {
52         return -100000000;
53     }
54
55     public int getMaximumValue() {
56         return 100000000;
57     }
58 }
59
Popular Tags