Package javax.time

Examples of javax.time.CalendricalException


    private static void loadLeapSeconds() {
        // It would be better for LeapSeconds.txt to be a file within the JRE lib folder to enable
        // simple updating.
        InputStream in = LeapSeconds.class.getResourceAsStream("LeapSeconds.txt");
        if (in == null) {
            throw new CalendricalException("LeapSeconds.txt resource missing");
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
            ArrayList<Entry> entries = new ArrayList<Entry>();
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                line = line.trim();
                if (line.length() > 0 && line.charAt(0) != '#') {
                    int index = 0;
                    boolean possible = false;
                    if (line.charAt(0) == '?') {
                        possible = true;
                        index=1;
                    }
                    // parse a simple date from index
                    int x = line.indexOf('-', index);
                    int year = Integer.parseInt(line.substring(index, x));
                    index = x+1;
                    x = line.indexOf('-', index);
                    int month = Integer.parseInt(line.substring(index, x));
                    index = x+1;
                    x = line.indexOf(' ');
                    int day = Integer.parseInt(x < 0 ? line.substring(index) : line.substring(index, x));
                    if (possible)
                        nextPossibleLeap = ScaleUtil.epochSeconds(year, month, day);
                    else
                        entries.add(new Entry(year, month, day));
                }
            }
            Entry[] entryArray = new Entry[entries.size()];
            entries.toArray(entryArray);
            LeapSeconds.list = new UTC_TAI<Entry>(entryArray);
            in.close();
        } catch (IOException e) {
            throw new CalendricalException("Exception reading LeapSeconds.txt", e);
        }
    }
View Full Code Here


        }
        T result = interpret(merger, value);
        if (result != null) {
            return result;
        }
        throw new CalendricalException("Unable to complete merge as input contains an unknown type " +
                " for rule '" + getName() + "': " + value.getClass().getName());
    }
View Full Code Here

            handleGap(zone, rules, discontinuity, newDateTime, oldDateTime != null ? oldDateTime.toOffsetDateTime() : null) :
            handleOverlap(zone, rules, discontinuity, newDateTime, oldDateTime != null ? oldDateTime.toOffsetDateTime() : null);
       
        // validate the result
        if (result == null) {
            throw new CalendricalException(
                    "ZoneResolver implementation must not return null: " + getClass().getName());
        }
        if (zone.isValidFor(result) == false) {
            throw new CalendricalException(
                    "ZoneResolver implementation must return a valid date-time and offset for the zone: " + getClass().getName());
        }
        return result;
    }
View Full Code Here

        /** {@inheritDoc} */
        @Override
        protected OffsetDateTime handleGap(
                TimeZone zone, ZoneRules rules, ZoneOffsetTransition discontinuity,
                LocalDateTime newDateTime, OffsetDateTime oldDateTime) {
            throw new CalendricalException("Local time " + newDateTime + " does not exist in time zone " +
                    zone + " due to a gap in the local time-line");
        }
View Full Code Here

        /** {@inheritDoc} */
        @Override
        protected OffsetDateTime handleOverlap(
                TimeZone zone, ZoneRules rules, ZoneOffsetTransition discontinuity,
                LocalDateTime newDateTime, OffsetDateTime oldDateTime) {
            throw new CalendricalException("Local time " + newDateTime +
                    " has two matching offsets, " + discontinuity.getOffsetBefore() +
                    " and " + discontinuity.getOffsetAfter() + ", in time zone " + zone);
        }
View Full Code Here

     * @throws CalendricalException if the result exceeds the supported date range
     */
    public LocalDate plus(PeriodProvider periodProvider) {
        Period period = Period.from(periodProvider)// TODO: overflows long->int PeriodFields
        if ((period.getHours() | period.getMinutes() | period.getSeconds() | period.getNanos()) != 0) {
            throw new CalendricalException("Unable to add to date as the period contains time units");
        }
        // TODO: calculate in one go - 31st Mar plus P1M-1D should be 30th Apr
        return plusYears(period.getYears()).plusMonths(period.getMonths()).plusDays(period.getDays());
    }
View Full Code Here

        long mjDays = toModifiedJulianDays();

        try {
            mjDays = MathUtils.safeAdd(mjDays, days);
        } catch (ArithmeticException ae) {
            throw new CalendricalException(this + " + " + days + " days exceeds the current capacity");
        }

        return LocalDate.fromModifiedJulianDays(mjDays);
    }
View Full Code Here

     * @throws CalendricalException if the result exceeds the supported date range
     */
    public LocalDate minus(PeriodProvider periodProvider) {
        Period period = Period.from(periodProvider)// TODO: overflows long->int PeriodFields
        if ((period.getHours() | period.getMinutes() | period.getSeconds() | period.getNanos()) != 0) {
            throw new CalendricalException("Unable to subtract from date as the period contains time units");
        }
        // TODO: calculate in one go
        return minusYears(period.getYears()).minusMonths(period.getMonths()).minusDays(period.getDays());
    }
View Full Code Here

        long mjDays = toModifiedJulianDays();

        try {
            mjDays = MathUtils.safeSubtract(mjDays, days);
        } catch (ArithmeticException ae) {
            throw new CalendricalException(this + " - " + days + " days exceeds the current capacity");
        }

        return LocalDate.fromModifiedJulianDays(mjDays);
    }
View Full Code Here

                (overflow.getDays() != 0 && additionalOverflow.getDays() != 0) ||
                (overflow.getHours() != 0 && additionalOverflow.getHours() != 0) ||
                (overflow.getMinutes() != 0 && additionalOverflow.getMinutes() != 0) ||
                (overflow.getSeconds() != 0 && additionalOverflow.getSeconds() != 0) ||
                (overflow.getNanos() != 0 && additionalOverflow.getNanos() != 0)) {
            throw new CalendricalException("Unable to complete merge as input contains two conflicting out of range values");
        }
        overflow = overflow.plus(additionalOverflow);
    }
View Full Code Here

TOP

Related Classes of javax.time.CalendricalException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.