View Javadoc

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 TestJulianWeekyearField extends TestGJWeekyearField {
25      public TestJulianWeekyearField(TestJulianChronology chrono) {
26          super(chrono);
27      }
28  
29      public long addWrapField(long millis, int value) {
30          int weekyear = get(millis);
31          int wrapped = FieldUtils.getWrappedValue
32              (weekyear, value, getMinimumValue(), getMaximumValue());
33          return add(millis, (long) wrapped - weekyear);
34      }
35  
36      public long add(long millis, long value) {
37          int weekyear = get(millis);
38          int newWeekyear = weekyear + FieldUtils.safeToInt(value);
39          if (weekyear < 0) {
40              if (newWeekyear >= 0) {
41                  newWeekyear++;
42              }
43          } else {
44              if (newWeekyear <= 0) {
45                  newWeekyear--;
46              }
47          }
48          return set(millis, newWeekyear);
49      }
50  
51      public int getMinimumValue() {
52          return -100000000;
53      }
54  
55      public int getMaximumValue() {
56          return 100000000;
57      }
58  }