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 TestGJDayOfMonthField extends TestGJDateTimeField {
26: public TestGJDayOfMonthField(TestGJChronology chrono) {
27: super (DateTimeFieldType.dayOfMonth(),
28: TestGJChronology.MILLIS_PER_DAY, chrono);
29: }
30:
31: public int get(long millis) {
32: return iChronology.gjFromMillis(millis)[2];
33: }
34:
35: public long set(long millis, int value) {
36: int[] ymd = iChronology.gjFromMillis(millis);
37: return iChronology.getTimeOnlyMillis(millis)
38: + iChronology.millisFromGJ(ymd[0], ymd[1], value);
39: }
40:
41: public long add(long millis, long value) {
42: return millis + value * TestGJChronology.MILLIS_PER_DAY;
43: }
44:
45: public DurationField getRangeDurationField() {
46: return iChronology.months();
47: }
48:
49: public int getMinimumValue() {
50: return 1;
51: }
52:
53: public int getMaximumValue() {
54: return 31;
55: }
56:
57: public int getMaximumValue(long millis) {
58: int[] lengths = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
59: 30, 31 };
60: if (iChronology.year().isLeap(millis)) {
61: lengths[2] = 29;
62: }
63: return lengths[iChronology.monthOfYear().get(millis)];
64: }
65:
66: public long roundFloor(long millis) {
67: return iChronology.getDateOnlyMillis(millis);
68: }
69: }
|