KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joda > time > LocalTime


1 /*
2  * Copyright 2001-2006 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;
17
18 import java.io.IOException JavaDoc;
19 import java.io.ObjectInputStream JavaDoc;
20 import java.io.ObjectOutputStream JavaDoc;
21 import java.io.Serializable JavaDoc;
22 import java.util.Calendar JavaDoc;
23 import java.util.Date JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Locale JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import org.joda.time.base.AbstractPartial;
29 import org.joda.time.chrono.ISOChronology;
30 import org.joda.time.convert.ConverterManager;
31 import org.joda.time.convert.PartialConverter;
32 import org.joda.time.field.AbstractReadableInstantFieldProperty;
33 import org.joda.time.format.DateTimeFormat;
34 import org.joda.time.format.ISODateTimeFormat;
35
36 /**
37  * LocalTime is an immutable time class representing a time
38  * without a time zone.
39  * <p>
40  * LocalTime implements the {@link ReadablePartial} interface.
41  * To do this, the interface methods focus on the key fields -
42  * HourOfDay, MinuteOfHour, SecondOfMinute and MillisOfSecond.
43  * However, <b>all</b> time fields may in fact be queried.
44  * <p>
45  * Calculations on LocalTime are performed using a {@link Chronology}.
46  * This chronology will be set internally to be in the UTC time zone
47  * for all calculations.
48  *
49  * <p>Each individual field can be queried in two ways:
50  * <ul>
51  * <li><code>getHourOfDay()</code>
52  * <li><code>hourOfDay().get()</code>
53  * </ul>
54  * The second technique also provides access to other useful methods on the
55  * field:
56  * <ul>
57  * <li>numeric value
58  * <li>text value
59  * <li>short text value
60  * <li>maximum/minimum values
61  * <li>add/subtract
62  * <li>set
63  * <li>rounding
64  * </ul>
65  *
66  * <p>
67  * LocalTime is thread-safe and immutable, provided that the Chronology is as well.
68  * All standard Chronology classes supplied are thread-safe and immutable.
69  *
70  * @author Stephen Colebourne
71  * @since 1.3
72  */

73 public final class LocalTime
74         extends AbstractPartial
75         implements ReadablePartial, Serializable JavaDoc {
76
77     /** Serialization lock */
78     private static final long serialVersionUID = -12873158713873L;
79
80     /** Constant for midnight. */
81     public static final LocalTime MIDNIGHT = new LocalTime(0, 0, 0, 0);
82
83     /** The index of the hourOfDay field in the field array */
84     private static final int HOUR_OF_DAY = 0;
85     /** The index of the minuteOfHour field in the field array */
86     private static final int MINUTE_OF_HOUR = 1;
87     /** The index of the secondOfMinute field in the field array */
88     private static final int SECOND_OF_MINUTE = 2;
89     /** The index of the millisOfSecond field in the field array */
90     private static final int MILLIS_OF_SECOND = 3;
91     /** Set of known duration types. */
92     private static final Set JavaDoc TIME_DURATION_TYPES = new HashSet JavaDoc();
93     static {
94         TIME_DURATION_TYPES.add(DurationFieldType.millis());
95         TIME_DURATION_TYPES.add(DurationFieldType.seconds());
96         TIME_DURATION_TYPES.add(DurationFieldType.minutes());
97         TIME_DURATION_TYPES.add(DurationFieldType.hours());
98     }
99
100     /** The local millis from 1970-01-01T00:00:00 */
101     private long iLocalMillis;
102     /** The chronology to use, in UTC */
103     private Chronology iChronology;
104
105     //-----------------------------------------------------------------------
106
/**
107      * Constructs a LocalTime from the specified millis of day using the
108      * ISO chronology.
109      * <p>
110      * The millisOfDay value may exceed the number of millis in one day,
111      * but additional days will be ignored.
112      * This method uses the UTC time zone internally.
113      *
114      * @param millisOfDay the number of milliseconds into a day to convert
115      */

116     public static LocalTime fromMillisOfDay(long millisOfDay) {
117         return fromMillisOfDay(millisOfDay, null);
118     }
119
120     /**
121      * Constructs a LocalTime from the specified millis of day using the
122      * specified chronology.
123      * <p>
124      * The millisOfDay value may exceed the number of millis in one day,
125      * but additional days will be ignored.
126      * This method uses the UTC time zone internally.
127      *
128      * @param millisOfDay the number of milliseconds into a day to convert
129      * @param chrono the chronology, null means ISO chronology
130      */

131     public static LocalTime fromMillisOfDay(long millisOfDay, Chronology chrono) {
132         chrono = DateTimeUtils.getChronology(chrono).withUTC();
133         return new LocalTime(millisOfDay, chrono);
134     }
135
136     //-----------------------------------------------------------------------
137
/**
138      * Constructs a LocalTime from a <code>java.util.Calendar</code>
139      * using exactly the same field values avoiding any time zone effects.
140      * <p>
141      * Each field is queried from the Calendar and assigned to the LocalTime.
142      * This is useful if you have been using the Calendar as a local time,
143      * ignoing the zone.
144      * <p>
145      * This factory method ignores the type of the calendar and always
146      * creates a LocalTime with ISO chronology. It is expected that you
147      * will only pass in instances of <code>GregorianCalendar</code> however
148      * this is not validated.
149      *
150      * @param calendar the Calendar to extract fields from
151      * @return the created LocalTime
152      * @throws IllegalArgumentException if the calendar is null
153      * @throws IllegalArgumentException if the date is invalid for the ISO chronology
154      */

155     public static LocalTime fromCalendarFields(Calendar JavaDoc calendar) {
156         if (calendar == null) {
157             throw new IllegalArgumentException JavaDoc("The calendar must not be null");
158         }
159         return new LocalTime(
160             calendar.get(Calendar.HOUR_OF_DAY),
161             calendar.get(Calendar.MINUTE),
162             calendar.get(Calendar.SECOND),
163             calendar.get(Calendar.MILLISECOND)
164         );
165     }
166
167     /**
168      * Constructs a LocalTime from a <code>java.util.Date</code>
169      * using exactly the same field values avoiding any time zone effects.
170      * <p>
171      * Each field is queried from the Date and assigned to the LocalTime.
172      * This is useful if you have been using the Date as a local time,
173      * ignoing the zone.
174      * <p>
175      * This factory method always creates a LocalTime with ISO chronology.
176      *
177      * @param date the Date to extract fields from
178      * @return the created LocalTime
179      * @throws IllegalArgumentException if the calendar is null
180      * @throws IllegalArgumentException if the date is invalid for the ISO chronology
181      */

182     public static LocalTime fromDateFields(Date JavaDoc date) {
183         if (date == null) {
184             throw new IllegalArgumentException JavaDoc("The date must not be null");
185         }
186         return new LocalTime(
187             date.getHours(),
188             date.getMinutes(),
189             date.getSeconds(),
190             (int) (date.getTime() % 1000)
191         );
192     }
193
194     //-----------------------------------------------------------------------
195
/**
196      * Constructs an instance set to the current local time evaluated using
197      * ISO chronology in the default zone.
198      * <p>
199      * Once the constructor is completed, the zone is no longer used.
200      */

201     public LocalTime() {
202         this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance());
203     }
204
205     /**
206      * Constructs an instance set to the current local time evaluated using
207      * ISO chronology in the specified zone.
208      * <p>
209      * If the specified time zone is null, the default zone is used.
210      * Once the constructor is completed, the zone is no longer used.
211      *
212      * @param zone the time zone, null means default zone
213      */

