1 /*
2 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
131 if (!isValidDayOfWeek(dayOfWeek) && cal.isLenient()) {
132 if (dayOfWeek >= 8) {
133 dayOfWeek--;
134 weekOfYear += dayOfWeek / 7;
135 dayOfWeek = (dayOfWeek % 7) + 1;
136 } else {
137 while (dayOfWeek <= 0) {
138 dayOfWeek += 7;
139 weekOfYear--;
140 }
141 }
142 dayOfWeek = toCalendarDayOfWeek(dayOfWeek);
143 }
144 cal.setWeekDate(field[MAX_FIELD + WEEK_YEAR], weekOfYear, dayOfWeek);
145 }
146 return cal;
147 }
148
149 public String toString() {
150 StringJoiner sj = new StringJoiner(",", "CalendarBuilder:[", "]");
151 for (int i = 0; i < field.length; i++) {
152 if (isSet(i)) {
153 sj.add(i + "=" + field[MAX_FIELD + i]);
154 }
155 }
156 return sj.toString();
157 }
158
159 static int toISODayOfWeek(int calendarDayOfWeek) {
160 return calendarDayOfWeek == SUNDAY ? 7 : calendarDayOfWeek - 1;
161 }
162
163 static int toCalendarDayOfWeek(int isoDayOfWeek) {
164 if (!isValidDayOfWeek(isoDayOfWeek)) {
165 // adjust later for lenient mode
166 return isoDayOfWeek;
167 }
168 return isoDayOfWeek == 7 ? SUNDAY : isoDayOfWeek + 1;
169 }
170
171 static boolean isValidDayOfWeek(int dayOfWeek) {
172 return dayOfWeek > 0 && dayOfWeek <= 7;
173 }
|
1 /*
2 * Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
131 if (!isValidDayOfWeek(dayOfWeek) && cal.isLenient()) {
132 if (dayOfWeek >= 8) {
133 dayOfWeek--;
134 weekOfYear += dayOfWeek / 7;
135 dayOfWeek = (dayOfWeek % 7) + 1;
136 } else {
137 while (dayOfWeek <= 0) {
138 dayOfWeek += 7;
139 weekOfYear--;
140 }
141 }
142 dayOfWeek = toCalendarDayOfWeek(dayOfWeek);
143 }
144 cal.setWeekDate(field[MAX_FIELD + WEEK_YEAR], weekOfYear, dayOfWeek);
145 }
146 return cal;
147 }
148
149 public String toString() {
150 StringJoiner sj = new StringJoiner(",", "CalendarBuilder:[", "]");
151 for (int i = 0; i < MAX_FIELD; i++) {
152 if (isSet(i)) {
153 sj.add(i + "=" + field[i] + ":" + field[MAX_FIELD + i]);
154 }
155 }
156 return sj.toString();
157 }
158
159 static int toISODayOfWeek(int calendarDayOfWeek) {
160 return calendarDayOfWeek == SUNDAY ? 7 : calendarDayOfWeek - 1;
161 }
162
163 static int toCalendarDayOfWeek(int isoDayOfWeek) {
164 if (!isValidDayOfWeek(isoDayOfWeek)) {
165 // adjust later for lenient mode
166 return isoDayOfWeek;
167 }
168 return isoDayOfWeek == 7 ? SUNDAY : isoDayOfWeek + 1;
169 }
170
171 static boolean isValidDayOfWeek(int dayOfWeek) {
172 return dayOfWeek > 0 && dayOfWeek <= 7;
173 }
|