1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.joda.time.chrono;
17
18 import org.joda.time.DateTimeConstants;
19 import org.joda.time.DateTimeFieldType;
20 import org.joda.time.DurationField;
21 import org.joda.time.ReadablePartial;
22 import org.joda.time.field.PreciseDurationDateTimeField;
23
24
25
26
27
28
29
30
31
32 final class BasicWeekOfWeekyearDateTimeField extends PreciseDurationDateTimeField {
33
34 private static final long serialVersionUID = -1587436826395135328L;
35
36 private final BasicChronology iChronology;
37
38
39
40
41 BasicWeekOfWeekyearDateTimeField(BasicChronology chronology, DurationField weeks) {
42 super(DateTimeFieldType.weekOfWeekyear(), weeks);
43 iChronology = chronology;
44 }
45
46
47
48
49
50
51
52
53 public int get(long instant) {
54 return iChronology.getWeekOfWeekyear(instant);
55 }
56
57 public DurationField getRangeDurationField() {
58 return iChronology.weekyears();
59 }
60
61
62
63
64 public long roundFloor(long instant) {
65 return super.roundFloor(instant + 3 * DateTimeConstants.MILLIS_PER_DAY)
66 - 3 * DateTimeConstants.MILLIS_PER_DAY;
67 }
68
69 public long roundCeiling(long instant) {
70 return super.roundCeiling(instant + 3 * DateTimeConstants.MILLIS_PER_DAY)
71 - 3 * DateTimeConstants.MILLIS_PER_DAY;
72 }
73
74 public long remainder(long instant) {
75 return super.remainder(instant + 3 * DateTimeConstants.MILLIS_PER_DAY);
76 }
77
78 public int getMinimumValue() {
79 return 1;
80 }
81
82 public int getMaximumValue() {
83 return 53;
84 }
85
86 public int getMaximumValue(long instant) {
87 int weekyear = iChronology.getWeekyear(instant);
88 return iChronology.getWeeksInYear(weekyear);
89 }
90
91 public int getMaximumValue(ReadablePartial partial) {
92 if (partial.isSupported(DateTimeFieldType.weekyear())) {
93 int weekyear = partial.get(DateTimeFieldType.weekyear());
94 return iChronology.getWeeksInYear(weekyear);
95 }
96 return 53;
97 }
98
99 public int getMaximumValue(ReadablePartial partial, int[] values) {
100 int size = partial.size();
101 for (int i = 0; i < size; i++) {
102 if (partial.getFieldType(i) == DateTimeFieldType.weekyear()) {
103 int weekyear = values[i];
104 return iChronology.getWeeksInYear(weekyear);
105 }
106 }
107 return 53;
108 }
109
110 protected int getMaximumValueForSet(long instant, int value) {
111 return value > 52 ? getMaximumValue(instant) : 52;
112 }
113
114
115
116
117 private Object readResolve() {
118 return iChronology.weekOfWeekyear();
119 }
120 }