214     public LocalTime(DateTimeZone zone) {
215         this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance(zone));
216     }
217
218     /**
219      * Constructs an instance set to the current local time evaluated using
220      * specified chronology and zone.
221      * <p>
222      * If the chronology is null, ISO chronology in the default time zone is used.
223      * Once the constructor is completed, the zone is no longer used.
224      *
225      * @param chronology the chronology, null means ISOChronology in default zone
226      */

227     public LocalTime(Chronology chronology) {
228         this(DateTimeUtils.currentTimeMillis(), chronology);
229     }
230
231     //-----------------------------------------------------------------------
232
/**
233      * Constructs an instance set to the local time defined by the specified
234      * instant evaluated using ISO chronology in the default zone.
235      * <p>
236      * Once the constructor is completed, the zone is no longer used.
237      *
238      * @param instant the milliseconds from 1970-01-01T00:00:00Z
239      */

240     public LocalTime(long instant) {
241         this(instant, ISOChronology.getInstance());
242     }
243
244     /**
245      * Constructs an instance set to the local time defined by the specified
246      * instant evaluated using ISO chronology in the specified zone.
247      * <p>
248      * If the specified time zone is null, the default zone is used.
249      * Once the constructor is completed, the zone is no longer used.
250      *
251      * @param instant the milliseconds from 1970-01-01T00:00:00Z
252      * @param zone the time zone, null means default zone
253      */

254     public LocalTime(long instant, DateTimeZone zone) {
255         this(instant, ISOChronology.getInstance(zone));
256     }
257
258     /**
259      * Constructs an instance set to the local time defined by the specified
260      * instant evaluated using the specified chronology.
261      * <p>
262      * If the chronology is null, ISO chronology in the default zone is used.
263      * Once the constructor is completed, the zone is no longer used.
264      *
265      * @param instant the milliseconds from 1970-01-01T00:00:00Z
266      * @param chronology the chronology, null means ISOChronology in default zone
267      */

268     public LocalTime(long instant, Chronology chronology) {
269         chronology = DateTimeUtils.getChronology(chronology);
270         
271         long localMillis = chronology.getZone().getMillisKeepLocal(DateTimeZone.UTC, instant);
272         chronology = chronology.withUTC();
273         chronology.millisOfDay().get(localMillis);
274         iLocalMillis = localMillis;
275         iChronology = chronology;
276     }
277
278     //-----------------------------------------------------------------------
279
/**
280      * Constructs an instance from an Object that represents a datetime.
281      * <p>
282      * If the object contains no chronology, <code>ISOChronology</code> is used.
283      * If the object contains no time zone, the default zone is used.
284      * Once the constructor is completed, the zone is no longer used.
285      * <p>
286      * The recognised object types are defined in
287      * {@link org.joda.time.convert.ConverterManager ConverterManager} and
288      * include ReadablePartial, ReadableInstant, String, Calendar and Date.
289      * The String formats are described by {@link ISODateTimeFormat#localTimeParser()}.
290      * The default String converter ignores the zone and only parses the field values.
291      *
292      * @param instant the datetime object
293      * @throws IllegalArgumentException if the instant is invalid
294      */

295     public LocalTime(Object JavaDoc instant) {
296         this(instant, (Chronology) null);
297     }
298
299     /**
300      * Constructs an instance from an Object that represents a datetime,
301      * forcing the time zone to that specified.
302      * <p>
303      * If the object contains no chronology, <code>ISOChronology</code> is used.
304      * If the specified time zone is null, the default zone is used.
305      * Once the constructor is completed, the zone is no longer used.
306      * <p>
307      * The recognised object types are defined in
308      * {@link org.joda.time.convert.ConverterManager ConverterManager} and
309      * include ReadablePartial, ReadableInstant, String, Calendar and Date.
310      * The String formats are described by {@link ISODateTimeFormat#localTimeParser()}.
311      * The default String converter ignores the zone and only parses the field values.
312      *
313      * @param instant the datetime object
314      * @param zone the time zone
315      * @throws IllegalArgumentException if the instant is invalid
316      */

317     public LocalTime(Object JavaDoc instant, DateTimeZone zone) {
318         PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
319         Chronology chronology = converter.getChronology(instant, zone);
320         chronology = DateTimeUtils.getChronology(chronology);
321         iChronology = chronology.withUTC();
322         int[] values = converter.getPartialValues(this, instant, chronology, ISODateTimeFormat.localTimeParser());
323         iLocalMillis = iChronology.getDateTimeMillis(0L, values[0], values[1], values[2], values[3]);
324     }
325
326     /**
327      * Constructs an instance from an Object that represents a datetime,
328      * using the specified chronology.
329      * <p>
330      * If the chronology is null, ISO in the default time zone is used.
331      * Once the constructor is completed, the zone is no longer used.
332      * <p>
333      * The recognised object types are defined in
334      * {@link org.joda.time.convert.ConverterManager ConverterManager} and
335      * include ReadablePartial, ReadableInstant, String, Calendar and Date.
336      * The String formats are described by {@link ISODateTimeFormat#localTimeParser()}.
337      * The default String converter ignores the zone and only parses the field values.
338      *
339      * @param instant the datetime object
340      * @param chronology the chronology
341      * @throws IllegalArgumentException if the instant is invalid
342      */

343     public LocalTime(Object JavaDoc instant, Chronology chronology) {
344         PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant);
345         chronology = converter.getChronology(instant, chronology);
346         chronology = DateTimeUtils.getChronology(chronology);
347         iChronology = chronology.withUTC();
348         int[] values = converter.getPartialValues(this, instant, chronology, ISODateTimeFormat.localTimeParser());
349         iLocalMillis = iChronology.getDateTimeMillis(0L, values[0], values[1], values[2], values[3]);
350     }
351
352     //-----------------------------------------------------------------------
353
/**
354      * Constructs an instance set to the specified time
355      * using <code>ISOChronology</code>.
356      *
357      * @param hourOfDay the hour of the day
358      * @param minuteOfHour the minute of the hour
359      */

