List of usage examples for java.time ZonedDateTime toInstant
default Instant toInstant()
From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java
@Test public void movingAMessageIsNotSupported() throws Exception { String newMailboxName = "heartFolder"; jmapServer.serverProbe().createMailbox("#private", username, newMailboxName); Mailbox heartFolder = jmapServer.serverProbe().getMailbox("#private", username, newMailboxName); String heartFolderId = heartFolder.getMailboxId().serialize(); ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z"); jmapServer.serverProbe().appendMessage(username, new MailboxPath("#private", username, "inbox"), new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags()); String messageToMoveId = "user|inbox|1"; String requestBody = "[" + " [" + " \"setMessages\"," + " {" + " \"update\": { \"" + messageToMoveId + "\" : {" + " \"mailboxIds\": [\"" + heartFolderId + "\"]" + " }}" + " }," + " \"#0\"" + " ]" + "]"; given().header("Authorization", this.accessToken.serialize()).body(requestBody).when().post("/jmap").then() .statusCode(200).body(NAME, equalTo("messagesSet")).body(NOT_UPDATED, hasKey(messageToMoveId)) .body(NOT_UPDATED + "[\"" + messageToMoveId + "\"].type", equalTo("invalidProperties")) .body(NOT_UPDATED + "[\"" + messageToMoveId + "\"].properties[0]", equalTo("mailboxIds")) .body(NOT_UPDATED + "[\"" + messageToMoveId + "\"].description", equalTo("mailboxIds: moving a message is not supported " + "(through reference chain: org.apache.james.jmap.model.Builder[\"mailboxIds\"])")) .body(ARGUMENTS + ".updated", hasSize(0)); }
From source file:org.apache.james.jmap.utils.FilterToSearchQueryTest.java
@Test public void filterConditionShouldMapWhenAfter() { ZonedDateTime after = ZonedDateTime.now(); SearchQuery expectedSearchQuery = new SearchQuery(); expectedSearchQuery/* www. j a va2 s . com*/ .andCriteria(SearchQuery.internalDateAfter(Date.from(after.toInstant()), DateResolution.Second)); SearchQuery searchQuery = new FilterToSearchQuery().convert(FilterCondition.builder().after(after).build()); assertThat(searchQuery).isEqualTo(expectedSearchQuery); }
From source file:org.apache.james.jmap.utils.FilterToSearchQueryTest.java
@Test public void filterConditionShouldMapWhenBefore() { ZonedDateTime before = ZonedDateTime.now(); SearchQuery expectedSearchQuery = new SearchQuery(); expectedSearchQuery/* ww w .j a v a 2 s.c om*/ .andCriteria(SearchQuery.internalDateBefore(Date.from(before.toInstant()), DateResolution.Second)); SearchQuery searchQuery = new FilterToSearchQuery() .convert(FilterCondition.builder().before(before).build()); assertThat(searchQuery).isEqualTo(expectedSearchQuery); }
From source file:org.apache.metron.parsers.snort.BasicSnortParser.java
/** * Parses Snort's default date-time representation and * converts to epoch./*from w ww.j ava 2s . com*/ * @param snortDatetime Snort's default date-time as String '01/27-16:01:04.877970' * @return epoch time * @throws java.text.ParseException */ private long toEpoch(String snortDatetime) throws ParseException { ZonedDateTime zonedDateTime = ZonedDateTime.parse(snortDatetime.trim(), dateTimeFormatter); return zonedDateTime.toInstant().toEpochMilli(); }
From source file:org.apache.servicecomb.demo.springmvc.tests.SpringMvcIntegrationTestBase.java
@Test public void ableToPostDate() throws Exception { ZonedDateTime date = ZonedDateTime.now().truncatedTo(SECONDS); MultiValueMap<String, String> body = new LinkedMultiValueMap<>(); body.add("date", RestObjectMapperFactory.getRestObjectMapper().convertToString(Date.from(date.toInstant()))); HttpHeaders headers = new HttpHeaders(); headers.add(CONTENT_TYPE, APPLICATION_FORM_URLENCODED_VALUE); int seconds = 1; Date result = restTemplate.postForObject(codeFirstUrl + "addDate?seconds={seconds}", new HttpEntity<>(body, headers), Date.class, seconds); assertThat(result, is(Date.from(date.plusSeconds(seconds).toInstant()))); ListenableFuture<ResponseEntity<Date>> listenableFuture = asyncRestTemplate.postForEntity( codeFirstUrl + "addDate?seconds={seconds}", new HttpEntity<>(body, headers), Date.class, seconds); ResponseEntity<Date> dateResponseEntity = listenableFuture.get(); assertThat(dateResponseEntity.getBody(), is(Date.from(date.plusSeconds(seconds).toInstant()))); }
From source file:org.codice.alliance.transformer.nitf.NitfAttributeConverters.java
@Nullable public static Date nitfDate(@Nullable DateTime nitfDateTime) { if (nitfDateTime == null || nitfDateTime.getZonedDateTime() == null) { return null; }//from ww w .j ava2 s. c o m ZonedDateTime zonedDateTime = nitfDateTime.getZonedDateTime(); Instant instant = zonedDateTime.toInstant(); return Date.from(instant); }
From source file:org.openhab.binding.ntp.test.NtpOSGiTest.java
@Test public void testDateTimeChannelTimeZoneUpdate() { Configuration configuration = new Configuration(); configuration.put(NtpBindingConstants.PROPERTY_TIMEZONE, TEST_TIME_ZONE_ID); initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null); String testItemState = getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME).toString(); assertFormat(testItemState, DateTimeType.DATE_PATTERN_WITH_TZ_AND_MS); ZonedDateTime timeZoneFromItemRegistry = ((DateTimeType) getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME)) .getZonedDateTime();/* www . j a v a 2 s.co m*/ ZoneOffset expectedOffset = ZoneId.of(TEST_TIME_ZONE_ID).getRules() .getOffset(timeZoneFromItemRegistry.toInstant()); assertEquals(expectedOffset, timeZoneFromItemRegistry.getOffset()); }
From source file:org.openhab.binding.ntp.test.NtpOSGiTest.java
@Test public void testDateTimeChannelCalendarTimeZoneUpdate() { Configuration configuration = new Configuration(); configuration.put(NtpBindingConstants.PROPERTY_TIMEZONE, TEST_TIME_ZONE_ID); initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null); ZonedDateTime timeZoneIdFromItemRegistry = ((DateTimeType) getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME)) .getZonedDateTime();/*from w w w .ja va2 s . c om*/ ZoneOffset expectedOffset = ZoneId.of(TEST_TIME_ZONE_ID).getRules() .getOffset(timeZoneIdFromItemRegistry.toInstant()); assertEquals(expectedOffset, timeZoneIdFromItemRegistry.getOffset()); }
From source file:org.openhab.binding.ntp.test.NtpOSGiTest.java
@Test @Ignore("https://github.com/eclipse/smarthome/issues/5224") public void testDateTimeChannelCalendarDefaultTimeZoneUpdate() { Configuration configuration = new Configuration(); // Initialize with configuration with no time zone property set. initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null); ZonedDateTime timeZoneIdFromItemRegistry = ((DateTimeType) getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME)) .getZonedDateTime();/*from w w w . j av a 2 s .com*/ ZoneOffset expectedOffset = ZoneId.systemDefault().getRules() .getOffset(timeZoneIdFromItemRegistry.toInstant()); assertEquals(expectedOffset, timeZoneIdFromItemRegistry.getOffset()); }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override public AssignmentConstants.Status getAssignmentCannonicalStatus(String assignmentId) throws IdUnusedException, PermissionException { Assignment assignment = getAssignment(assignmentId); ZonedDateTime currentTime = ZonedDateTime.now(); // TODO these status's should be an enum and translation should occur in tool if (assignment.getDraft()) { return AssignmentConstants.Status.DRAFT; } else if (assignment.getOpenDate().isAfter(currentTime.toInstant())) { return AssignmentConstants.Status.NOT_OPEN; } else if (assignment.getDueDate().isAfter(currentTime.toInstant())) { return AssignmentConstants.Status.OPEN; } else if ((assignment.getCloseDate() != null) && (assignment.getCloseDate().isBefore(currentTime.toInstant()))) { return AssignmentConstants.Status.CLOSED; } else {// ww w .ja va 2 s . co m return AssignmentConstants.Status.DUE; } }