Package javax.time

Examples of javax.time.CalendricalException


     * @return the local time, never null
     * @throws CalendricalException if the nanos of day value is invalid
     */
    public static LocalTime fromNanoOfDay(long nanoOfDay) {
        if (nanoOfDay < 0) {
            throw new CalendricalException("Cannot create LocalTime from nanos of day as value " +
                    nanoOfDay + " must not be negative");
        }
        if (nanoOfDay >= NANOS_PER_DAY) {
            throw new CalendricalException("Cannot create LocalTime from nanos of day as value " +
                    nanoOfDay + " must be less than " + NANOS_PER_DAY);
        }
        int hours = (int) (nanoOfDay / NANOS_PER_HOUR);
        nanoOfDay -= hours * NANOS_PER_HOUR;
        int minutes = (int) (nanoOfDay / NANOS_PER_MINUTE);
View Full Code Here


     * @throws CalendricalException if the provider contains date period units
     */
    public LocalTime plus(PeriodProvider periodProvider) {
        Period period = Period.from(periodProvider)// TODO: overflows long->int PeriodFields
        if ((period.getYears() | period.getMonths() | period.getDays()) != 0) {
            throw new CalendricalException("Unable to add to date as the period contains date units");
        }
        long totNanos = period.getNanos() % NANOS_PER_DAY +                    //   max  86400000000000
                (period.getSeconds() % SECONDS_PER_DAY) * NANOS_PER_SECOND +   //   max  86400000000000
                (period.getMinutes() % MINUTES_PER_DAY) * NANOS_PER_MINUTE +   //   max  86400000000000
                (period.getHours() % HOURS_PER_DAY) * NANOS_PER_HOUR;          //   max  86400000000000
View Full Code Here

     * @throws CalendricalException if the provider contains date period units
     */
    public LocalTime minus(PeriodProvider periodProvider) {
        Period period = Period.from(periodProvider)// TODO: overflows long->int PeriodFields
        if ((period.getYears() | period.getMonths() | period.getDays()) != 0) {
            throw new CalendricalException("Unable to add to date as the period contains date units");
        }
        long totNanos = period.getNanos() % NANOS_PER_DAY +                    //   max  86400000000000
                (period.getSeconds() % SECONDS_PER_DAY) * NANOS_PER_SECOND +   //   max  86400000000000
                (period.getMinutes() % MINUTES_PER_DAY) * NANOS_PER_MINUTE +   //   max  86400000000000
                (period.getHours() % HOURS_PER_DAY) * NANOS_PER_HOUR;          //   max  86400000000000
View Full Code Here

     * @throws CalendricalException if the result exceeds the supported year range
     */
    static int addYears(int year, int years) {
        int result = year + years;
        if (((year ^ result) < 0 && (year ^ years) >= 0) || yearRule().isValidValue(result) == false) {
            throw new CalendricalException("Addition exceeds the supported year range: " + year + " + " + years);
        }
        return result;
    }
View Full Code Here

     * @throws CalendricalException if the result exceeds the supported year range
     */
    static int subtractYears(int year, int years) {
        int result = year - years;
        if (((year ^ result) < 0 && (year ^ years) < 0) || yearRule().isValidValue(result) == false) {
            throw new CalendricalException("Subtraction exceeds the supported year range: " + year + " - " + years);
        }
        return result;
    }
View Full Code Here

        ISOChronology.checkNotNull(zoneID, "Time zone ID must not be null");
        if (zoneID.equals("UTC") || zoneID.equals("GMT")) {
            return UTC;
           
        } else if (zoneID.equals("UTCZ") || zoneID.equals("GMTZ")) {
            throw new CalendricalException("Invalid time zone ID: " + zoneID);
           
        } else if (zoneID.startsWith("UTC") || zoneID.startsWith("GMT")) {  // not sure about GMT
            try {
                return of(ZoneOffset.of(zoneID.substring(3)));
            } catch (IllegalArgumentException ex) {
                throw new CalendricalException("Invalid time zone ID: " + ex.toString(), ex);
            }
           
        } else {
            int pos = zoneID.indexOf(':');
            ZoneRulesGroup group;
View Full Code Here

     */
    public TimeZone withVersion(String versionID) {
        ISOChronology.checkNotNull(versionID, "Version ID must not be null");
        if (isFixed()) {
            if (versionID.length() > 0) {
                throw new CalendricalException("Fixed time zone does not provide versions");
            }
            return this;
        }
        ZoneRules rules = getGroup().getRules(regionID, versionID)// validates IDs
        if (versionID.equals(this.versionID)) {
View Full Code Here

     */
    public TimeZone withLatestVersionValidFor(OffsetDateTime dateTime) {
        ISOChronology.checkNotNull(dateTime, "OffsetDateTime must not be null");
        if (isFixed()) {
            if (getRules().getOffset(dateTime).equals(dateTime.getOffset()) == false) {
                throw new CalendricalException("Fixed time zone " + getID() + " is invalid for date-time " + dateTime);
            }
            return this;
        }
        return withVersion(getGroup().getLatestVersionIDValidFor(regionID, dateTime));
    }
View Full Code Here

     * @throws CalendricalException if the time zone is fixed
     * @throws CalendricalException if the group ID cannot be found
     */
    public ZoneRulesGroup getGroup() {
        if (isFixed()) {
            throw new CalendricalException("Fixed time zone is not provided by a group");
        }
        return ZoneRulesGroup.getGroup(groupID);
    }
View Full Code Here

     */
    public ZoneRules getRulesValidFor(OffsetDateTime dateTime) {
        ISOChronology.checkNotNull(dateTime, "OffsetDateTime must not be null");
        if (isFixed()) {
            if (getRules().getOffset(dateTime).equals(dateTime.getOffset()) == false) {
                throw new CalendricalException("Fixed time zone " + getID() + " is invalid for date-time " + dateTime);
            }
            return ZoneRules.fixed(getRules().getOffset(dateTime));
        }
        ZoneRulesGroup group = ZoneRulesGroup.getGroup(groupID);
        return group.getRulesValidFor(regionID, versionID, dateTime);
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.