360     public LocalTime(
361             int hourOfDay,
362             int minuteOfHour) {
363         this(hourOfDay, minuteOfHour, 0, 0, ISOChronology.getInstanceUTC());
364     }
365
366     /**
367      * Constructs an instance set to the specified time
368      * using <code>ISOChronology</code>.
369      *
370      * @param hourOfDay the hour of the day
371      * @param minuteOfHour the minute of the hour
372      * @param secondOfMinute the second of the minute
373      */

374     public LocalTime(
375             int hourOfDay,
376             int minuteOfHour,
377             int secondOfMinute) {
378         this(hourOfDay, minuteOfHour, secondOfMinute, 0, ISOChronology.getInstanceUTC());
379     }
380
381     /**
382      * Constructs an instance set to the specified time
383      * using <code>ISOChronology</code>.
384      *
385      * @param hourOfDay the hour of the day
386      * @param minuteOfHour the minute of the hour
387      * @param secondOfMinute the second of the minute
388      * @param millisOfSecond the millisecond of the second
389      */

390     public LocalTime(
391             int hourOfDay,
392             int minuteOfHour,
393             int secondOfMinute,
394             int millisOfSecond) {
395         this(hourOfDay, minuteOfHour, secondOfMinute,
396                 millisOfSecond, ISOChronology.getInstanceUTC());
397     }
398
399     /**
400      * Constructs an instance set to the specified time
401      * using the specified chronology, whose zone is ignored.
402      * <p>
403      * If the chronology is null, <code>ISOChronology</code> is used.
404      *
405      * @param hourOfDay the hour of the day
406      * @param minuteOfHour the minute of the hour
407      * @param secondOfMinute the second of the minute
408      * @param millisOfSecond the millisecond of the second
409      * @param chronology the chronology, null means ISOChronology in default zone
410      */

