15289
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, 2013, 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
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
/*
|
|
27 |
* This file is available under and governed by the GNU General Public
|
|
28 |
* License version 2 only, as published by the Free Software Foundation.
|
|
29 |
* However, the following notice accompanied the original version of this
|
|
30 |
* file:
|
|
31 |
*
|
|
32 |
* Copyright (c) 2007-2012, Stephen Colebourne & Michael Nascimento Santos
|
|
33 |
*
|
|
34 |
* All rights reserved.
|
|
35 |
*
|
|
36 |
* Redistribution and use in source and binary forms, with or without
|
|
37 |
* modification, are permitted provided that the following conditions are met:
|
|
38 |
*
|
|
39 |
* * Redistributions of source code must retain the above copyright notice,
|
|
40 |
* this list of conditions and the following disclaimer.
|
|
41 |
*
|
|
42 |
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
43 |
* this list of conditions and the following disclaimer in the documentation
|
|
44 |
* and/or other materials provided with the distribution.
|
|
45 |
*
|
|
46 |
* * Neither the name of JSR-310 nor the names of its contributors
|
|
47 |
* may be used to endorse or promote products derived from this software
|
|
48 |
* without specific prior written permission.
|
|
49 |
*
|
|
50 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
51 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
52 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
53 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
54 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
55 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
56 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
57 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
58 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
59 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
60 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
61 |
*/
|
|
62 |
package java.time;
|
|
63 |
|
|
64 |
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
|
|
65 |
import static java.time.temporal.ChronoUnit.DAYS;
|
|
66 |
|
|
67 |
import java.time.format.DateTimeFormatterBuilder;
|
|
68 |
import java.time.format.TextStyle;
|
|
69 |
import java.time.temporal.ChronoField;
|
|
70 |
import java.time.temporal.Temporal;
|
|
71 |
import java.time.temporal.TemporalAccessor;
|
|
72 |
import java.time.temporal.TemporalAdjuster;
|
|
73 |
import java.time.temporal.TemporalField;
|
|
74 |
import java.time.temporal.TemporalQuery;
|
19030
|
75 |
import java.time.temporal.UnsupportedTemporalTypeException;
|
15289
|
76 |
import java.time.temporal.ValueRange;
|
|
77 |
import java.time.temporal.WeekFields;
|
|
78 |
import java.util.Locale;
|
|
79 |
|
|
80 |
/**
|
|
81 |
* A day-of-week, such as 'Tuesday'.
|
|
82 |
* <p>
|
|
83 |
* {@code DayOfWeek} is an enum representing the 7 days of the week -
|
|
84 |
* Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.
|
|
85 |
* <p>
|
|
86 |
* In addition to the textual enum name, each day-of-week has an {@code int} value.
|
|
87 |
* The {@code int} value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
|
|
88 |
* It is recommended that applications use the enum rather than the {@code int} value
|
|
89 |
* to ensure code clarity.
|
|
90 |
* <p>
|
|
91 |
* This enum provides access to the localized textual form of the day-of-week.
|
|
92 |
* Some locales also assign different numeric values to the days, declaring
|
|
93 |
* Sunday to have the value 1, however this class provides no support for this.
|
|
94 |
* See {@link WeekFields} for localized week-numbering.
|
|
95 |
* <p>
|
|
96 |
* <b>Do not use {@code ordinal()} to obtain the numeric representation of {@code DayOfWeek}.
|
|
97 |
* Use {@code getValue()} instead.</b>
|
|
98 |
* <p>
|
|
99 |
* This enum represents a common concept that is found in many calendar systems.
|
|
100 |
* As such, this enum may be used by any calendar system that has the day-of-week
|
|
101 |
* concept defined exactly equivalent to the ISO calendar system.
|
|
102 |
*
|
17474
|
103 |
* @implSpec
|
15289
|
104 |
* This is an immutable and thread-safe enum.
|
|
105 |
*
|
|
106 |
* @since 1.8
|
|
107 |
*/
|
|
108 |
public enum DayOfWeek implements TemporalAccessor, TemporalAdjuster {
|
|
109 |
|
|
110 |
/**
|
|
111 |
* The singleton instance for the day-of-week of Monday.
|
|
112 |
* This has the numeric value of {@code 1}.
|
|
113 |
*/
|
|
114 |
MONDAY,
|
|
115 |
/**
|
|
116 |
* The singleton instance for the day-of-week of Tuesday.
|
|
117 |
* This has the numeric value of {@code 2}.
|
|
118 |
*/
|
|
119 |
TUESDAY,
|
|
120 |
/**
|
|
121 |
* The singleton instance for the day-of-week of Wednesday.
|
|
122 |
* This has the numeric value of {@code 3}.
|
|
123 |
*/
|
|
124 |
WEDNESDAY,
|
|
125 |
/**
|
|
126 |
* The singleton instance for the day-of-week of Thursday.
|
|
127 |
* This has the numeric value of {@code 4}.
|
|
128 |
*/
|
|
129 |
THURSDAY,
|
|
130 |
/**
|
|
131 |
* The singleton instance for the day-of-week of Friday.
|
|
132 |
* This has the numeric value of {@code 5}.
|
|
133 |
*/
|
|
134 |
FRIDAY,
|
|
135 |
/**
|
|
136 |
* The singleton instance for the day-of-week of Saturday.
|
|
137 |
* This has the numeric value of {@code 6}.
|
|
138 |
*/
|
|
139 |
SATURDAY,
|
|
140 |
/**
|
|
141 |
* The singleton instance for the day-of-week of Sunday.
|
|
142 |
* This has the numeric value of {@code 7}.
|
|
143 |
*/
|
|
144 |
SUNDAY;
|
|
145 |
/**
|
|
146 |
* Private cache of all the constants.
|
|
147 |
*/
|
|
148 |
private static final DayOfWeek[] ENUMS = DayOfWeek.values();
|
|
149 |
|
|
150 |
//-----------------------------------------------------------------------
|
|
151 |
/**
|
|
152 |
* Obtains an instance of {@code DayOfWeek} from an {@code int} value.
|
|
153 |
* <p>
|
|
154 |
* {@code DayOfWeek} is an enum representing the 7 days of the week.
|
|
155 |
* This factory allows the enum to be obtained from the {@code int} value.
|
|
156 |
* The {@code int} value follows the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
|
|
157 |
*
|
|
158 |
* @param dayOfWeek the day-of-week to represent, from 1 (Monday) to 7 (Sunday)
|
|
159 |
* @return the day-of-week singleton, not null
|
|
160 |
* @throws DateTimeException if the day-of-week is invalid
|
|
161 |
*/
|
|
162 |
public static DayOfWeek of(int dayOfWeek) {
|
|
163 |
if (dayOfWeek < 1 || dayOfWeek > 7) {
|
|
164 |
throw new DateTimeException("Invalid value for DayOfWeek: " + dayOfWeek);
|
|
165 |
}
|
|
166 |
return ENUMS[dayOfWeek - 1];
|
|
167 |
}
|
|
168 |
|
|
169 |
//-----------------------------------------------------------------------
|
|
170 |
/**
|
|
171 |
* Obtains an instance of {@code DayOfWeek} from a temporal object.
|
|
172 |
* <p>
|
15658
|
173 |
* This obtains a day-of-week based on the specified temporal.
|
|
174 |
* A {@code TemporalAccessor} represents an arbitrary set of date and time information,
|
|
175 |
* which this factory converts to an instance of {@code DayOfWeek}.
|
15289
|
176 |
* <p>
|
|
177 |
* The conversion extracts the {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} field.
|
|
178 |
* <p>
|
|
179 |
* This method matches the signature of the functional interface {@link TemporalQuery}
|
|
180 |
* allowing it to be used as a query via method reference, {@code DayOfWeek::from}.
|
|
181 |
*
|
|
182 |
* @param temporal the temporal object to convert, not null
|
|
183 |
* @return the day-of-week, not null
|
|
184 |
* @throws DateTimeException if unable to convert to a {@code DayOfWeek}
|
|
185 |
*/
|
|
186 |
public static DayOfWeek from(TemporalAccessor temporal) {
|
|
187 |
if (temporal instanceof DayOfWeek) {
|
|
188 |
return (DayOfWeek) temporal;
|
|
189 |
}
|
|
190 |
return of(temporal.get(DAY_OF_WEEK));
|
|
191 |
}
|
|
192 |
|
|
193 |
//-----------------------------------------------------------------------
|
|
194 |
/**
|
|
195 |
* Gets the day-of-week {@code int} value.
|
|
196 |
* <p>
|
|
197 |
* The values are numbered following the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
|
|
198 |
* See {@link WeekFields#dayOfWeek} for localized week-numbering.
|
|
199 |
*
|
|
200 |
* @return the day-of-week, from 1 (Monday) to 7 (Sunday)
|
|
201 |
*/
|
|
202 |
public int getValue() {
|
|
203 |
return ordinal() + 1;
|
|
204 |
}
|
|
205 |
|
|
206 |
//-----------------------------------------------------------------------
|
|
207 |
/**
|
|
208 |
* Gets the textual representation, such as 'Mon' or 'Friday'.
|
|
209 |
* <p>
|
15658
|
210 |
* This returns the textual name used to identify the day-of-week,
|
|
211 |
* suitable for presentation to the user.
|
|
212 |
* The parameters control the style of the returned text and the locale.
|
15289
|
213 |
* <p>
|
|
214 |
* If no textual mapping is found then the {@link #getValue() numeric value} is returned.
|
|
215 |
*
|
|
216 |
* @param style the length of the text required, not null
|
|
217 |
* @param locale the locale to use, not null
|
|
218 |
* @return the text value of the day-of-week, not null
|
|
219 |
*/
|
15658
|
220 |
public String getDisplayName(TextStyle style, Locale locale) {
|
|
221 |
return new DateTimeFormatterBuilder().appendText(DAY_OF_WEEK, style).toFormatter(locale).format(this);
|
15289
|
222 |
}
|
|
223 |
|
|
224 |
//-----------------------------------------------------------------------
|
|
225 |
/**
|
|
226 |
* Checks if the specified field is supported.
|
|
227 |
* <p>
|
|
228 |
* This checks if this day-of-week can be queried for the specified field.
|
|
229 |
* If false, then calling the {@link #range(TemporalField) range} and
|
|
230 |
* {@link #get(TemporalField) get} methods will throw an exception.
|
|
231 |
* <p>
|
|
232 |
* If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then
|
|
233 |
* this method returns true.
|
|
234 |
* All other {@code ChronoField} instances will return false.
|
|
235 |
* <p>
|
|
236 |
* If the field is not a {@code ChronoField}, then the result of this method
|
15658
|
237 |
* is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
|
15289
|
238 |
* passing {@code this} as the argument.
|
|
239 |
* Whether the field is supported is determined by the field.
|
|
240 |
*
|
|
241 |
* @param field the field to check, null returns false
|
|
242 |
* @return true if the field is supported on this day-of-week, false if not
|
|
243 |
*/
|
|
244 |
@Override
|
|
245 |
public boolean isSupported(TemporalField field) {
|
|
246 |
if (field instanceof ChronoField) {
|
|
247 |
return field == DAY_OF_WEEK;
|
|
248 |
}
|
15658
|
249 |
return field != null && field.isSupportedBy(this);
|
15289
|
250 |
}
|
|
251 |
|
|
252 |
/**
|
|
253 |
* Gets the range of valid values for the specified field.
|
|
254 |
* <p>
|
|
255 |
* The range object expresses the minimum and maximum valid values for a field.
|
|
256 |
* This day-of-week is used to enhance the accuracy of the returned range.
|
|
257 |
* If it is not possible to return the range, because the field is not supported
|
|
258 |
* or for some other reason, an exception is thrown.
|
|
259 |
* <p>
|
|
260 |
* If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then the
|
|
261 |
* range of the day-of-week, from 1 to 7, will be returned.
|
16852
|
262 |
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
|
15289
|
263 |
* <p>
|
|
264 |
* If the field is not a {@code ChronoField}, then the result of this method
|
15658
|
265 |
* is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
|
15289
|
266 |
* passing {@code this} as the argument.
|
|
267 |
* Whether the range can be obtained is determined by the field.
|
|
268 |
*
|
|
269 |
* @param field the field to query the range for, not null
|
|
270 |
* @return the range of valid values for the field, not null
|
|
271 |
* @throws DateTimeException if the range for the field cannot be obtained
|
16852
|
272 |
* @throws UnsupportedTemporalTypeException if the field is not supported
|
15289
|
273 |
*/
|
|
274 |
@Override
|
|
275 |
public ValueRange range(TemporalField field) {
|
|
276 |
if (field == DAY_OF_WEEK) {
|
|
277 |
return field.range();
|
|
278 |
}
|
|
279 |
return TemporalAccessor.super.range(field);
|
|
280 |
}
|
|
281 |
|
|
282 |
/**
|
|
283 |
* Gets the value of the specified field from this day-of-week as an {@code int}.
|
|
284 |
* <p>
|
|
285 |
* This queries this day-of-week for the value for the specified field.
|
|
286 |
* The returned value will always be within the valid range of values for the field.
|
|
287 |
* If it is not possible to return the value, because the field is not supported
|
|
288 |
* or for some other reason, an exception is thrown.
|
|
289 |
* <p>
|
|
290 |
* If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then the
|
|
291 |
* value of the day-of-week, from 1 to 7, will be returned.
|
16852
|
292 |
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
|
15289
|
293 |
* <p>
|
|
294 |
* If the field is not a {@code ChronoField}, then the result of this method
|
15658
|
295 |
* is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
|
15289
|
296 |
* passing {@code this} as the argument. Whether the value can be obtained,
|
|
297 |
* and what the value represents, is determined by the field.
|
|
298 |
*
|
|
299 |
* @param field the field to get, not null
|
|
300 |
* @return the value for the field, within the valid range of values
|
16852
|
301 |
* @throws DateTimeException if a value for the field cannot be obtained or
|
|
302 |
* the value is outside the range of valid values for the field
|
|
303 |
* @throws UnsupportedTemporalTypeException if the field is not supported or
|
|
304 |
* the range of values exceeds an {@code int}
|
15289
|
305 |
* @throws ArithmeticException if numeric overflow occurs
|
|
306 |
*/
|
|
307 |
@Override
|
|
308 |
public int get(TemporalField field) {
|
|
309 |
if (field == DAY_OF_WEEK) {
|
|
310 |
return getValue();
|
|
311 |
}
|
|
312 |
return TemporalAccessor.super.get(field);
|
|
313 |
}
|
|
314 |
|
|
315 |
/**
|
|
316 |
* Gets the value of the specified field from this day-of-week as a {@code long}.
|
|
317 |
* <p>
|
|
318 |
* This queries this day-of-week for the value for the specified field.
|
|
319 |
* If it is not possible to return the value, because the field is not supported
|
|
320 |
* or for some other reason, an exception is thrown.
|
|
321 |
* <p>
|
|
322 |
* If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then the
|
|
323 |
* value of the day-of-week, from 1 to 7, will be returned.
|
16852
|
324 |
* All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
|
15289
|
325 |
* <p>
|
|
326 |
* If the field is not a {@code ChronoField}, then the result of this method
|
15658
|
327 |
* is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
|
15289
|
328 |
* passing {@code this} as the argument. Whether the value can be obtained,
|
|
329 |
* and what the value represents, is determined by the field.
|
|
330 |
*
|
|
331 |
* @param field the field to get, not null
|
|
332 |
* @return the value for the field
|
|
333 |
* @throws DateTimeException if a value for the field cannot be obtained
|
16852
|
334 |
* @throws UnsupportedTemporalTypeException if the field is not supported
|
15289
|
335 |
* @throws ArithmeticException if numeric overflow occurs
|
|
336 |
*/
|
|
337 |
@Override
|
|
338 |
public long getLong(TemporalField field) {
|
|
339 |
if (field == DAY_OF_WEEK) {
|
|
340 |
return getValue();
|
|
341 |
} else if (field instanceof ChronoField) {
|
19030
|
342 |
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
|
15289
|
343 |
}
|
15658
|
344 |
return field.getFrom(this);
|
15289
|
345 |
}
|
|
346 |
|
|
347 |
//-----------------------------------------------------------------------
|
|
348 |
/**
|
|
349 |
* Returns the day-of-week that is the specified number of days after this one.
|
|
350 |
* <p>
|
|
351 |
* The calculation rolls around the end of the week from Sunday to Monday.
|
|
352 |
* The specified period may be negative.
|
|
353 |
* <p>
|
|
354 |
* This instance is immutable and unaffected by this method call.
|
|
355 |
*
|
|
356 |
* @param days the days to add, positive or negative
|
|
357 |
* @return the resulting day-of-week, not null
|
|
358 |
*/
|
|
359 |
public DayOfWeek plus(long days) {
|
|
360 |
int amount = (int) (days % 7);
|
|
361 |
return ENUMS[(ordinal() + (amount + 7)) % 7];
|
|
362 |
}
|
|
363 |
|
|
364 |
/**
|
|
365 |
* Returns the day-of-week that is the specified number of days before this one.
|
|
366 |
* <p>
|
|
367 |
* The calculation rolls around the start of the year from Monday to Sunday.
|
|
368 |
* The specified period may be negative.
|
|
369 |
* <p>
|
|
370 |
* This instance is immutable and unaffected by this method call.
|
|
371 |
*
|
|
372 |
* @param days the days to subtract, positive or negative
|
|
373 |
* @return the resulting day-of-week, not null
|
|
374 |
*/
|
|
375 |
public DayOfWeek minus(long days) {
|
|
376 |
return plus(-(days % 7));
|
|
377 |
}
|
|
378 |
|
|
379 |
//-----------------------------------------------------------------------
|
|
380 |
/**
|
|
381 |
* Queries this day-of-week using the specified query.
|
|
382 |
* <p>
|
|
383 |
* This queries this day-of-week using the specified query strategy object.
|
|
384 |
* The {@code TemporalQuery} object defines the logic to be used to
|
|
385 |
* obtain the result. Read the documentation of the query to understand
|
|
386 |
* what the result of this method will be.
|
|
387 |
* <p>
|
|
388 |
* The result of this method is obtained by invoking the
|
|
389 |
* {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
|
|
390 |
* specified query passing {@code this} as the argument.
|
|
391 |
*
|
|
392 |
* @param <R> the type of the result
|
|
393 |
* @param query the query to invoke, not null
|
|
394 |
* @return the query result, null may be returned (defined by the query)
|
|
395 |
* @throws DateTimeException if unable to query (defined by the query)
|
|
396 |
* @throws ArithmeticException if numeric overflow occurs (defined by the query)
|
|
397 |
*/
|
|
398 |
@SuppressWarnings("unchecked")
|
|
399 |
@Override
|
|
400 |
public <R> R query(TemporalQuery<R> query) {
|
16852
|
401 |
if (query == TemporalQuery.precision()) {
|
15289
|
402 |
return (R) DAYS;
|
|
403 |
}
|
|
404 |
return TemporalAccessor.super.query(query);
|
|
405 |
}
|
|
406 |
|
|
407 |
/**
|
|
408 |
* Adjusts the specified temporal object to have this day-of-week.
|
|
409 |
* <p>
|
|
410 |
* This returns a temporal object of the same observable type as the input
|
|
411 |
* with the day-of-week changed to be the same as this.
|
|
412 |
* <p>
|
|
413 |
* The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
|
|
414 |
* passing {@link ChronoField#DAY_OF_WEEK} as the field.
|
|
415 |
* Note that this adjusts forwards or backwards within a Monday to Sunday week.
|
|
416 |
* See {@link WeekFields#dayOfWeek} for localized week start days.
|
16852
|
417 |
* See {@code TemporalAdjuster} for other adjusters with more control,
|
|
418 |
* such as {@code next(MONDAY)}.
|
15289
|
419 |
* <p>
|
|
420 |
* In most cases, it is clearer to reverse the calling pattern by using
|
|
421 |
* {@link Temporal#with(TemporalAdjuster)}:
|
|
422 |
* <pre>
|
|
423 |
* // these two lines are equivalent, but the second approach is recommended
|
|
424 |
* temporal = thisDayOfWeek.adjustInto(temporal);
|
|
425 |
* temporal = temporal.with(thisDayOfWeek);
|
|
426 |
* </pre>
|
|
427 |
* <p>
|
|
428 |
* For example, given a date that is a Wednesday, the following are output:
|
|
429 |
* <pre>
|
|
430 |
* dateOnWed.with(MONDAY); // two days earlier
|
|
431 |
* dateOnWed.with(TUESDAY); // one day earlier
|
|
432 |
* dateOnWed.with(WEDNESDAY); // same date
|
|
433 |
* dateOnWed.with(THURSDAY); // one day later
|
|
434 |
* dateOnWed.with(FRIDAY); // two days later
|
|
435 |
* dateOnWed.with(SATURDAY); // three days later
|
|
436 |
* dateOnWed.with(SUNDAY); // four days later
|
|
437 |
* </pre>
|
|
438 |
* <p>
|
|
439 |
* This instance is immutable and unaffected by this method call.
|
|
440 |
*
|
|
441 |
* @param temporal the target object to be adjusted, not null
|
|
442 |
* @return the adjusted object, not null
|
|
443 |
* @throws DateTimeException if unable to make the adjustment
|
|
444 |
* @throws ArithmeticException if numeric overflow occurs
|
|
445 |
*/
|
|
446 |
@Override
|
|
447 |
public Temporal adjustInto(Temporal temporal) {
|
|
448 |
return temporal.with(DAY_OF_WEEK, getValue());
|
|
449 |
}
|
|
450 |
|
|
451 |
}
|