Java Code Examples for java.time.ZonedDateTime#parse()

The following examples show how to use java.time.ZonedDateTime#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CartDiscountUpdateActionUtilsTest.java    From commercetools-sync-java with Apache License 2.0 6 votes vote down vote up
@Test
void buildSetValidDatesUpdateAction_WithOnlyNullNewDates_ShouldBuildUpdateAction() {
    final ZonedDateTime validFrom = ZonedDateTime.parse("2019-04-30T22:00:00.000Z");
    final ZonedDateTime validUntil = ZonedDateTime.parse("2019-05-30T22:00:00.000Z");
    final CartDiscount oldCartDiscount = mock(CartDiscount.class);
    when(oldCartDiscount.getValidUntil()).thenReturn(validFrom);
    when(oldCartDiscount.getValidFrom()).thenReturn(validUntil);

    final CartDiscountDraft newCartDiscountDraft = mock(CartDiscountDraft.class);
    when(newCartDiscountDraft.getValidUntil()).thenReturn(null);
    when(newCartDiscountDraft.getValidFrom()).thenReturn(null);

    final Optional<UpdateAction<CartDiscount>> setValidUntilUpdateAction =
            buildSetValidDatesUpdateAction(oldCartDiscount, newCartDiscountDraft);

    assertThat(setValidUntilUpdateAction).contains(SetValidFromAndUntil.of(null, null));
}
 
Example 2
Source File: JSONCommunicatorTest.java    From Java-OCA-OCPP with MIT License 6 votes vote down vote up
@Test
public void unpackPayload_bootNotificationCallResultPayload_returnBootNotificationConfirmation()
    throws Exception {
  // Given
  String currentTime = "2016-04-28T07:16:11.988Z";
  ZonedDateTime someDate = ZonedDateTime.parse("2016-04-28T07:16:11.988Z");

  int interval = 300;
  RegistrationStatus status = RegistrationStatus.Accepted;
  String payload = "{\"currentTime\": \"%s\", \"interval\": %d, \"status\": \"%s\"}";
  Class<?> type = BootNotificationConfirmation.class;

  // When
  Object result =
      communicator.unpackPayload(String.format(payload, currentTime, interval, status), type);

  // Then
  assertThat(result, instanceOf(type));
  assertThat(((BootNotificationConfirmation) result).getCurrentTime().compareTo(someDate), is(0));
  assertThat(((BootNotificationConfirmation) result).getInterval(), is(interval));
  assertThat(((BootNotificationConfirmation) result).getStatus(), is(status));
}
 
Example 3
Source File: NewsAttributesTest.java    From crawler-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void testNewsAttributesAsMap() {
    ZonedDateTime dt = ZonedDateTime.parse("2008-11-23T00:00:00+00:00");
    NewsAttributes attributes = new NewsAttributes("The Example Times", "en", dt, "Companies A, B in Merger Talks");
    attributes.setKeywords(new String[] { "business", "merger", "acquisition", "A", "B" });
    attributes.setGenres(new NewsAttributes.NewsGenre[] { NewsAttributes.NewsGenre.PressRelease, NewsAttributes.NewsGenre.Blog });
    attributes.setStockTickers(new String[] { "NASDAQ:A", "NASDAQ:B" });
    Map<String, String[]> map = attributes.asMap();

    assertEquals(attributes.getName(), map.get(NewsAttributes.NAME)[0]);
    assertEquals(attributes.getTitle(), map.get(NewsAttributes.TITLE)[0]);
    assertEquals(attributes.getLanguage(), map.get(NewsAttributes.LANGUAGE)[0]);
    assertEquals(attributes.getPublicationDateTime().toString(), map.get(NewsAttributes.PUBLICATION_DATE)[0]);
    assertArrayEquals(attributes.getKeywords(), map.get(NewsAttributes.KEYWORDS));
    assertArrayEquals(attributes.getStockTickers(), map.get(NewsAttributes.STOCK_TICKERS));
    assertArrayEquals(Arrays.stream(attributes.getGenres())
            .map(NewsAttributes.NewsGenre::toString)
            .toArray(String[]::new), map.get(NewsAttributes.GENRES));
}
 