411     public LocalTime(
412             int hourOfDay,
413             int minuteOfHour,
414             int secondOfMinute,
415             int millisOfSecond,
416             Chronology chronology) {
417         super();
418         chronology = DateTimeUtils.getChronology(chronology).withUTC();
419         long instant = chronology.getDateTimeMillis(
420             0L, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
421         iChronology = chronology;
422         iLocalMillis = instant;
423     }
424
425     //-----------------------------------------------------------------------
426
/**
427      * Gets the number of fields in this partial, which is four.
428      * The supported fields are HourOfDay, MinuteOfHour, SecondOfMinute
429      * and MillisOfSecond.
430      *
431      * @return the field count, four
432      */

433     public int size() {
434         return 4;
435     }
436
437     /**
438      * Gets the field for a specific index in the chronology specified.
439      * <p>
440      * This method must not use any instance variables.
441      *
442      * @param index the index to retrieve
443      * @param chrono the chronology to use
444      * @return the field
445      */

446     protected DateTimeField getField(int index, Chronology chrono) {
447         switch (index) {
448             case HOUR_OF_DAY:
449                 return chrono.hourOfDay();
450             case MINUTE_OF_HOUR:
451                 return chrono.minuteOfHour();
452             case SECOND_OF_MINUTE:
453                 return chrono.secondOfMinute();
454             case MILLIS_OF_SECOND:
455                 return chrono.millisOfSecond();
456             default:
457                 throw new IndexOutOfBoundsException JavaDoc("Invalid index: " + index);
458         }
459     }
460
461     /**
462      * Gets the value of the field at the specifed index.
463      * <p>
464      * This method is required to support the <code>ReadablePartial</code>
465      * interface. The supported fields are HourOfDay, MinuteOfHour,
466      * SecondOfMinute and MillisOfSecond.
467      *
468      * @param index the index, zero to three
469      * @return the value
470      * @throws IndexOutOfBoundsException if the index is invalid
471      */

472     public int getValue(int index) {
473         switch (index) {
474             case HOUR_OF_DAY:
475                 return getChronology().hourOfDay().get(getLocalMillis());
476             case MINUTE_OF_HOUR:
477                 return getChronology().minuteOfHour().get(getLocalMillis());
478             case SECOND_OF_MINUTE:
479                 return getChronology().secondOfMinute().get(getLocalMillis());
480             case MILLIS_OF_SECOND:
481                 return getChronology().millisOfSecond().get(getLocalMillis());
482             default:
483                 throw new IndexOutOfBoundsException JavaDoc("Invalid index: " + index);
484         }
485     }
486
487     //-----------------------------------------------------------------------
488
/**
489      * Get the value of one of the fields of time.
490      * <p>
491      * This method gets the value of the specified field.
492      * For example:
493      * <pre>
494      * DateTime dt = new DateTime();
495      * int hourOfDay = dt.get(DateTimeFieldType.hourOfDay());
496      * </pre>
497      *
498      * @param fieldType a field type, usually obtained from DateTimeFieldType, not null
499      * @return the value of that field
500      * @throws IllegalArgumentException if the field type is null
501      */

502     public int get(DateTimeFieldType fieldType) {
503         if (fieldType == null) {
504             throw new IllegalArgumentException JavaDoc("The DateTimeFieldType must not be null");
505         }
506         if (isSupported(fieldType) == false) {
507             throw new IllegalArgumentException JavaDoc("Field '" + fieldType + "' is not supported");
508         }
509         return fieldType.getField(getChronology()).get(getLocalMillis());
510     }
511
512     /**
513      * Checks if the field type specified is supported by this
514      * local time and chronology.
515      * This can be used to avoid exceptions in {@link #get(DateTimeFieldType)}.
516      *
517      * @param type a field type, usually obtained from DateTimeFieldType
518      * @return true if the field type is supported
519      */

520     public boolean isSupported(DateTimeFieldType type) {
521         if (type == null) {
522             return false;
523         }
524         if (isSupported(type.getDurationType()) == false) {
525             return false;
526         }
527         DurationFieldType range = type.getRangeDurationType();
528         return (isSupported(range) || range == DurationFieldType.days());
529     }
530
531     /**
532      * Checks if the duration type specified is supported by this
533      * local time and chronology.
534      *
535      * @param type a duration type, usually obtained from DurationFieldType
536      * @return true if the field type is supported
537      */

538     public boolean isSupported(DurationFieldType type) {
539         if (type == null) {
540             return false;
541         }
542         DurationField field = type.getField(getChronology());
543         if (TIME_DURATION_TYPES.contains(type) ||
544             field.getUnitMillis() < getChronology().days().getUnitMillis()) {
545             return field.isSupported();
546         }
547         return false;
548     }
549
550     //-----------------------------------------------------------------------
551
/**
552      * Gets the local milliseconds from the Java epoch
553      * of 1970-01-01T00:00:00 (not fixed to any specific time zone).
554      *
555      * @return the number of milliseconds since 1970-01-01T00:00:00
556      */

557     long getLocalMillis() {
558         return iLocalMillis;
559     }
560
561     /**
562      * Gets the chronology of the time.
563      *
564      * @return the Chronology that the time is using
565      */

566     public Chronology getChronology() {
567         return iChronology;
568     }
569
570     //-----------------------------------------------------------------------
571
/**
572      * Returns a copy of this time with different local millis.
573      * <p>
574      * The returned object will be a new instance of the same type.
575      * Only the millis will change, the chronology is kept.
576      * The returned object will be either be a new instance or <code>this</code>.
577      *
578      * @param newMillis the new millis, from 1970-01-01T00:00:00
579      * @return a copy of this time with different millis
580      */

581     LocalTime withLocalMillis(long newMillis) {
582         return (newMillis == getLocalMillis() ? this : new LocalTime(newMillis, getChronology()));
583     }
584
585     //-----------------------------------------------------------------------
586
/**
587      * Returns a copy of this time with the partial set of fields replacing
588      * those from this instance.
589      * <p>
590      * For example, if the partial contains an hour and minute then those two
591      * fields will be changed in the returned instance.
592      * Unsupported fields are ignored.
593      * If the partial is null, then <code>this</code> is returned.
594      *
595      * @param partial the partial set of fields to apply to this time, null ignored
596      * @return a copy of this time with a different set of fields
597      * @throws IllegalArgumentException if any value is invalid
598      */

599     public LocalTime withFields(ReadablePartial partial) {
600         if (partial == null) {
601             return this;
602         }
603         return withLocalMillis(getChronology().set(partial, getLocalMillis()));
604     }
605
606     /**
607      * Returns a copy of this time with the specified field set
608      * to a new value.
609      * <p>
610      * For example, if the field type is <code>hourOfDay</code> then the hour of day
611      * field would be changed in the returned instance.
612      * If the field type is null, then <code>this</code> is returned.
613      * <p>
614      * These lines are equivalent:
615      * <pre>
616      * LocalTime updated = dt.withHourOfDay(6);
617      * LocalTime updated = dt.withField(DateTimeFieldType.hourOfDay(), 6);
618      * </pre>
619      *
620      * @param fieldType the field type to set, not null
621      * @param value the value to set
622      * @return a copy of this time with the field set
623      * @throws IllegalArgumentException if the value is null or invalid
624      */

625     public LocalTime withField(DateTimeFieldType fieldType, int value) {
626         if (fieldType == null) {
627             throw new IllegalArgumentException JavaDoc("Field must not be null");
628         }
629         if (isSupported(fieldType) == false) {
630             throw new IllegalArgumentException JavaDoc("Field '" + fieldType + "' is not supported");
631         }
632         long instant = fieldType.getField(getChronology()).set(getLocalMillis(), value);
633         return withLocalMillis(instant);
634     }
635
636     /**
637      * Returns a copy of this time with the value of the specified
638      * field increased.
639      * <p>
640      * If the addition is zero or the field is null, then <code>this</code>
641      * is returned.
642      * <p>
643      * If the addition causes the maximum value of the field to be exceeded,
644      * then the value will wrap. Thus 23:59 plus two minutes yields 00:01.
645      * <p>
646      * These lines are equivalent:
647      * <pre>
648      * LocalTime added = dt.plusHours(6);
649      * LocalTime added = dt.withFieldAdded(DurationFieldType.hours(), 6);
650      * </pre>
651      *
652      * @param fieldType the field type to add to, not null
653      * @param amount the amount to add
654      * @return a copy of this time with the field updated
655      * @throws IllegalArgumentException if the value is null or invalid
656      * @throws ArithmeticException if the result exceeds the internal capacity
657      */

658     public LocalTime withFieldAdded(DurationFieldType fieldType, int amount) {
659         if (fieldType == null) {
660             throw new IllegalArgumentException JavaDoc("Field must not be null");
661         }
662         if (isSupported(fieldType) == false) {
663             throw new IllegalArgumentException JavaDoc("Field '" + fieldType + "' is not supported");
664         }
665         if (amount == 0) {
666             return this;
667         }
668         long instant = fieldType.getField(getChronology()).add(getLocalMillis(), amount);
669         return withLocalMillis(instant);
670     }
671
672     //-----------------------------------------------------------------------
673
/**
674      * Returns a copy of this time with the specified period added.
675      * <p>
676      * If the addition is zero, then <code>this</code> is returned.
677      * <p>
678      * This method is typically used to add multiple copies of complex
679      * period instances. Adding one field is best achieved using methods
680      * like {@link #withFieldAdded(DurationFieldType, int)}
681      * or {@link #plusHours(int)}.
682      *
683      * @param period the period to add to this one, null means zero
684      * @param scalar the amount of times to add, such as -1 to subtract once
685      * @return a copy of this time with the period added
686      * @throws ArithmeticException if the result exceeds the internal capacity
687      */

688     public LocalTime withPeriodAdded(ReadablePeriod period, int scalar) {
689         if (period == null || scalar == 0) {
690             return this;
691         }
692         long instant = getChronology().add(period, getLocalMillis(), scalar);
693         return withLocalMillis(instant);
694     }
695
696     //-----------------------------------------------------------------------
697
/**
698      * Returns a copy of this time with the specified period added.
699      * <p>
700      * If the amount is zero or null, then <code>this</code> is returned.
701      * <p>
702      * This method is typically used to add complex period instances.
703      * Adding one field is best achieved using methods
704      * like {@link #plusHours(int)}.
705      *
706      * @param period the period to add to this one, null means zero
707      * @return a copy of this time with the period added
708      * @throws ArithmeticException if the result exceeds the internal capacity
709      */

710     public LocalTime plus(ReadablePeriod period) {
711         return withPeriodAdded(period, 1);
712     }
713
714     //-----------------------------------------------------------------------
715
/**
716      * Returns a copy of this time plus the specified number of hours.
717      * <p>
718      * This LocalTime instance is immutable and unaffected by this method call.
719      * <p>
720      * The following three lines are identical in effect:
721      * <pre>
722      * LocalTime added = dt.plusHours(6);
723      * LocalTime added = dt.plus(Period.hours(6));
724      * LocalTime added = dt.withFieldAdded(DurationFieldType.hours(), 6);
725      * </pre>
726      *
727      * @param hours the amount of hours to add, may be negative
728      * @return the new LocalTime plus the increased hours
729      */

730     public LocalTime plusHours(int hours) {
731         if (hours == 0) {
732             return this;
733         }
734         long instant = getChronology().hours().add(getLocalMillis(), hours);
735         return withLocalMillis(instant);
736     }
737
738     /**
739      * Returns a copy of this time plus the specified number of minutes.
740      * <p>
741      * This LocalTime instance is immutable and unaffected by this method call.
742      * <p>
743      * The following three lines are identical in effect:
744      * <pre>
745      * LocalTime added = dt.plusMinutes(6);
746      * LocalTime added = dt.plus(Period.minutes(6));
747      * LocalTime added = dt.withFieldAdded(DurationFieldType.minutes(), 6);
748      * </pre>
749      *
750      * @param minutes the amount of minutes to add, may be negative
751      * @return the new LocalTime plus the increased minutes
752      */

753     public LocalTime plusMinutes(int minutes) {
754         if (minutes == 0) {
755             return this;
756         }
757         long instant = getChronology().minutes().add(getLocalMillis(), minutes);
758         return withLocalMillis(instant);
759     }
760
761     /**
762      * Returns a copy of this time plus the specified number of seconds.
763      * <p>
764      * This LocalTime instance is immutable and unaffected by this method call.
765      * <p>
766      * The following three lines are identical in effect:
767      * <pre>
768      * LocalTime added = dt.plusSeconds(6);
769      * LocalTime added = dt.plus(Period.seconds(6));
770      * LocalTime added = dt.withFieldAdded(DurationFieldType.seconds(), 6);
771      * </pre>
772      *
773      * @param seconds the amount of seconds to add, may be negative
774      * @return the new LocalTime plus the increased seconds
775      */

776     public LocalTime plusSeconds(int seconds) {
777         if (seconds == 0) {
778             return this;
779         }
780         long instant = getChronology().seconds().add(getLocalMillis(), seconds);
781         return withLocalMillis(instant);
782     }
783
784     /**
785      * Returns a copy of this time plus the specified number of millis.
786      * <p>
787      * This LocalTime instance is immutable and unaffected by this method call.
788      * <p>
789      * The following three lines are identical in effect:
790      * <pre>
791      * LocalTime added = dt.plusMillis(6);
792      * LocalTime added = dt.plus(Period.millis(6));
793      * LocalTime added = dt.withFieldAdded(DurationFieldType.millis(), 6);
794      * </pre>
795      *
796      * @param millis the amount of millis to add, may be negative
797      * @return the new LocalTime plus the increased millis
798      */

799     public LocalTime plusMillis(int millis) {
800         if (millis == 0) {
801             return this;
802         }
803         long instant = getChronology().millis().add(getLocalMillis(), millis);
804         return withLocalMillis(instant);
805     }
806
807     //-----------------------------------------------------------------------
808
/**
809      * Returns a copy of this time with the specified period taken away.
810      * <p>
811      * If the amount is zero or null, then <code>this</code> is returned.
812      * <p>
813      * This method is typically used to subtract complex period instances.
814      * Subtracting one field is best achieved using methods
815      * like {@link #minusHours(int)}.
816      *
817      * @param period the period to reduce this instant by
818      * @return a copy of this time with the period taken away
819      * @throws ArithmeticException if the result exceeds the internal capacity
820      */

821     public LocalTime minus(ReadablePeriod period) {
822         return withPeriodAdded(period, -1);
823     }
824
825     //-----------------------------------------------------------------------
826
/**
827      * Returns a copy of this time minus the specified number of hours.
828      * <p>
829      * This LocalTime instance is immutable and unaffected by this method call.
830      * <p>
831      * The following three lines are identical in effect:
832      * <pre>
833      * LocalTime subtracted = dt.minusHours(6);
834      * LocalTime subtracted = dt.minus(Period.hours(6));
835      * LocalTime subtracted = dt.withFieldAdded(DurationFieldType.hours(), -6);
836      * </pre>
837      *
838      * @param hours the amount of hours to subtract, may be negative
839      * @return the new LocalTime minus the increased hours
840      */

841     public LocalTime minusHours(int hours) {
842         if (hours == 0) {
843             return this;
844         }
845         long instant = getChronology().hours().subtract(getLocalMillis(), hours);
846         return withLocalMillis(instant);
847     }
848
849     /**
850      * Returns a copy of this time minus the specified number of minutes.
851      * <p>
852      * This LocalTime instance is immutable and unaffected by this method call.
853      * <p>
854      * The following three lines are identical in effect:
855      * <pre>
856      * LocalTime subtracted = dt.minusMinutes(6);
857      * LocalTime subtracted = dt.minus(Period.minutes(6));
858      * LocalTime subtracted = dt.withFieldAdded(DurationFieldType.minutes(), -6);
859      * </pre>
860      *
861      * @param minutes the amount of minutes to subtract, may be negative
862      * @return the new LocalTime minus the increased minutes
863      */

864     public LocalTime minusMinutes(int minutes) {
865         if (minutes == 0) {
866             return this;
867         }
868         long instant = getChronology().minutes().subtract(getLocalMillis(), minutes);
869         return withLocalMillis(instant);
870     }
871
872     /**
873      * Returns a copy of this time minus the specified number of seconds.
874      * <p>
875      * This LocalTime instance is immutable and unaffected by this method call.
876      * <p>
877      * The following three lines are identical in effect:
878      * <pre>
879      * LocalTime subtracted = dt.minusSeconds(6);
880      * LocalTime subtracted = dt.minus(Period.seconds(6));
881      * LocalTime subtracted = dt.withFieldAdded(DurationFieldType.seconds(), -6);
882      * </pre>
883      *
884      * @param seconds the amount of seconds to subtract, may be negative
885      * @return the new LocalTime minus the increased seconds
886      */

887     public LocalTime minusSeconds(int seconds) {
888         if (seconds == 0) {
889             return this;
890         }
891         long instant = getChronology().seconds().subtract(getLocalMillis(), seconds);
892         return withLocalMillis(instant);
893     }
894
895     /**
896      * Returns a copy of this time minus the specified number of millis.
897      * <p>
898      * This LocalTime instance is immutable and unaffected by this method call.
899      * <p>
900      * The following three lines are identical in effect:
901      * <pre>
902      * LocalTime subtracted = dt.minusMillis(6);
903      * LocalTime subtracted = dt.minus(Period.millis(6));
904      * LocalTime subtracted = dt.withFieldAdded(DurationFieldType.millis(), -6);
905      * </pre>
906      *
907      * @param millis the amount of millis to subtract, may be negative
908      * @return the new LocalTime minus the increased millis
909      */

910     public LocalTime minusMillis(int millis) {
911         if (millis == 0) {
912             return this;
913         }
914         long instant = getChronology().millis().subtract(getLocalMillis(), millis);
915         return withLocalMillis(instant);
916     }
917
918     //-----------------------------------------------------------------------
919
/**
920      * Gets the property object for the specified type, which contains
921      * many useful methods.
922      *
923      * @param fieldType the field type to get the chronology for
924      * @return the property object
925      * @throws IllegalArgumentException if the field is null or unsupported
926      */

927     public Property property(DateTimeFieldType fieldType) {
928         if (fieldType == null) {
929             throw new IllegalArgumentException JavaDoc("The DateTimeFieldType must not be null");
930         }
931         if (isSupported(fieldType) == false) {
932             throw new IllegalArgumentException JavaDoc("Field '" + fieldType + "' is not supported");
933         }
934         return new Property(this, fieldType.getField(getChronology()));
935     }
936
937     //-----------------------------------------------------------------------
938
/**
939      * Get the hour of day field value.
940      *
941      * @return the hour of day
942      */

943     public int getHourOfDay() {
944         return getChronology().hourOfDay().get(getLocalMillis());
945     }
946
947     /**
948      * Get the minute of hour field value.
949      *
950      * @return the minute of hour
951      */

952     public int getMinuteOfHour() {
953         return getChronology().minuteOfHour().get(getLocalMillis());
954     }
955
956     /**
957      * Get the second of minute field value.
958      *
959      * @return the second of minute
960      */

961     public int getSecondOfMinute() {
962         return getChronology().secondOfMinute().get(getLocalMillis());
963     }
964
965     /**
966      * Get the millis of second field value.
967      *
968      * @return the millis of second
969      */

970     public int getMillisOfSecond() {
971         return getChronology().millisOfSecond().get(getLocalMillis());
972     }
973
974     /**
975      * Get the millis of day field value.
976      *
977      * @return the millis of day
978      */

979     public int getMillisOfDay() {
980         return getChronology().millisOfDay().get(getLocalMillis());
981     }
982
983     //-----------------------------------------------------------------------
984
/**
985      * Returns a copy of this time with the hour of day field updated.
986      * <p>
987      * LocalTime is immutable, so there are no set methods.
988      * Instead, this method returns a new instance with the value of
989      * hour of day changed.
990      *
991      * @param hour the hour of day to set
992      * @return a copy of this object with the field set
993      * @throws IllegalArgumentException if the value is invalid
994      */

995     public LocalTime withHourOfDay(int hour) {
996         return withLocalMillis(getChronology().hourOfDay().set(getLocalMillis(), hour));
997     }
998
999     /**
1000     * Returns a copy of this time with the minute of hour field updated.
1001     * <p>
1002     * LocalTime is immutable, so there are no set methods.
1003     * Instead, this method returns a new instance with the value of
1004     * minute of hour changed.
1005     *
1006     * @param minute the minute of hour to set
1007     * @return a copy of this object with the field set
1008     * @throws IllegalArgumentException if the value is invalid
1009     */

1010    public LocalTime withMinuteOfHour(int minute) {
1011        return withLocalMillis(getChronology().minuteOfHour().set(getLocalMillis(), minute));
1012    }
1013
1014    /**
1015     * Returns a copy of this time with the second of minute field updated.
1016     * <p>
1017     * LocalTime is immutable, so there are no set methods.
1018     * Instead, this method returns a new instance with the value of
1019     * second of minute changed.
1020     *
1021     * @param second the second of minute to set
1022     * @return a copy of this object with the field set
1023     * @throws IllegalArgumentException if the value is invalid
1024     */

1025    public LocalTime withSecondOfMinute(int second) {
1026        return withLocalMillis(getChronology().secondOfMinute().set(getLocalMillis(), second));
1027    }
1028
1029    /**
1030     * Returns a copy of this time with the millis of second field updated.
1031     * <p>
1032     * LocalTime is immutable, so there are no set methods.
1033     * Instead, this method returns a new instance with the value of
1034     * millis of second changed.
1035     *
1036     * @param millis the millis of second to set
1037     * @return a copy of this object with the field set
1038     * @throws IllegalArgumentException if the value is invalid
1039     */

1040    public LocalTime withMillisOfSecond(int millis) {
1041        return withLocalMillis(getChronology().millisOfSecond().set(getLocalMillis(), millis));
1042    }
1043
1044    /**
1045     * Returns a copy of this time with the millis of day field updated.
1046     * <p>
1047     * LocalTime is immutable, so there are no set methods.
1048     * Instead, this method returns a new instance with the value of
1049     * millis of day changed.
1050     *
1051     * @param millis the millis of day to set
1052     * @return a copy of this object with the field set
1053     * @throws IllegalArgumentException if the value is invalid
1054     */

1055    public LocalTime withMillisOfDay(int millis) {
1056        return withLocalMillis(getChronology().millisOfDay().set(getLocalMillis(), millis));
1057    }
1058
1059    //-----------------------------------------------------------------------
1060
/**
1061     * Get the hour of day field property which provides access to advanced functionality.
1062     *
1063     * @return the hour of day property
1064     */

1065    public Property hourOfDay() {
1066        return new Property(this, getChronology().hourOfDay());
1067    }
1068
1069    /**
1070     * Get the minute of hour field property which provides access to advanced functionality.
1071     *
1072     * @return the minute of hour property
1073     */

1074    public Property minuteOfHour() {
1075        return new Property(this, getChronology().minuteOfHour());
1076    }
1077
1078    /**
1079     * Get the second of minute field property which provides access to advanced functionality.
1080     *
1081     * @return the second of minute property
1082     */

1083    public Property secondOfMinute() {
1084        return new Property(this, getChronology().secondOfMinute());
1085    }
1086
1087    /**
1088     * Get the millis of second property which provides access to advanced functionality.
1089     *
1090     * @return the millis of second property
1091     */

1092    public Property millisOfSecond() {
1093        return new Property(this, getChronology().millisOfSecond());
1094    }
1095
1096    /**
1097     * Get the millis of day property which provides access to advanced functionality.
1098     *
1099     * @return the millis of day property
1100     */

1101    public Property millisOfDay() {
1102        return new Property(this, getChronology().millisOfDay());
1103    }
1104
1105    //-----------------------------------------------------------------------
1106
/**
1107     * Converts this LocalTime to a full datetime using the default time zone
1108     * setting the time fields from this instance and the date fields from
1109     * the current date.
1110     *
1111     * @return this time as a datetime using todays date
1112     */

1113    public DateTime toDateTimeToday() {
1114        return toDateTimeToday(null);
1115    }
1116
1117    /**
1118     * Converts this LocalTime to a full datetime using the specified time zone
1119     * setting the time fields from this instance and the date fields from
1120     * the current time.
1121     * <p>
1122     * This method uses the chronology from this instance plus the time zone
1123     * specified.
1124     *
1125     * @param zone the zone to use, null means default
1126     * @return this time as a datetime using todays date
1127     */

1128    public DateTime toDateTimeToday(DateTimeZone zone) {
1129        Chronology chrono = getChronology().withZone(zone);
1130        long instantMillis = DateTimeUtils.currentTimeMillis();
1131        long resolved = chrono.set(this, instantMillis);
1132        return new DateTime(resolved, chrono);
1133    }
1134
1135    //-----------------------------------------------------------------------
1136
/**
1137     * Output the time in ISO8601 format (HH:mm:ss.SSSZ).
1138     *
1139     * @return ISO8601 time formatted string.
1140     */

1141    public String JavaDoc toString() {
1142        return ISODateTimeFormat.time().print(this);
1143    }
1144
1145    /**
1146     * Output the time using the specified format pattern.
1147     *
1148     * @param pattern the pattern specification, null means use <code>toString</code>
1149     * @see org.joda.time.format.DateTimeFormat
1150     */

1151    public String JavaDoc toString(String JavaDoc pattern) {
1152        if (pattern == null) {
1153            return toString();
1154        }
1155        return DateTimeFormat.forPattern(pattern).print(this);
1156    }
1157
1158    /**
1159     * Output the time using the specified format pattern.
1160     *
1161     * @param pattern the pattern specification, null means use <code>toString</code>
1162     * @param locale Locale to use, null means default
1163     * @see org.joda.time.format.DateTimeFormat
1164     */

1165    public String JavaDoc toString(String JavaDoc pattern, Locale JavaDoc locale) throws IllegalArgumentException JavaDoc {
1166        if (pattern == null) {
1167            return toString();
1168        }
1169        return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this);
1170    }
1171
1172    //-----------------------------------------------------------------------
1173
/**
1174     * LocalTime.Property binds a LocalTime to a DateTimeField allowing
1175     * powerful datetime functionality to be easily accessed.
1176     * <p>
1177     * The simplest use of this class is as an alternative get method, here used to
1178     * get the minute '30'.
1179     * <pre>
1180     * LocalTime dt = new LocalTime(12, 30);
1181     * int year = dt.minuteOfHour().get();
1182     * </pre>
1183     * <p>
1184     * Methods are also provided that allow time modification. These return
1185     * new instances of LocalTime - they do not modify the original. The example
1186     * below yields two independent immutable date objects 2 hours apart.
1187     * <pre>
1188     * LocalTime dt1230 = new LocalTime(12, 30);
1189     * LocalTime dt1430 = dt1230.hourOfDay().setCopy(14);
1190     * </pre>
1191     * <p>
1192     * LocalTime.Property itself is thread-safe and immutable, as well as the
1193     * LocalTime being operated on.
1194     *
1195     * @author Stephen Colebourne
1196     * @author Brian S O'Neill
1197     * @since 1.3
1198     */

