< prev index next >

src/java.base/share/classes/java/time/format/Parsed.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2019, 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


 382             if (resolverStyle == ResolverStyle.STRICT || (resolverStyle == ResolverStyle.SMART && ch != 0)) {
 383                 CLOCK_HOUR_OF_DAY.checkValidValue(ch);
 384             }
 385             updateCheckConflict(CLOCK_HOUR_OF_DAY, HOUR_OF_DAY, ch == 24 ? 0 : ch);
 386         }
 387         if (fieldValues.containsKey(CLOCK_HOUR_OF_AMPM)) {
 388             // lenient allows anything, smart allows 0-12, strict allows 1-12
 389             long ch = fieldValues.remove(CLOCK_HOUR_OF_AMPM);
 390             if (resolverStyle == ResolverStyle.STRICT || (resolverStyle == ResolverStyle.SMART && ch != 0)) {
 391                 CLOCK_HOUR_OF_AMPM.checkValidValue(ch);
 392             }
 393             updateCheckConflict(CLOCK_HOUR_OF_AMPM, HOUR_OF_AMPM, ch == 12 ? 0 : ch);
 394         }
 395         if (fieldValues.containsKey(AMPM_OF_DAY) && fieldValues.containsKey(HOUR_OF_AMPM)) {
 396             long ap = fieldValues.remove(AMPM_OF_DAY);
 397             long hap = fieldValues.remove(HOUR_OF_AMPM);
 398             if (resolverStyle == ResolverStyle.LENIENT) {
 399                 updateCheckConflict(AMPM_OF_DAY, HOUR_OF_DAY, Math.addExact(Math.multiplyExact(ap, 12), hap));
 400             } else {  // STRICT or SMART
 401                 AMPM_OF_DAY.checkValidValue(ap);
 402                 HOUR_OF_AMPM.checkValidValue(hap);
 403                 updateCheckConflict(AMPM_OF_DAY, HOUR_OF_DAY, ap * 12 + hap);
 404             }
 405         }
 406         if (fieldValues.containsKey(NANO_OF_DAY)) {
 407             long nod = fieldValues.remove(NANO_OF_DAY);
 408             if (resolverStyle != ResolverStyle.LENIENT) {
 409                 NANO_OF_DAY.checkValidValue(nod);
 410             }
 411             updateCheckConflict(NANO_OF_DAY, HOUR_OF_DAY, nod / 3600_000_000_000L);
 412             updateCheckConflict(NANO_OF_DAY, MINUTE_OF_HOUR, (nod / 60_000_000_000L) % 60);
 413             updateCheckConflict(NANO_OF_DAY, SECOND_OF_MINUTE, (nod / 1_000_000_000L) % 60);
 414             updateCheckConflict(NANO_OF_DAY, NANO_OF_SECOND, nod % 1_000_000_000L);
 415         }
 416         if (fieldValues.containsKey(MICRO_OF_DAY)) {
 417             long cod = fieldValues.remove(MICRO_OF_DAY);
 418             if (resolverStyle != ResolverStyle.LENIENT) {
 419                 MICRO_OF_DAY.checkValidValue(cod);
 420             }
 421             updateCheckConflict(MICRO_OF_DAY, SECOND_OF_DAY, cod / 1_000_000L);
 422             updateCheckConflict(MICRO_OF_DAY, MICRO_OF_SECOND, cod % 1_000_000L);


   1 /*
   2  * Copyright (c) 2012, 2015, 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


 382             if (resolverStyle == ResolverStyle.STRICT || (resolverStyle == ResolverStyle.SMART && ch != 0)) {
 383                 CLOCK_HOUR_OF_DAY.checkValidValue(ch);
 384             }
 385             updateCheckConflict(CLOCK_HOUR_OF_DAY, HOUR_OF_DAY, ch == 24 ? 0 : ch);
 386         }
 387         if (fieldValues.containsKey(CLOCK_HOUR_OF_AMPM)) {
 388             // lenient allows anything, smart allows 0-12, strict allows 1-12
 389             long ch = fieldValues.remove(CLOCK_HOUR_OF_AMPM);
 390             if (resolverStyle == ResolverStyle.STRICT || (resolverStyle == ResolverStyle.SMART && ch != 0)) {
 391                 CLOCK_HOUR_OF_AMPM.checkValidValue(ch);
 392             }
 393             updateCheckConflict(CLOCK_HOUR_OF_AMPM, HOUR_OF_AMPM, ch == 12 ? 0 : ch);
 394         }
 395         if (fieldValues.containsKey(AMPM_OF_DAY) && fieldValues.containsKey(HOUR_OF_AMPM)) {
 396             long ap = fieldValues.remove(AMPM_OF_DAY);
 397             long hap = fieldValues.remove(HOUR_OF_AMPM);
 398             if (resolverStyle == ResolverStyle.LENIENT) {
 399                 updateCheckConflict(AMPM_OF_DAY, HOUR_OF_DAY, Math.addExact(Math.multiplyExact(ap, 12), hap));
 400             } else {  // STRICT or SMART
 401                 AMPM_OF_DAY.checkValidValue(ap);
 402                 HOUR_OF_AMPM.checkValidValue(ap);
 403                 updateCheckConflict(AMPM_OF_DAY, HOUR_OF_DAY, ap * 12 + hap);
 404             }
 405         }
 406         if (fieldValues.containsKey(NANO_OF_DAY)) {
 407             long nod = fieldValues.remove(NANO_OF_DAY);
 408             if (resolverStyle != ResolverStyle.LENIENT) {
 409                 NANO_OF_DAY.checkValidValue(nod);
 410             }
 411             updateCheckConflict(NANO_OF_DAY, HOUR_OF_DAY, nod / 3600_000_000_000L);
 412             updateCheckConflict(NANO_OF_DAY, MINUTE_OF_HOUR, (nod / 60_000_000_000L) % 60);
 413             updateCheckConflict(NANO_OF_DAY, SECOND_OF_MINUTE, (nod / 1_000_000_000L) % 60);
 414             updateCheckConflict(NANO_OF_DAY, NANO_OF_SECOND, nod % 1_000_000_000L);
 415         }
 416         if (fieldValues.containsKey(MICRO_OF_DAY)) {
 417             long cod = fieldValues.remove(MICRO_OF_DAY);
 418             if (resolverStyle != ResolverStyle.LENIENT) {
 419                 MICRO_OF_DAY.checkValidValue(cod);
 420             }
 421             updateCheckConflict(MICRO_OF_DAY, SECOND_OF_DAY, cod / 1_000_000L);
 422             updateCheckConflict(MICRO_OF_DAY, MICRO_OF_SECOND, cod % 1_000_000L);


< prev index next >