Examples of ZonedDateTime


Examples of java.time.ZonedDateTime

    }

    @Test
    public void testCalendarMapping() {
        Source source = new Source();
        ZonedDateTime dateTime = ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) );
        source.setForCalendarConversion(
                        dateTime );

        Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );

        assertThat( target.getForCalendarConversion() ).isNotNull();
        assertThat( target.getForCalendarConversion().getTimeZone() ).isEqualTo(
                        TimeZone.getTimeZone(
                                        "UTC" ) );
        assertThat( target.getForCalendarConversion().get( Calendar.YEAR ) ).isEqualTo( dateTime.getYear() );
        assertThat( target.getForCalendarConversion().get( Calendar.MONTH ) ).isEqualTo(
                        dateTime.getMonthValue() - 1 );
        assertThat( target.getForCalendarConversion().get( Calendar.DATE ) ).isEqualTo( dateTime.getDayOfMonth() );
        assertThat( target.getForCalendarConversion().get( Calendar.MINUTE ) ).isEqualTo( dateTime.getMinute() );
        assertThat( target.getForCalendarConversion().get( Calendar.HOUR ) ).isEqualTo( dateTime.getHour() );

        source = SourceTargetMapper.INSTANCE.targetToSource( target );

        assertThat( source.getForCalendarConversion() ).isEqualTo( dateTime );
    }
View Full Code Here

Examples of java.time.ZonedDateTime

    @Test
    public void testZonedDateTimeToDateMapping() {
        TimeZone.setDefault( TimeZone.getTimeZone( "UTC" ) );
        Source source = new Source();
        ZonedDateTime dateTime = ZonedDateTime.of( LocalDateTime.of( 2014, 1, 1, 0, 0 ), ZoneId.of( "UTC" ) );
        source.setForDateConversionWithZonedDateTime(
                        dateTime );
        Target target = SourceTargetMapper.INSTANCE.sourceToTargetDefaultMapping( source );

        assertThat( target.getForDateConversionWithZonedDateTime() ).isNotNull();

        Calendar instance = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) );
        instance.setTimeInMillis( target.getForDateConversionWithZonedDateTime().getTime() );

        assertThat( instance.get( Calendar.YEAR ) ).isEqualTo( dateTime.getYear() );
        assertThat( instance.get( Calendar.MONTH ) ).isEqualTo( dateTime.getMonthValue() - 1 );
        assertThat( instance.get( Calendar.DATE ) ).isEqualTo( dateTime.getDayOfMonth() );
        assertThat( instance.get( Calendar.MINUTE ) ).isEqualTo( dateTime.getMinute() );
        assertThat( instance.get( Calendar.HOUR ) ).isEqualTo( dateTime.getHour() );

        source = SourceTargetMapper.INSTANCE.targetToSource( target );

        assertThat( source.getForDateConversionWithZonedDateTime() ).isEqualTo( dateTime );
View Full Code Here

Examples of java.time.ZonedDateTime

            } else if (type == LocalTime.class) {
                LocalTime localDate = LocalTime.parse(text);
               
                return (T) localDate;
            } else if (type == ZonedDateTime.class) {
                ZonedDateTime zonedDateTime = ZonedDateTime.parse(text);

                return (T) zonedDateTime;
            } else if (type == OffsetDateTime.class) {
                OffsetDateTime offsetDateTime = OffsetDateTime.parse(text);
View Full Code Here

Examples of java.time.ZonedDateTime

  @Test
  public void createDateTimeFormatterWithTimeZone() throws Exception {
    factory.setPattern("yyyyMMddHHmmss Z");
    factory.setTimeZone(TEST_TIMEZONE);
    ZoneId dateTimeZone = TEST_TIMEZONE.toZoneId();
    ZonedDateTime dateTime = ZonedDateTime.of(2009, 10, 21, 12, 10, 00, 00, dateTimeZone);
    String offset = (TEST_TIMEZONE.equals(NEW_YORK) ? "-0400" : "+0200");
    assertThat(factory.createDateTimeFormatter().format(dateTime), is("20091021121000 " + offset));
  }
View Full Code Here

Examples of java.time.ZonedDateTime

    final LocalDateTime localdateTime = LocalDateTime.parse("2014-08-30T21:40:20");
    assertThat(localdateTime, is(LocalDateTime.of(2014, Month.AUGUST, 30, 21, 40, 20)));

    // Parse a date/time string with a time zone, in ISO-8601 format - this one is in UTC, as per the 'Z' zone indicator
    // Uses java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME.
    final ZonedDateTime zonedDateTime = ZonedDateTime.parse("2014-08-30T21:40:20Z");
    assertThat(zonedDateTime, is(ZonedDateTime.of(2014, Month.AUGUST.getValue(), 30, 21, 40, 20, 0, ZoneId.of("Z"))));
  }
