~ubuntu-branches/ubuntu/precise/libjoda-time-java/precise

« back to all changes in this revision

Viewing changes to src/test/java/org/joda/time/chrono/gj/TestJulianMonthOfYearField.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2011-02-09 23:05:14 UTC
  • mfrom: (5.2.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110209230514-22otglg8nm2y2y2n
Tags: 1.6.2-2
* Upload to unstable.
* Add (temporary) Build-Depends: ant.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/**
 
19
 * 
 
20
 * @author Brian S O'Neill
 
21
 */
 
22
class TestJulianMonthOfYearField extends TestGJMonthOfYearField {
 
23
    public TestJulianMonthOfYearField(TestJulianChronology chrono) {
 
24
        super(chrono);
 
25
    }
 
26
 
 
27
    public int get(long millis) {
 
28
        return iChronology.gjFromMillis(millis)[1];
 
29
    }
 
30
 
 
31
    public long add(long millis, long value) {
 
32
        int year = iChronology.year().get(millis);
 
33
        int newYear = year + (int)TestGJChronology.div(value, 12);
 
34
        if (year < 0) {
 
35
            if (newYear >= 0) {
 
36
                newYear++;
 
37
            }
 
38
        } else {
 
39
            if (newYear <= 0) {
 
40
                newYear--;
 
41
            }
 
42
        }
 
43
        int newMonth = get(millis) + (int)TestGJChronology.mod(value, 12);
 
44
        if (newMonth > 12) {
 
45
            if (newYear == -1) {
 
46
                newYear = 1;
 
47
            } else {
 
48
                newYear++;
 
49
            }
 
50
            newMonth -= 12;
 
51
        }
 
52
        int newDay = iChronology.dayOfMonth().get(millis);
 
53
        millis = iChronology.getTimeOnlyMillis(millis) 
 
54
            + iChronology.millisFromGJ(newYear, newMonth, newDay);
 
55
        while (get(millis) != newMonth) {
 
56
            millis = iChronology.dayOfYear().add(millis, -1);
 
57
        }
 
58
        return millis;
 
59
    }
 
60
}