Package javax.time

Examples of javax.time.Instant


     * @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.instant(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.dateTime(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 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.instant(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

     *
     * @return the current offset date, never null
     * @throws CalendricalException if the date-time cannot be created
     */
    public OffsetDate offsetDate() {
        Instant instant = instant();
        return OffsetDate.fromInstant(instant, getZone().getRules().getOffset(instant));
    }
View Full Code Here

     *
     * @return the current offset time, never null
     * @throws CalendricalException if the time cannot be created
     */
    public OffsetTime offsetTime() {
        Instant instant = instant();
        return OffsetTime.fromInstant(instant, getZone().getRules().getOffset(instant));
    }
View Full Code Here

     *
     * @return the current offset date-time, never null
     * @throws CalendricalException if the date-time cannot be created
     */
    public OffsetDateTime offsetDateTime() {
        Instant instant = instant();
        return OffsetDateTime.fromInstant(instant, getZone().getRules().getOffset(instant));
    }
View Full Code Here

     * @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.instant(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 the current offset date, never null
     * @throws CalendricalException if the date-time cannot be created
     */
    public OffsetDate offsetDate() {
        Instant instant = instant();
        return OffsetDate.fromInstant(instant, getZone().getRules().getOffset(instant));
    }
View Full Code Here

     *
     * @return the current offset time, never null
     * @throws CalendricalException if the time cannot be created
     */
    public OffsetTime offsetTime() {
        Instant instant = instant();
        return OffsetTime.fromInstant(instant, getZone().getRules().getOffset(instant));
    }
View Full Code Here

     *
     * @return the current offset date-time, never null
     * @throws CalendricalException if the date-time cannot be created
     */
    public OffsetDateTime offsetDateTime() {
        Instant instant = instant();
        return OffsetDateTime.fromInstant(instant, getZone().getRules().getOffset(instant));
    }
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.