Package javax.time

Examples of javax.time.Instant


     * @param instantProvider  the instant to convert, not null
     * @param offset  the zone offset, not null
     * @return the offset time, never null
     */
    public static OffsetTime fromInstant(InstantProvider instantProvider, ZoneOffset offset) {
        Instant instant = Instant.from(instantProvider);
        ISOChronology.checkNotNull(offset, "ZoneOffset must not be null");
       
        long secsOfDay = instant.getEpochSeconds() % ISOChronology.SECONDS_PER_DAY;
        secsOfDay = (secsOfDay + offset.getAmountSeconds()) % ISOChronology.SECONDS_PER_DAY;
        if (secsOfDay < 0) {
            secsOfDay += ISOChronology.SECONDS_PER_DAY;
        }
        LocalTime time = LocalTime.fromSecondOfDay(secsOfDay, instant.getNanoOfSecond());
        return new OffsetTime(time, offset);
    }
View Full Code Here


        return ScaleUtil.tai(tsi.getEpochSeconds(), tsi.getLeapSecond(), tsi.getNanoOfSecond());
    }

    /** {@inheritDoc} */
    public TimeScaleInstant toTimeScaleInstant(InstantProvider provider) {
        Instant t = Instant.from(provider);
        return TimeScaleInstant.seconds(this, t.getEpochSeconds(), t.getNanoOfSecond());
    }
View Full Code Here

        return ScaleUtil.tai(src.getEpochSeconds(), src.getNanoOfSecond());
    }

    /** {@inheritDoc} */
    public TimeScaleInstant toTimeScaleInstant(InstantProvider instantProvider) {
        Instant t = Instant.from(instantProvider);
        return TimeScaleInstant.seconds(this, t.getEpochSeconds(), t.getNanoOfSecond());
    }
View Full Code Here

        return tsi;
    }

    /** {@inheritDoc} */
    public TimeScaleInstant toTimeScaleInstant(InstantProvider provider) {
        Instant t = Instant.from(provider);
        return ScaleUtil.tai(t.getEpochSeconds(), t.getNanoOfSecond());
    }
View Full Code Here

     * @param offset  the zone offset, not null
     * @return the offset date, never null
     * @throws CalendarConversionException if the instant exceeds the supported date range
     */
    public static OffsetDate fromInstant(InstantProvider instantProvider, ZoneOffset offset) {
        Instant instant = Instant.from(instantProvider);
        ISOChronology.checkNotNull(offset, "ZoneOffset must not be null");
       
        long epochSecs = instant.getEpochSeconds() + offset.getAmountSeconds()// overflow caught later
        long yearZeroDays = (epochSecs / ISOChronology.SECONDS_PER_DAY) + ISOChronology.DAYS_0000_TO_1970;
        long secsOfDay = epochSecs % ISOChronology.SECONDS_PER_DAY;
        if (secsOfDay < 0) {
            yearZeroDays--;  // overflow caught later
        }
View Full Code Here

     * @param offset  the zone offset, not null
     * @return the offset date-time, never null
     * @throws CalendarConversionException if the instant exceeds the supported date range
     */
    public static OffsetDateTime fromInstant(InstantProvider instantProvider, ZoneOffset offset) {
        Instant instant = Instant.from(instantProvider);
        ISOChronology.checkNotNull(offset, "ZoneOffset must not be null");
       
        long epochSecs = instant.getEpochSeconds() + offset.getAmountSeconds()// overflow caught later
        long yearZeroDays = (epochSecs / ISOChronology.SECONDS_PER_DAY) + ISOChronology.DAYS_0000_TO_1970;
        int secsOfDay = (int) (epochSecs % ISOChronology.SECONDS_PER_DAY);
        if (secsOfDay < 0) {
            secsOfDay += ISOChronology.SECONDS_PER_DAY;
            yearZeroDays--;  // overflow caught later
        }
        LocalDate date = LocalDate.fromYearZeroDays(yearZeroDays);
        LocalTime time = LocalTime.fromSecondOfDay(secsOfDay, instant.getNanoOfSecond());
        LocalDateTime dateTime = LocalDateTime.from(date, time);
        return new OffsetDateTime(dateTime, offset);
    }
View Full Code Here

        /** {@inheritDoc} */
        @Override
        protected OffsetDateTime handleGap(
                TimeZone zone, ZoneRules rules, ZoneOffsetTransition discontinuity,
                LocalDateTime newDateTime, OffsetDateTime oldDateTime) {
            Instant instantBefore = discontinuity.getInstant().minusNanos(1);
            return OffsetDateTime.fromInstant(instantBefore, discontinuity.getOffsetBefore());
        }
View Full Code Here

     * @param zone  the time zone, not null
     * @return the zoned date-time, never null
     * @throws CalendricalException if the result exceeds the supported range
     */
    public static ZonedDateTime fromInstant(InstantProvider instantProvider, TimeZone zone) {
        Instant instant = Instant.from(instantProvider);
        ISOChronology.checkNotNull(zone, "TimeZone must not be null");
        ZoneRules rules = zone.getRules()// latest rules version
        OffsetDateTime offsetDT = OffsetDateTime.fromInstant(instant, rules.getOffset(instant));
        return new ZonedDateTime(offsetDT, zone);
    }
View Full Code Here

     */
    public ZonedDateTime plusDuration(int hours, int minutes, int seconds, long nanos) {
        if ((hours | minutes | seconds | nanos) == 0) {
            return this;
        }
        Instant instant = toInstant().plusSeconds(hours * 3600L + minutes * 60L + seconds).plusNanos(nanos);
        return fromInstant(instant, zone);
    }
View Full Code Here

     */
    public ZonedDateTime minusDuration(int hours, int minutes, int seconds, long nanos) {
        if ((hours | minutes | seconds | nanos) == 0) {
            return this;
        }
        Instant instant = toInstant().minusSeconds(hours * 3600L + minutes * 60L + seconds).minusNanos(nanos);
        return fromInstant(instant, zone);
    }
View Full Code Here

TOP

Related Classes of javax.time.Instant

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.