List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:net.ceos.project.poi.annotated.core.CsvHandler.java
/** * Apply a date time value at the field. * /*from w w w . j ava 2 s. com*/ * @param value * the value * @param formatMask * the decorator mask * @param transformMask * the transformation mask * @return false if problem otherwise true * @throws ConverterException * the conversion exception type */ protected static String toLocalDateTime(final LocalDateTime value, final String formatMask, final String transformMask) throws ConverterException { String dateMasked = StringUtils.EMPTY; if (value != null) { try { if (StringUtils.isNotBlank(transformMask)) { // apply transformation mask dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()), transformMask); } else if (StringUtils.isNotBlank(formatMask)) { // apply format mask dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()), formatMask); } else { // default mask dateMasked = applyMaskToDate(Date.from(value.atZone(ZoneId.systemDefault()).toInstant()), Constants.DD_MMM_YYYY_HH_MM_SS); } } catch (Exception e) { throw new ConverterException(ExceptionMessage.CONVERTER_LOCALDATETIME.getMessage(), e); } } return dateMasked; }
From source file:alfio.manager.AdminReservationManager.java
private void createMissingTickets(Event event, int tickets) { final MapSqlParameterSource[] params = generateEmptyTickets(event, Date.from(ZonedDateTime.now(event.getZoneId()).toInstant()), tickets, Ticket.TicketStatus.FREE) .toArray(MapSqlParameterSource[]::new); jdbc.batchUpdate(ticketRepository.bulkTicketInitialization(), params); }
From source file:org.pentaho.hadoop.shim.common.format.avro.AvroNestedReader.java
/** * Perform Kettle type conversions for the Avro leaf field value. * * @param fieldValue the leaf value from the Avro structure * @return an Object of the appropriate Kettle type * @throws KettleException if a problem occurs *///from w w w . ja v a 2 s . co m protected Object getKettleValue(AvroInputField avroInputField, Object fieldValue) throws KettleException { switch (avroInputField.getTempValueMeta().getType()) { case ValueMetaInterface.TYPE_BIGNUMBER: return avroInputField.getTempValueMeta().getBigNumber(fieldValue); case ValueMetaInterface.TYPE_BINARY: return avroInputField.getTempValueMeta().getBinary(fieldValue); case ValueMetaInterface.TYPE_BOOLEAN: return avroInputField.getTempValueMeta().getBoolean(fieldValue); case ValueMetaInterface.TYPE_DATE: if (avroInputField.getAvroType().getBaseType() == AvroSpec.DataType.INTEGER.getBaseType()) { LocalDate localDate = LocalDate.ofEpochDay(0).plusDays((Long) fieldValue); return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } else if (avroInputField.getAvroType().getBaseType() == AvroSpec.DataType.STRING.getBaseType()) { Object pentahoData = null; String dateFormatStr = avroInputField.getStringFormat(); if ((dateFormatStr == null) || (dateFormatStr.trim().length() == 0)) { dateFormatStr = ValueMetaBase.DEFAULT_DATE_FORMAT_MASK; } SimpleDateFormat datePattern = new SimpleDateFormat(dateFormatStr); try { return datePattern.parse(fieldValue.toString()); } catch (Exception e) { return null; } } return avroInputField.getTempValueMeta().getDate(fieldValue); case ValueMetaInterface.TYPE_TIMESTAMP: return new Timestamp((Long) fieldValue); case ValueMetaInterface.TYPE_INTEGER: return avroInputField.getTempValueMeta().getInteger(fieldValue); case ValueMetaInterface.TYPE_NUMBER: return avroInputField.getTempValueMeta().getNumber(fieldValue); case ValueMetaInterface.TYPE_STRING: return avroInputField.getTempValueMeta().getString(fieldValue); case ValueMetaInterface.TYPE_INET: try { return InetAddress.getByName(fieldValue.toString()); } catch (UnknownHostException ex) { return null; } default: return null; } }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraAssignmentsRepository.java
List<Date> getUserAssignmentPartitions(Date fromTime, Date toTime) { final LocalDateTime startTime = LocalDateTime.ofInstant(fromTime.toInstant(), ZoneId.systemDefault()) .withMinute(0).withSecond(0).withNano(0); final LocalDateTime endTime = LocalDateTime.ofInstant(toTime.toInstant(), ZoneId.systemDefault()) .withMinute(0).withSecond(0).withNano(0); final long hours = Duration.between(startTime, endTime).toHours(); return LongStream.rangeClosed(0, hours).mapToObj(startTime::plusHours) .map(t -> Date.from(t.atZone(ZoneId.systemDefault()).toInstant())).collect(Collectors.toList()); }
From source file:alfio.manager.TicketReservationManager.java
private void transitionToOfflinePayment(Event event, String reservationId, String email, CustomerName customerName, String billingAddress) { ZonedDateTime deadline = getOfflinePaymentDeadline(event, configurationManager); int updatedReservation = ticketReservationRepository.postponePayment(reservationId, Date.from(deadline.toInstant()), email, customerName.getFullName(), customerName.getFirstName(), customerName.getLastName(), billingAddress); Validate.isTrue(updatedReservation == 1, "expected exactly one updated reservation, got " + updatedReservation); }
From source file:jef.tools.DateUtils.java
/** * Convert LocalDate to jud/* w w w. ja v a2 s.c o m*/ * * @param date * LocalDate * @return java.util.Date */ public static Date fromLocalDate(LocalDate date) { return date == null ? null : Date.from(date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); }
From source file:jef.tools.DateUtils.java
/** * Convert LocalTime to jud.// www . j a va 2 s . com * * @param time * LocalTime * @return java.util.Date */ public static Date fromLocalTime(LocalTime time) { return time == null ? null : Date.from(LocalDateTime.of(LocalDate.now(), time).atZone(ZoneId.systemDefault()).toInstant()); }
From source file:jef.tools.DateUtils.java
/** * Converts LocalDateTime to java.util.Date (null safety) * @param LocalDateTime//from www . j a va 2 s.co m * @return java.util.Date */ public static Date fromLocalDateTime(LocalDateTime value) { return value == null ? null : Date.from(value.atZone(ZoneId.systemDefault()).toInstant()); }
From source file:jef.tools.DateUtils.java
/** * Converts instant to JUD (null safety) * @param instant/* ww w.j a v a 2s .c o m*/ * @return java.util.Date */ public static Date fromInstant(Instant instant) { return instant == null ? null : Date.from(instant); }
From source file:org.sakaiproject.contentreview.turnitin.oc.ContentReviewServiceTurnitinOC.java
public void checkForReport() { // Original file has been uploaded, and similarity report has been requested // Check for status of report and return score int errors = 0; int success = 0; for (ContentReviewItem item : crqs.getAwaitingReports(getProviderId())) { try {/*w w w . j ava2s .com*/ // Make sure it's after the next retry time if (item.getNextRetryTime().getTime() > new Date().getTime()) { continue; } if (!incrementItem(item)) { errors++; continue; } // Check if any placeholder items need to regenerate report after due date if (PLACEHOLDER_ITEM_REVIEW_SCORE.equals(item.getReviewScore())) { // Get assignment associated with current item's task Id Assignment assignment = assignmentService .getAssignment(entityManager.newReference(item.getTaskId())); Date assignmentDueDate = Date.from(assignment.getDueDate()); if (assignment != null && assignmentDueDate != null) { // Make sure due date is past if (assignmentDueDate.before(new Date())) { //Lookup reference item String referenceItemContentId = item.getContentId().substring(0, item.getContentId().indexOf(PLACEHOLDER_STRING_FLAG)); Optional<ContentReviewItem> quededReferenceItem = crqs .getQueuedItem(item.getProviderId(), referenceItemContentId); ContentReviewItem referenceItem = quededReferenceItem.isPresent() ? quededReferenceItem.get() : null; if (referenceItem != null && checkForContentItemInSubmission(referenceItem, assignment)) { // Regenerate similarity request for reference id // Report is recalled after due date generateSimilarityReport(referenceItem.getExternalId(), referenceItem.getTaskId()); //reschedule reference item by setting score to null, reset retry time and set status to awaiting report referenceItem.setStatus( ContentReviewConstants.CONTENT_REVIEW_SUBMITTED_AWAITING_REPORT_CODE); referenceItem.setRetryCount(Long.valueOf(0)); referenceItem.setReviewScore(null); referenceItem.setNextRetryTime(new Date()); crqs.update(referenceItem); // Report regenerated for reference item, placeholder item is no longer needed crqs.delete(item); success++; continue; } else { // Reference item no longer exists // Placeholder item is no longer needed crqs.delete(item); errors++; continue; } } else { // We don't want placeholder items to exceed retry count maximum // Reset retry count to zero item.setRetryCount(Long.valueOf(0)); item.setNextRetryTime(getDueDateRetryTime(assignmentDueDate)); crqs.update(item); continue; } } else { // Assignment or due date no longer exist // placeholder item is no longer needed crqs.delete(item); errors++; continue; } } // Get status of similarity report // Returns -1 if report is still processing // Returns -2 if an error occurs // Else returns reports score as integer int status = getSimilarityReportStatus(item.getExternalId()); if (status >= 0) { success++; } handleReportStatus(item, status); } catch (IOException e) { log.error(e.getLocalizedMessage(), e); item.setLastError("A problem occurred while retrieving an originality score from Turnitin"); item.setStatus(ContentReviewConstants.CONTENT_REVIEW_REPORT_ERROR_RETRY_CODE); crqs.update(item); errors++; } catch (Exception e) { log.error(e.getLocalizedMessage(), e); item.setLastError(e.getMessage()); item.setStatus(ContentReviewConstants.CONTENT_REVIEW_REPORT_ERROR_RETRY_CODE); crqs.update(item); errors++; } } log.info("Turnitin report queue run completed: " + success + " items submitted, " + errors + " errors."); }