1199    public static final class Property extends AbstractReadableInstantFieldProperty {
1200        
1201        /** Serialization version */
1202        private static final long serialVersionUID = -325842547277223L;
1203        
1204        /** The instant this property is working against */
1205        private transient LocalTime iInstant;
1206        /** The field this property is working against */
1207        private transient DateTimeField iField;
1208        
1209        /**
1210         * Constructor.
1211         *
1212         * @param instant the instant to set
1213         * @param field the field to use
1214         */

1215        Property(LocalTime instant, DateTimeField field) {
1216            super();
1217            iInstant = instant;
1218            iField = field;
1219        }
1220        
1221        /**
1222         * Writes the property in a safe serialization format.
1223         */

1224        private void writeObject(ObjectOutputStream JavaDoc oos) throws IOException JavaDoc {
1225            oos.writeObject(iInstant);
1226            oos.writeObject(iField.getType());
1227        }
1228        
1229        /**
1230         * Reads the property from a safe serialization format.
1231         */

1232        private void readObject(ObjectInputStream JavaDoc oos) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
1233            iInstant = (LocalTime) oos.readObject();
1234            DateTimeFieldType type = (DateTimeFieldType) oos.readObject();
1235            iField = type.getField(iInstant.getChronology());
1236        }
1237        
1238        //-----------------------------------------------------------------------
1239
/**
1240         * Gets the field being used.
1241         *
1242         * @return the field
1243         */

