Package java.time

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


    @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

            } 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

  @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

    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

  @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

        adapter = new ZonedDateTimeAdapter();
    }

    @Test
    public void unmarshalProducesCorrectLocalDateTimeObject() throws Exception {
        final ZonedDateTime unmarshaled = adapter.unmarshal(DATE_AS_STRING);

        assertEquals(unmarshaled.format(getDateTimeFormatter()), DATE_AS_STRING);
    }
View Full Code Here

TOP

Related Classes of java.time.ZonedDateTime

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.