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
577 // ensure fractional seconds available as ChronoField requires
578 // resolveTimeLenient() will have merged MICRO_OF_SECOND/MILLI_OF_SECOND to NANO_OF_SECOND
579 if (time == null &&
580 (fieldValues.containsKey(INSTANT_SECONDS) ||
581 fieldValues.containsKey(SECOND_OF_DAY) ||
582 fieldValues.containsKey(SECOND_OF_MINUTE))) {
583 if (fieldValues.containsKey(NANO_OF_SECOND)) {
584 long nos = fieldValues.get(NANO_OF_SECOND);
585 fieldValues.put(MICRO_OF_SECOND, nos / 1000);
586 fieldValues.put(MILLI_OF_SECOND, nos / 1000000);
587 } else {
588 fieldValues.put(NANO_OF_SECOND, 0L);
589 fieldValues.put(MICRO_OF_SECOND, 0L);
590 fieldValues.put(MILLI_OF_SECOND, 0L);
591 }
592 }
593 }
594
595 private void resolveInstant() {
596 // add instant seconds if we have date, time and zone
597 if (date != null && time != null) {
598 if (zone != null) {
599 long instant = date.atTime(time).atZone(zone).getLong(ChronoField.INSTANT_SECONDS);
600 fieldValues.put(INSTANT_SECONDS, instant);
601 } else {
602 Long offsetSecs = fieldValues.get(OFFSET_SECONDS);
603 if (offsetSecs != null) {
604 ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue());
605 long instant = date.atTime(time).atZone(offset).getLong(ChronoField.INSTANT_SECONDS);
606 fieldValues.put(INSTANT_SECONDS, instant);
607 }
608 }
609 }
610 }
611
612 private void updateCheckConflict(LocalTime timeToSet, Period periodToSet) {
613 if (time != null) {
614 if (time.equals(timeToSet) == false) {
615 throw new DateTimeException("Conflict found: Fields resolved to different times: " + time + " " + timeToSet);
616 }
617 if (excessDays.isZero() == false && periodToSet.isZero() == false && excessDays.equals(periodToSet) == false) {
618 throw new DateTimeException("Conflict found: Fields resolved to different excess periods: " + excessDays + " " + periodToSet);
619 } else {
620 excessDays = periodToSet;
621 }
622 } else {
623 time = timeToSet;
624 excessDays = periodToSet;
625 }
|
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
577 // ensure fractional seconds available as ChronoField requires
578 // resolveTimeLenient() will have merged MICRO_OF_SECOND/MILLI_OF_SECOND to NANO_OF_SECOND
579 if (time == null &&
580 (fieldValues.containsKey(INSTANT_SECONDS) ||
581 fieldValues.containsKey(SECOND_OF_DAY) ||
582 fieldValues.containsKey(SECOND_OF_MINUTE))) {
583 if (fieldValues.containsKey(NANO_OF_SECOND)) {
584 long nos = fieldValues.get(NANO_OF_SECOND);
585 fieldValues.put(MICRO_OF_SECOND, nos / 1000);
586 fieldValues.put(MILLI_OF_SECOND, nos / 1000000);
587 } else {
588 fieldValues.put(NANO_OF_SECOND, 0L);
589 fieldValues.put(MICRO_OF_SECOND, 0L);
590 fieldValues.put(MILLI_OF_SECOND, 0L);
591 }
592 }
593 }
594
595 private void resolveInstant() {
596 // add instant seconds if we have date, time and zone
597 // Offset (if present) will be given priority over the zone.
598 if (date != null && time != null) {
599 Long offsetSecs = fieldValues.get(OFFSET_SECONDS);
600 if (offsetSecs != null) {
601 ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue());
602 long instant = date.atTime(time).atZone(offset).toEpochSecond();
603 fieldValues.put(INSTANT_SECONDS, instant);
604 } else {
605 if (zone != null) {
606 long instant = date.atTime(time).atZone(zone).toEpochSecond();
607 fieldValues.put(INSTANT_SECONDS, instant);
608 }
609 }
610 }
611 }
612
613 private void updateCheckConflict(LocalTime timeToSet, Period periodToSet) {
614 if (time != null) {
615 if (time.equals(timeToSet) == false) {
616 throw new DateTimeException("Conflict found: Fields resolved to different times: " + time + " " + timeToSet);
617 }
618 if (excessDays.isZero() == false && periodToSet.isZero() == false && excessDays.equals(periodToSet) == false) {
619 throw new DateTimeException("Conflict found: Fields resolved to different excess periods: " + excessDays + " " + periodToSet);
620 } else {
621 excessDays = periodToSet;
622 }
623 } else {
624 time = timeToSet;
625 excessDays = periodToSet;
626 }
|