Example 4
Source File: StringToZonedDateTimeConverter.java    From spring-cloud-gateway with Apache License 2.0 6 votes vote down vote up
@Override
public ZonedDateTime convert(String source) {
	ZonedDateTime dateTime;
	try {
		long epoch = Long.parseLong(source);

		dateTime = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.ofTotalSeconds(0))
				.toZonedDateTime();
	}
	catch (NumberFormatException e) {
		// try ZonedDateTime instead
		dateTime = ZonedDateTime.parse(source);
	}

	return dateTime;
}
 
Example 5
Source File: TCKZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="sampleToString")
public void test_parse(int y, int month, int d, int h, int m, int s, int n, String zoneId, String text) {
    ZonedDateTime t = ZonedDateTime.parse(text);
    assertEquals(t.getYear(), y);
    assertEquals(t.getMonth().getValue(), month);
    assertEquals(t.getDayOfMonth(), d);
    assertEquals(t.getHour(), h);
    assertEquals(t.getMinute(), m);
    assertEquals(t.getSecond(), s);
    assertEquals(t.getNano(), n);
    assertEquals(t.getZone().getId(), zoneId);
}
 
Example 6
Source File: ExecutionTimeQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #66: Incorrect Day Of Week processing for Quartz when Month or Year isn't '*'.
 */
@Test
public void testNextExecutionRightDoWForFixedMonth() {
    //cron format: s,m,H,DoM,M,DoW,Y
    final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("0 * * ? 5 1 *"));
    final ZonedDateTime scanTime = ZonedDateTime.parse("2016-03-06T20:17:28.000-03:00");
    final Optional<ZonedDateTime> nextExecution = executionTime.nextExecution(scanTime);
    if (nextExecution.isPresent()) {
        final ZonedDateTime nextTime = nextExecution.get();
        assertNotNull(nextTime);
        assertEquals(DayOfWeek.SUNDAY, nextTime.getDayOfWeek());
    } else {
        fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
Example 7
Source File: TimeUtilTest.java    From styx with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSubtractOffsetWithWeek() {
  String offset = "P2W";
  ZonedDateTime time = ZonedDateTime.parse("2017-02-05T08:07:11.22Z");
  ZonedDateTime offsetTime = subtractOffset(time, offset);

  assertThat(offsetTime, is(ZonedDateTime.parse("2017-01-22T08:07:11.22Z")));
}
 
Example 8
Source File: DataMigrator.java    From alf.io with GNU General Public License v3.0 5 votes vote down vote up
@Autowired
public DataMigrator(EventMigrationRepository eventMigrationRepository,
                    EventRepository eventRepository,
                    TicketCategoryRepository ticketCategoryRepository,
                    @Value("${alfio.version}") String currentVersion,
                    @Value("${alfio.build-ts}") String buildTimestamp,
                    PlatformTransactionManager transactionManager,
                    ConfigurationRepository configurationRepository,
                    NamedParameterJdbcTemplate jdbc,
                    TicketReservationManager ticketReservationManager,
                    TicketSearchRepository ticketSearchRepository,
                    PromoCodeDiscountRepository promoCodeDiscountRepository,
                    AdditionalServiceItemRepository additionalServiceItemRepository,
                    AdditionalServiceRepository additionalServiceRepository,
                    BillingDocumentManager billingDocumentManager) {
    this.eventMigrationRepository = eventMigrationRepository;
    this.eventRepository = eventRepository;
    this.ticketCategoryRepository = ticketCategoryRepository;
    this.configurationRepository = configurationRepository;
    this.jdbc = jdbc;
    this.currentVersion = parseVersion(currentVersion);
    this.currentVersionAsString = currentVersion;
    this.buildTimestamp = ZonedDateTime.parse(buildTimestamp);
    this.transactionTemplate = new TransactionTemplate(transactionManager, new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW));
    this.ticketReservationManager = ticketReservationManager;
    this.ticketSearchRepository = ticketSearchRepository;
    this.promoCodeDiscountRepository = promoCodeDiscountRepository;
    this.additionalServiceItemRepository = additionalServiceItemRepository;
    this.additionalServiceRepository = additionalServiceRepository;
    this.billingDocumentManager = billingDocumentManager;
}
 
Example 9
Source File: CronParserQuartzIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #78: ExecutionTime.forCron fails on intervals
 */