1244        public DateTimeField getField() {
1245            return iField;
1246        }
1247        
1248        /**
1249         * Gets the milliseconds of the time that this property is linked to.
1250         *
1251         * @return the milliseconds
1252         */

1253        protected long getMillis() {
1254            return iInstant.getLocalMillis();
1255        }
1256        
1257        /**
1258         * Gets the chronology of the datetime that this property is linked to.
1259         *
1260         * @return the chronology
1261         * @since 1.4
1262         */

1263        protected Chronology getChronology() {
1264            return iInstant.getChronology();
1265        }
1266        
1267        /**
1268         * Gets the LocalTime object linked to this property.
1269         *
1270         * @return the linked LocalTime
1271         */

1272        public LocalTime getLocalTime() {
1273            return iInstant;
1274        }
1275        
1276        //-----------------------------------------------------------------------
1277
/**
1278         * Adds to this field in a copy of this LocalTime.
1279         * <p>
1280         * The LocalTime attached to this property is unchanged by this call.
1281         *
1282         * @param value the value to add to the field in the copy
1283         * @return a copy of the LocalTime with the field value changed
1284         */

1285        public LocalTime addCopy(int value) {
1286            return iInstant.withLocalMillis(iField.add(iInstant.getLocalMillis(), value));
1287        }
1288        
1289        /**
1290         * Adds to this field in a copy of this LocalTime.
1291         * If the addition exceeds the maximum value (eg. 23:59) it will
1292         * wrap to the minimum value (eg. 00:00).
1293         * <p>
1294         * The LocalTime attached to this property is unchanged by this call.
1295         *
1296         * @param value the value to add to the field in the copy
1297         * @return a copy of the LocalTime with the field value changed
1298         */