View Full Code Here

Examples of java.time.ZonedDateTime

  @Test
  public void testZoneIdRegionAndFixedOffset() {
    // Create zoned date/time using ZoneId to parse an IANA area/region format TZ ID (use one that doesn't vary with
    // daylight saving to ensure this test-case is stable)
    final ZoneId zoneId = ZoneId.of("Africa/Addis_Ababa");
    final ZonedDateTime zonedDateTime = ZonedDateTime.of(2014, Month.AUGUST.getValue(), 30, 21, 40, 20, 0, zoneId);

    // Use ZoneOffset to return the fixed offset of a zoned date/time from UTC
    final ZoneOffset zoneOffset = zonedDateTime.getOffset();
    int threeHoursInSeconds = 3 * 60 * 60;
    assertThat(zoneOffset.getTotalSeconds(), is(threeHoursInSeconds));
  }
View Full Code Here

Examples of org.threeten.bp.ZonedDateTime

        assertEquals(test.isFixedOffset(), false);
    }

    public void test_London_preTimeZones() {
        ZoneRules test = europeLondon();
        ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
        Instant instant = old.toInstant();
        ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, -1, -15);
        assertEquals(test.getOffset(instant), offset);
        checkOffset(test, old.toLocalDateTime(), offset, 1);
        assertEquals(test.getStandardOffset(instant), offset);
        assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
        assertEquals(test.isDaylightSavings(instant), false);
    }
View Full Code Here

Examples of org.threeten.bp.ZonedDateTime

        assertEquals(trans.hashCode(), otherTrans.hashCode());
    }

    public void test_London_getStandardOffset() {
        ZoneRules test = europeLondon();
        ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
        while (zdt.getYear() < 2010) {
            Instant instant = zdt.toInstant();
            if (zdt.getYear() < 1848) {
                assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15));
            } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) {
                assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
            } else {
                assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
            }
            zdt = zdt.plusMonths(6);
        }
    }
View Full Code Here

Examples of org.threeten.bp.ZonedDateTime

        ZoneOffsetTransition last = trans.get(trans.size() - 1);
        assertEquals(test.previousTransition(last.getInstant().plusSeconds(1)), last);
        assertEquals(test.previousTransition(last.getInstant().plusNanos(1)), last);

        // Jan 1st of year between transitions and rules
        ZonedDateTime odt = ZonedDateTime.ofInstant(last.getInstant(), last.getOffsetAfter());
        odt = odt.withDayOfYear(1).plusYears(1).with(LocalTime.MIDNIGHT);
        assertEquals(test.previousTransition(odt.toInstant()), last);

        // later years
        for (int year = 1998; year < 2010; year++) {
            ZoneOffsetTransition a = rules.get(0).createTransition(year);
            ZoneOffsetTransition b = rules.get(1).createTransition(year);
View Full Code Here

Examples of org.threeten.bp.ZonedDateTime

        assertEquals(test.isFixedOffset(), false);
    }

    public void test_Paris_preTimeZones() {
        ZoneRules test = europeParis();
        ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
        Instant instant = old.toInstant();
        ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, 9, 21);
        assertEquals(test.getOffset(instant), offset);
        checkOffset(test, old.toLocalDateTime(), offset, 1);
        assertEquals(test.getStandardOffset(instant), offset);
        assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
        assertEquals(test.isDaylightSavings(instant), false);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.