List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:com.orange.clara.cloud.servicedbdumper.task.job.JobFactoryTest.java
@Test public void when_purge_errored_jobs_and_jobs_in_error_exist_it_should_delete_job_which_pass_expiration() { Job jobNotExpired = new Job(); jobNotExpired.setUpdatedAt(new Date()); Date date = new Date(); LocalDateTime localDateTime = LocalDateTime.from(date.toInstant().atZone(ZoneId.systemDefault())) .minusDays(jobErroredDeleteExpirationDays + 1); Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant(); Job jobExpired = new Job(); jobExpired.setUpdatedAt(Date.from(instant)); when(jobRepo.findByJobEventOrderByUpdatedAtDesc(anyObject())) .thenReturn(Arrays.asList(jobNotExpired, jobExpired)); jobFactory.purgeErroredJobs();/*from w w w . j a v a2 s.co m*/ verify(jobRepo, times(1)).delete((Job) notNull()); }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldSendMultipartMailContainingTextPartWhenCustomMessageIsConfigured() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).setProperty("messageString", "My custom message\n").build(); dsnBounce.init(mailetConfig);/*from w w w . j a v a 2 s . c o m*/ MailAddress senderMailAddress = new MailAddress("sender@domain.com"); FakeMail mail = FakeMail.builder().sender(senderMailAddress).attribute("delivery-error", "Delivery error") .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).name(MAILET_NAME) .recipient("recipient@domain.com").lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z"))) .build(); dsnBounce.service(mail); String expectedContent = "My custom message\n\n" + "Failed recipient(s):\n" + "recipient@domain.com\n" + "\n" + "Error message:\n" + "Delivery error\n" + "\n"; List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); MimeMessage sentMessage = sentMail.getMsg(); MimeMultipart content = (MimeMultipart) sentMessage.getContent(); BodyPart bodyPart = content.getBodyPart(0); assertThat(bodyPart.getContentType()).isEqualTo("text/plain; charset=us-ascii"); assertThat(bodyPart.getContent()).isEqualTo(expectedContent); }
From source file:com.vmware.photon.controller.api.client.resource.DisksApiTest.java
@Test public void testDelete() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); DisksApi disksApi = new DisksApi(restClient); Task task = disksApi.delete("foo"); assertEquals(task, responseTask);/* ww w .ja v a 2 s.c o m*/ }
From source file:com.vmware.photon.controller.api.client.resource.DisksRestApiTest.java
@Test public void testDelete() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); DisksApi disksApi = new DisksRestApi(restClient); Task task = disksApi.delete("foo"); assertEquals(task, responseTask);/*from w w w . j a v a 2 s. c o m*/ }
From source file:org.millr.slick.servlets.item.EditItemServlet.java
private Date convertDate(String publishString) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm", Locale.ENGLISH); LocalDateTime dateTime = LocalDateTime.parse(publishString, formatter); Date publishDate = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant()); return publishDate; }
From source file:net.ceos.project.poi.annotated.core.CellFormulaHandler.java
/** * Apply a Date value to the cell.// w w w. j a v a2 s . c om * * @param configCriteria * the {@link XConfigCriteria} * @param object * the object * @param cell * the {@link Cell} to use * @throws IllegalAccessException * @throws ConverterException */ protected static void localDateHandler(final XConfigCriteria configCriteria, final Object object, final Cell cell) throws IllegalAccessException, ConverterException { LocalDate date = (LocalDate) configCriteria.getField().get(object); if (StringUtils.isNotBlank(configCriteria.getElement().transformMask())) { // apply transformation mask String decorator = configCriteria.getElement().transformMask(); convertDate(cell, Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()), decorator); } else if (StringUtils.isNotBlank(configCriteria.getElement().formatMask())) { // apply format mask CellValueHandler.consumeValue(cell, Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant())); } else { // apply default date mask CellValueHandler.consumeValue(cell, Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant())); } }
From source file:retsys.client.controller.CreditNoteController.java
@Override protected Object buildRequestMsg() { CreditNote creditNote = new CreditNote(); if (!creditNoteNo.getText().isEmpty()) { // update operation creditNote.setId(Integer.parseInt(creditNoteNo.getText())); }// w ww. j a v a 2s . c o m Vendor vendorObj = new Vendor(); vendorObj.setId(splitId(vendor.getText())); creditNote.setVendor(vendorObj); Date date = Date.from(Instant.from(creationDate.getValue().atStartOfDay(ZoneId.systemDefault()))); creditNote.setCreationDate(date); creditNote.setTotalAmount(Double.parseDouble(totalCredit.getText())); creditNote.setRemarks(remarks.getText()); List<CreditNoteDetail> details = new ArrayList<>(); Iterator<CreditNoteItem> items = creditNoteDetail.getItems().iterator(); while (items.hasNext()) { CreditNoteItem creditNoteItem = items.next(); Item item = new Item(); //item.setId(getId(creditNoteItem.getItemName().get())); item.setId(splitId(creditNoteItem.getItemName().get())); if (creditNoteItem.getId().get() != 0) { // update operation details.add(new CreditNoteDetail(creditNoteItem.getId().get(), item, creditNoteItem.getReturnQuantity().get(), creditNoteItem.getItemAmount().get(), creditNoteItem.getConfirm().get())); } else { details.add(new CreditNoteDetail(item, creditNoteItem.getReturnQuantity().get(), creditNoteItem.getItemAmount().get(), creditNoteItem.getConfirm().get())); } } creditNote.setCreditNoteDetails(details); return creditNote; }
From source file:org.sonar.core.issue.DefaultIssue.java
@CheckForNull private static Date truncateToSeconds(@Nullable Date d) { if (d == null) { return null; }//w ww. j a v a 2 s.c o m Instant instant = d.toInstant(); instant = instant.truncatedTo(ChronoUnit.SECONDS); return Date.from(instant); }
From source file:org.dbflute.solr.cbean.SolrQueryBuilder.java
public static String queryBuilderForRangeSearch(String solrFieldName, LocalDateTime from, LocalDateTime to) { Date fromDate = from == null ? null : Date.from(ZonedDateTime.of(from, ZoneId.systemDefault()).toInstant()); Date toDate = to == null ? null : Date.from(ZonedDateTime.of(to, ZoneId.systemDefault()).toInstant()); return queryBuilderForRangeSearch(solrFieldName, fromDate, toDate); }
From source file:retsys.client.controller.DeliveryChallanController.java
@Override Object buildRequestMsg() {/* www . j ava 2 s . co m*/ DeliveryChallan dc = new DeliveryChallan(); dc.setChallanDate(Date.from(Instant.now())); Project proj = new Project(); proj.setId(getId(project.getText())); dc.setProject(proj); dc.setIsDelivery(true); dc.setOriginalDeliveryChallan(null); dc.setDeliveryMode(deliverymode.getText()); dc.setConcernPerson(concernperson.getText()); Iterator<DCItem> items = dcDetail.getItems().iterator(); List<DeliveryChallanDetail> dcDetails = new ArrayList<>(); while (items.hasNext()) { DCItem dcItem = items.next(); DeliveryChallanDetail dcDetail = new DeliveryChallanDetail(); Item item = new Item(); //item.setId(getId(String.valueOf(dcItem.getId().get()))); item.setId(dcItem.getId().get()); dcDetail.setItem(item); dcDetail.setQuantity(dcItem.getQuantity().get()); dcDetail.setUnits(dcItem.getUnits().get()); dcDetail.setAmount(dcItem.getAmount().get()); dcDetails.add(dcDetail); } dc.setDeliveryChallanDetail(dcDetails); return dc; }