1299        public LocalTime addCopy(long value) {
1300            return iInstant.withLocalMillis(iField.add(iInstant.getLocalMillis(), value));
1301        }
1302        
1303        /**
1304         * Adds to this field in a copy of this LocalTime.
1305         * If the addition exceeds the maximum value (eg. 23:59) then
1306         * an exception will be thrown.
1307         * Contrast this behaviour to {@link #addCopy(int)}.
1308         * <p>
1309         * The LocalTime attached to this property is unchanged by this call.
1310         *
1311         * @param value the value to add to the field in the copy
1312         * @return a copy of the LocalTime with the field value changed
1313         * @throws IllegalArgumentException if the result is invalid
1314         */

1315        public LocalTime addNoWrapToCopy(int value) {
1316            long millis = iField.add(iInstant.getLocalMillis(), value);
1317            long rounded = iInstant.getChronology().millisOfDay().get(millis);
1318            if (rounded != millis) {
1319                throw new IllegalArgumentException JavaDoc("The addition exceeded the boundaries of LocalTime");
1320            }
1321            return iInstant.withLocalMillis(millis);
1322        }
1323        
1324        /**
1325         * Adds to this field, possibly wrapped, in a copy of this LocalTime.
1326         * A field wrapped operation only changes this field.
1327         * Thus 10:59 plusWrapField one minute goes to 10:00.
1328         * <p>
1329         * The LocalTime attached to this property is unchanged by this call.
1330         *
1331         * @param value the value to add to the field in the copy
1332         * @return a copy of the LocalTime with the field value changed
1333         * @throws IllegalArgumentException if the value isn't valid
1334         */