@Test
public void testIntervalSeconds() {
    final ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("0/20 * * * * ?"));
    final ZonedDateTime now = ZonedDateTime.parse("2005-08-09T18:32:42Z");
    final Optional<ZonedDateTime> lastExecution = executionTime.lastExecution(now);
    if (lastExecution.isPresent()) {
        final ZonedDateTime assertDate = ZonedDateTime.parse("2005-08-09T18:32:40Z");
        assertEquals(assertDate, lastExecution.get());
    } else {
        fail(LAST_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
Example 10
Source File: ZonedDateTimeConverterTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
@Test
public void convertToEntityAttribute_convertsCorrectly() {
  ZonedDateTime zonedDateTime = ZonedDateTime.parse("2019-09-01T01:01:01Z");
  Instant instant = zonedDateTime.toInstant();
  assertThat(converter.convertToEntityAttribute(Timestamp.from(instant)))
      .isEqualTo(zonedDateTime);
}
 
Example 11
Source File: Issue228Test.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
@Test
public void testFirstMondayOfTheMonthNextExecution() {
    final CronParser parser = new CronParser(cronDefinition);

    // This is 9am on a day between the 1st and 7th which is a Monday (in this case it should be Oct 2
    final Cron myCron = parser.parse("0 9 1-7 * 1");
    final ZonedDateTime time = ZonedDateTime.parse(TEST_DATE);
    assertEquals(ZonedDateTime.parse("2017-10-02T09:00-07:00"), getNextExecutionTime(myCron, time));
}
 
Example 12
Source File: ExecutionTimeUnixIntegrationTest.java    From cron-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Issue #41: for everything other than a dayOfWeek value == 1, nextExecution and lastExecution do not return correct results.
 */
@Test
public void testEveryTuesdayAtThirdHourOfDayNextExecution() {
    final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX);
    final CronParser parser = new CronParser(cronDefinition);
    final Cron myCron = parser.parse("0 3 * * 3");
    final ZonedDateTime time = ZonedDateTime.parse("2015-09-17T00:00:00.000-07:00");
    final Optional<ZonedDateTime> nextExecution = ExecutionTime.forCron(myCron).nextExecution(time);
    if (nextExecution.isPresent()) {
        assertEquals(ZonedDateTime.parse("2015-09-23T03:00:00.000-07:00"), nextExecution.get());
    } else {
        fail(NEXT_EXECUTION_NOT_PRESENT_ERROR);
    }
}
 
Example 13
Source File: TCKZonedDateTime.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    ZonedDateTime.parse((String) null, f);
}
 
Example 14
Source File: DateTimeUtilsTest.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Test
public void testSuccess_toJodaDateTime_fromStringZulu() {
  ZonedDateTime zonedDateTime = ZonedDateTime.parse("2015-10-13T11:22:33.168Z");
  DateTime dateTime = toJodaDateTime(zonedDateTime);
  assertThat(dateTime.toString()).isEqualTo("2015-10-13T11:22:33.168Z");
}
 
Example 15
Source File: ImapDateTimeFormatterTest.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Test
void yearShouldBeParsedWhenFourDigits() {
    ZonedDateTime dateTime = ZonedDateTime.parse("Wed, 28 Jun 2017 04:35:11 -0700", ImapDateTimeFormatter.rfc5322());
    assertThat(dateTime.getYear()).isEqualTo(2017);
}
 
Example 16
Source File: TCKZonedDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullFormatter() {
    ZonedDateTime.parse("ANY", null);
}
 
Example 17
Source File: TCKZonedDateTime.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void factory_parse_formatter() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s VV");
    ZonedDateTime test = ZonedDateTime.parse("2010 12 3 11 30 0 Europe/London", f);
    assertEquals(test, ZonedDateTime.of(LocalDateTime.of(2010, 12, 3, 11, 30), ZoneId.of("Europe/London")));
}
 
Example 18
Source File: PropertyMapper.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
@Override
public Object map( Composite composite, Type type, String value )
{
    return ZonedDateTime.parse( value.trim() );
}
 
Example 19
Source File: TCKZonedDateTime.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    ZonedDateTime.parse((String) null, f);
}
 
Example 20
Source File: TCKZonedDateTime.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void factory_parse_formatter_nullText() {
    DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d H m s");
    ZonedDateTime.parse((String) null, f);
}