List of usage examples for java.time LocalDate atStartOfDay
public ZonedDateTime atStartOfDay(ZoneId zone)
From source file:Main.java
public static void main(String[] args) { LocalDate a = LocalDate.of(2014, 6, 30); System.out.println(a.atStartOfDay(ZoneId.systemDefault())); }
From source file:com.rcs.shoe.shop.fx.utils.DateUtils.java
public static Date convert(LocalDate localDate) { Instant instant = Instant.from(localDate.atStartOfDay(ZoneId.systemDefault())); return Date.from(instant); }
From source file:org.opendatakit.briefcase.util.ExportAction.java
public static List<String> export(BriefcaseFormDefinition formDefinition, ExportConfiguration configuration, TerminationFuture terminationFuture) { List<String> errors = new ArrayList<>(); Optional<File> pemFile = configuration.mapPemFile(Path::toFile).filter(File::exists); if ((formDefinition.isFileEncryptedForm() || formDefinition.isFieldEncryptedForm()) && !pemFile.isPresent()) errors.add(formDefinition.getFormName() + " form is encrypted"); else/*from ww w . ja v a 2 s. c om*/ try { export(configuration.mapExportDir(Path::toFile) .orElseThrow(() -> new RuntimeException("Wrong export configuration")), ExportType.CSV, formDefinition, pemFile.orElse(null), terminationFuture, configuration.mapStartDate( (LocalDate ld) -> Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant())) .orElse(null), configuration.mapEndDate( (LocalDate ld) -> Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant())) .orElse(null)); } catch (IOException ex) { errors.add("Export of form " + formDefinition.getFormName() + " has failed: " + ex.getMessage()); } return errors; }
From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java
public static Date toDate(LocalDate localDate) throws BusinessException { return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); }
From source file:org.silverpeas.core.date.Period.java
/** * Creates a new period of time between the two non null specified dates. The period is spreading * over all the day(s) between the specified inclusive start day and the exclusive end day; the * period is expressed in days. For example, a period between 2016-12-15 and 2016-12-17 means the * period is spreading over two days (2016-12-15 and 2016-12-16). * @param startDay the start day of the period. It defines the inclusive date at which the * period starts./* www . ja va 2 s . com*/ * @param endDay the end day of the period. It defines the exclusive date at which the period * ends. The end date must be the same or after the start date. An end date equal to the start * date means the period is spanning all the day of the start date; it is equivalent to an end * date being one day after the start date. * @return the period of days between the two specified dates. */ public static Period between(LocalDate startDay, LocalDate endDay) { checkPeriod(startDay, endDay); Period period = new Period(); period.startDateTime = startDay == LocalDate.MIN ? OffsetDateTime.MIN : startDay.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime(); period.endDateTime = endDay == LocalDate.MAX ? OffsetDateTime.MAX : endDay.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime(); if (startDay.isEqual(endDay)) { period.endDateTime = period.endDateTime.plusDays(1); } period.inDays = true; return period; }
From source file:net.ceos.project.poi.annotated.core.CellFormulaHandler.java
/** * Apply a Date value to the cell.//from w ww .j av a 2s . c o m * * @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:com.splicemachine.orc.OrcTester.java
private static Object preprocessWriteValueOld(TypeInfo typeInfo, Object value) throws IOException { if (value == null) { return null; }/*from www. j a v a 2 s . c om*/ switch (typeInfo.getCategory()) { case PRIMITIVE: PrimitiveObjectInspector.PrimitiveCategory primitiveCategory = ((PrimitiveTypeInfo) typeInfo) .getPrimitiveCategory(); switch (primitiveCategory) { case BOOLEAN: return value; case BYTE: return ((Number) value).byteValue(); case SHORT: return ((Number) value).shortValue(); case INT: return ((Number) value).intValue(); case LONG: return ((Number) value).longValue(); case FLOAT: return ((Number) value).floatValue(); case DOUBLE: return ((Number) value).doubleValue(); case DECIMAL: return HiveDecimal.create(((Decimal) value).toBigDecimal().bigDecimal()); case STRING: return value; case CHAR: return new HiveChar(value.toString(), ((CharTypeInfo) typeInfo).getLength()); case DATE: LocalDate localDate = LocalDate.ofEpochDay((int) value); ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault()); long millis = zonedDateTime.toEpochSecond() * 1000; Date date = new Date(0); // mills must be set separately to avoid masking date.setTime(millis); return date; case TIMESTAMP: long millisUtc = ((Long) value).intValue(); return new Timestamp(millisUtc); case BINARY: return ((String) value).getBytes(); // return (byte[])value; } break; case MAP: MapTypeInfo mapTypeInfo = (MapTypeInfo) typeInfo; TypeInfo keyTypeInfo = mapTypeInfo.getMapKeyTypeInfo(); TypeInfo valueTypeInfo = mapTypeInfo.getMapValueTypeInfo(); Map<Object, Object> newMap = new HashMap<>(); for (Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) { newMap.put(preprocessWriteValueOld(keyTypeInfo, entry.getKey()), preprocessWriteValueOld(valueTypeInfo, entry.getValue())); } return newMap; case LIST: ListTypeInfo listTypeInfo = (ListTypeInfo) typeInfo; TypeInfo elementTypeInfo = listTypeInfo.getListElementTypeInfo(); List<Object> newList = new ArrayList<>(((Collection<?>) value).size()); for (Object element : (Iterable<?>) value) { newList.add(preprocessWriteValueOld(elementTypeInfo, element)); } return newList; case STRUCT: StructTypeInfo structTypeInfo = (StructTypeInfo) typeInfo; List<?> fieldValues = (List<?>) value; List<TypeInfo> fieldTypeInfos = structTypeInfo.getAllStructFieldTypeInfos(); List<Object> newStruct = new ArrayList<>(); for (int fieldId = 0; fieldId < fieldValues.size(); fieldId++) { newStruct.add(preprocessWriteValueOld(fieldTypeInfos.get(fieldId), fieldValues.get(fieldId))); } return newStruct; } throw new IOException(format("Unsupported Hive type: %s", typeInfo)); }
From source file:com.ewerk.prototype.persistence.converters.LocalDateToDateConverter.java
@Override public Date convert(LocalDate localDate) { if (localDate == null) { return null; }//from w ww . j ava 2 s . c om return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); }
From source file:org.sonatype.nexus.tasklog.TaskLogCleanup.java
void cleanup() { String taskLogsHome = getTaskLogHome(); if (taskLogsHome == null) { // we are forgiving if the task logs home is not defined. Just log a message with a call to action. log.warn(//from ww w .j a va 2 s.c o m "Unable to cleanup task log files. Please check that the 'tasklogfile' appender exists in logback.xml"); return; } File logFilesHome = new File(taskLogsHome); log.info("Cleaning up log files in {} older than {} days", logFilesHome.getAbsolutePath(), numberOfDays); LocalDate now = LocalDate.now().minusDays(numberOfDays); Date thresholdDate = Date.from(now.atStartOfDay(ZoneId.systemDefault()).toInstant()); AgeFileFilter ageFileFilter = new AgeFileFilter(thresholdDate); Iterator<File> filesToDelete = iterateFiles(logFilesHome, ageFileFilter, ageFileFilter); filesToDelete.forEachRemaining(f -> { try { forceDelete(f); log.info("Removed task log file {}", f.toString()); } catch (IOException e) { // NOSONAR log.error("Unable to delete task file {}. Message was {}.", f.toString(), e.getMessage()); } }); }
From source file:org.ojbc.util.model.rapback.IdentificationResultSearchRequest.java
public void setReportedDateEndLocalDate(LocalDate localDate) { this.reportedDateEndDate = localDate == null ? null : Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); }