1335        public LocalTime addWrapFieldToCopy(int value) {
1336            return iInstant.withLocalMillis(iField.addWrapField(iInstant.getLocalMillis(), value));
1337        }
1338        
1339        //-----------------------------------------------------------------------
1340
/**
1341         * Sets this field in a copy of the LocalTime.
1342         * <p>
1343         * The LocalTime attached to this property is unchanged by this call.
1344         *
1345         * @param value the value to set the field in the copy to
1346         * @return a copy of the LocalTime with the field value changed
1347         * @throws IllegalArgumentException if the value isn't valid
1348         */

1349        public LocalTime setCopy(int value) {
1350            return iInstant.withLocalMillis(iField.set(iInstant.getLocalMillis(), value));
1351        }
1352        
1353        /**
1354         * Sets this field in a copy of the LocalTime to a parsed text value.
1355         * <p>
1356         * The LocalTime attached to this property is unchanged by this call.
1357         *
1358         * @param text the text value to set
1359         * @param locale optional locale to use for selecting a text symbol
1360         * @return a copy of the LocalTime with the field value changed
1361         * @throws IllegalArgumentException if the text value isn't valid
1362         */

1363        public LocalTime setCopy(String JavaDoc text, Locale JavaDoc locale) {
1364            return iInstant.withLocalMillis(iField.set(iInstant.getLocalMillis(), text, locale));
1365        }
1366        
1367        /**
1368         * Sets this field in a copy of the LocalTime to a parsed text value.
1369         * <p>
1370         * The LocalTime attached to this property is unchanged by this call.
1371         *
1372         * @param text the text value to set
1373         * @return a copy of the LocalTime with the field value changed
1374         * @throws IllegalArgumentException if the text value isn't valid
1375         */

1376        public LocalTime setCopy(String JavaDoc text) {
1377            return setCopy(text, null);
1378        }
1379        
1380        //-----------------------------------------------------------------------
1381
/**
1382         * Returns a new LocalTime with this field set to the maximum value
1383         * for this field.
1384         * <p>
1385         * The LocalTime attached to this property is unchanged by this call.
1386         *
1387         * @return a copy of the LocalTime with this field set to its maximum
1388         */

1389        public LocalTime withMaximumValue() {
1390            return setCopy(getMaximumValue());
1391        }
1392        
1393        /**
1394         * Returns a new LocalTime with this field set to the minimum value
1395         * for this field.
1396         * <p>
1397         * The LocalTime attached to this property is unchanged by this call.
1398         *
1399         * @return a copy of the LocalTime with this field set to its minimum
1400         */

1401        public LocalTime withMinimumValue() {
1402            return setCopy(getMinimumValue());
1403        }
1404        
1405        //-----------------------------------------------------------------------
1406
/**
1407         * Rounds to the lowest whole unit of this field on a copy of this
1408         * LocalTime.
1409         * <p>
1410         * For example, rounding floor on the hourOfDay field of a LocalTime
1411         * where the time is 10:30 would result in new LocalTime with the
1412         * time of 10:00.
1413         *
1414         * @return a copy of the LocalTime with the field value changed
1415         */

1416        public LocalTime roundFloorCopy() {
1417            return iInstant.withLocalMillis(iField.roundFloor(iInstant.getLocalMillis()));
1418        }
1419        
1420        /**
1421         * Rounds to the highest whole unit of this field on a copy of this
1422         * LocalTime.
1423         * <p>
1424         * For example, rounding floor on the hourOfDay field of a LocalTime
1425         * where the time is 10:30 would result in new LocalTime with the
1426         * time of 11:00.
1427         *
1428         * @return a copy of the LocalTime with the field value changed
1429         */

1430        public LocalTime roundCeilingCopy() {
1431            return iInstant.withLocalMillis(iField.roundCeiling(iInstant.getLocalMillis()));
1432        }
1433        
1434        /**
1435         * Rounds to the nearest whole unit of this field on a copy of this
1436         * LocalTime, favoring the floor if halfway.
1437         *
1438         * @return a copy of the LocalTime with the field value changed
1439         */

1440        public LocalTime roundHalfFloorCopy() {
1441            return iInstant.withLocalMillis(iField.roundHalfFloor(iInstant.getLocalMillis()));
1442        }
1443        
1444        /**
1445         * Rounds to the nearest whole unit of this field on a copy of this
1446         * LocalTime, favoring the ceiling if halfway.
1447         *
1448         * @return a copy of the LocalTime with the field value changed
1449         */

1450        public LocalTime roundHalfCeilingCopy() {
1451            return iInstant.withLocalMillis(iField.roundHalfCeiling(iInstant.getLocalMillis()));
1452        }
1453        
1454        /**
1455         * Rounds to the nearest whole unit of this field on a copy of this
1456         * LocalTime. If halfway, the ceiling is favored over the floor
1457         * only if it makes this field's value even.
1458         *
1459         * @return a copy of the LocalTime with the field value changed
1460         */

1461        public LocalTime roundHalfEvenCopy() {
1462            return iInstant.withLocalMillis(iField.roundHalfEven(iInstant.getLocalMillis()));
1463        }
1464    }
1465
1466}
1467
Popular Tags