Package javax.time.calendar.format

Examples of javax.time.calendar.format.CalendricalParseException


        // check for zero and skip parse
        if (ZERO.equals(s)) {
            return Period.ZERO;
        }
        if (s.length() < 3 || s.charAt(0) != 'P') {
            throw new CalendricalParseException("Period could not be parsed: " + text, text, 0);
        }
        validateCharactersAndOrdering(s, text);
       
        // strip off the leading P
        ParseValues values = new ParseValues(text);
View Full Code Here


                switch(c) {
                    case 'Y': values.years = parseInt(values, value, baseIndex) ; break;
                    case 'M': values.months = parseInt(values, value, baseIndex) ; break;
                    case 'D': values.days = parseInt(values, value, baseIndex) ; break;
                    default:
                        throw new CalendricalParseException("Period could not be parsed, unrecognized letter '" +
                                c + ": " + values.text, values.text, baseIndex + values.index);
                }
                values.index++;
            }
        }
View Full Code Here

                    case 'H': values.hours = parseInt(values, value, baseIndex) ; break;
                    case 'M': values.minutes = parseInt(values, value, baseIndex) ; break;
                    case 'S': values.seconds = parseInt(values, value, baseIndex) ; break;
                    case 'N': values.nanos = parseNanos(values, value, baseIndex); break;
                    default:
                        throw new CalendricalParseException("Period could not be parsed, unrecognized letter '" +
                                c + "': " + values.text, values.text, baseIndex + values.index);
                }
                values.index++;
            }
        }
View Full Code Here

        }
    }

    private long parseNanos(ParseValues values, String s, int baseIndex) {
        if (s.length() > 9) {
            throw new CalendricalParseException("Period could not be parsed, nanosecond range exceeded: " +
                    values.text, values.text, baseIndex + values.index - s.length());
        }
        // pad to the right to create 10**9, then trim
        return Long.parseLong((s + "000000000").substring(0, 9));
    }
View Full Code Here

           
            // verify that the first character after the dot is a digit
            if (Character.isDigit(s.charAt(i))) {
                i++;
            } else {
                throw new CalendricalParseException("Period could not be parsed, invalid decimal number: " +
                        values.text, values.text, baseIndex + values.index);
            }
           
            // verify that only digits follow the decimal point followed by an S
            while (i < s.length()) {
                // || !Character.isDigit(s.charAt(i))
                char c = s.charAt(i);
                if (Character.isDigit(c) || c == 'S') {
                    i++;
                } else {
                    throw new CalendricalParseException("Period could not be parsed, invalid decimal number: " +
                            values.text, values.text, baseIndex + values.index);
                }
            }
            s = s.replace('S', 'N').replace('.', 'S');
            if (s.contains("-0S")) {
View Full Code Here

    private int parseInt(ParseValues values, String s, int baseIndex) {
        try {
            int value = Integer.parseInt(s);
            if (s.charAt(0) == '-' && value == 0) {
                throw new CalendricalParseException("Period could not be parsed, invalid number '" +
                        s + "': " + values.text, values.text, baseIndex + values.index - s.length());
            }
            return value;
        } catch (NumberFormatException ex) {
            throw new CalendricalParseException("Period could not be parsed, invalid number '" +
                    s + "': " + values.text, values.text, baseIndex + values.index - s.length());
        }
    }
View Full Code Here

        char[] chars = s.toCharArray();
        int tokenPos = 0;
        boolean lastLetter = false;
        for (int i = 0; i < chars.length; i++) {
            if (tokenPos >= TOKEN_SEQUENCE.length()) {
                throw new CalendricalParseException("Period could not be parsed, characters after last 'S': " + text, text, i);
            }
            char c = chars[i];
            if ((c < '0' || c > '9') && c != '-' && c != '.') {
                tokenPos = TOKEN_SEQUENCE.indexOf(c, tokenPos);
                if (tokenPos < 0) {
                    throw new CalendricalParseException("Period could not be parsed, invalid character '" + c + "': " + text, text, i);
                }
                tokenPos++;
                lastLetter = true;
            } else {
                lastLetter = false;
            }
        }
        if (lastLetter == false) {
            throw new CalendricalParseException("Period could not be parsed, invalid last character: " + text, text, s.length() - 1);
        }
    }
View Full Code Here

        if (len < 4 ||
                (text.charAt(0) != 'P' && text.charAt(0) != 'p') ||
                (text.charAt(1) != 'T' && text.charAt(1) != 't') ||
                (text.charAt(len - 1) != 'S' && text.charAt(len - 1) != 's') ||
                (len == 5 && text.charAt(2) == '-' && text.charAt(3) == '0')) {
            throw new CalendricalParseException("Duration could not be parsed: " + text, text, 0);
        }
        String numberText = text.substring(2, len - 1).replace(',', '.');
        int dot = numberText.indexOf('.');
        try {
            if (dot == -1) {
                // no decimal places
                return create(Long.parseLong(numberText), 0);
            }
            // decimal places
            boolean negative = false;
            if (numberText.charAt(0) == '-') {
                negative = true;
            }
            long secs = Long.parseLong(numberText.substring(0, dot));
            numberText = numberText.substring(dot + 1);
            len = numberText.length();
            if (len == 0 || len > 9 || numberText.charAt(0) == '-') {
                throw new CalendricalParseException("Duration could not be parsed: " + text, text, 2);
            }
            int nanos = Integer.parseInt(numberText);
            switch (len) {
                case 1:
                    nanos *= 100000000;
                    break;
                case 2:
                    nanos *= 10000000;
                    break;
                case 3:
                    nanos *= 1000000;
                    break;
                case 4:
                    nanos *= 100000;
                    break;
                case 5:
                    nanos *= 10000;
                    break;
                case 6:
                    nanos *= 1000;
                    break;
                case 7:
                    nanos *= 100;
                    break;
                case 8:
                    nanos *= 10;
                    break;
            }
            return negative ? seconds(secs, -nanos) : create(secs, nanos);
           
        } catch (ArithmeticException ex) {
            throw new CalendricalParseException("Duration could not be parsed: " + text, text, 2, ex);
        } catch (NumberFormatException ex) {
            throw new CalendricalParseException("Duration could not be parsed: " + text, text, 2, ex);
        }
    }
View Full Code Here

        // check for zero and skip parse
        if (ZERO.equals(s)) {
            return Period.ZERO;
        }
        if (s.length() < 3 || s.charAt(0) != 'P') {
            throw new CalendricalParseException("Period could not be parsed: " + text, text, 0);
        }
        validateCharactersAndOrdering(s, text);
       
        // strip off the leading P
        ParseValues values = new ParseValues(text);
View Full Code Here

                switch(c) {
                    case 'Y': values.years = parseInt(values, value, baseIndex) ; break;
                    case 'M': values.months = parseInt(values, value, baseIndex) ; break;
                    case 'D': values.days = parseInt(values, value, baseIndex) ; break;
                    default:
                        throw new CalendricalParseException("Period could not be parsed, unrecognized letter '" +
                                c + ": " + values.text, values.text, baseIndex + values.index);
                }
                values.index++;
            }
        }
View Full Code Here

TOP

Related Classes of javax.time.calendar.format.CalendricalParseException

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.