List of usage examples for java.time LocalDate atStartOfDay
public LocalDateTime atStartOfDay()
From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java
public static Timestamp getTimestamp(final LocalDate date) { return date != null ? Timestamp.valueOf(date.atStartOfDay()) : null; }
From source file:daylightchart.daylightchart.calculation.RiseSetUtility.java
/** * Calculator for sunrise and sunset times for a year. * * @param location//w w w . j a v a 2 s. c o m * Location * @param year * Year * @param options * Options * @return Full years sunset and sunrise times for a location */ public static RiseSetYearData createRiseSetYear(final Location location, final int year, final Options options) { final TimeZoneOption timeZoneOption = options.getTimeZoneOption(); final ZoneId zoneId; if (location != null) { final String timeZoneId; if (timeZoneOption != null && timeZoneOption == TimeZoneOption.USE_TIME_ZONE) { timeZoneId = location.getTimeZoneId(); } else { timeZoneId = DefaultTimezones.createGMTTimeZoneId(location.getPointLocation().getLongitude()); } zoneId = ZoneId.of(timeZoneId); } else { zoneId = ZoneId.systemDefault(); } final boolean timeZoneUsesDaylightTime = !zoneId.getRules().getTransitionRules().isEmpty(); final boolean useDaylightTime = timeZoneUsesDaylightTime && timeZoneOption != TimeZoneOption.USE_LOCAL_TIME; boolean wasDaylightSavings = false; final TwilightType twilight = options.getTwilightType(); final RiseSetYearData riseSetYear = new RiseSetYearData(location, twilight, year); riseSetYear.setUsesDaylightTime(useDaylightTime); for (final LocalDate date : getYearsDates(year)) { final boolean inDaylightSavings = zoneId.getRules() .isDaylightSavings(date.atStartOfDay().atZone(zoneId).toInstant()); if (wasDaylightSavings != inDaylightSavings) { if (!wasDaylightSavings) { riseSetYear.setDstStart(date); } else { riseSetYear.setDstEnd(date); } } wasDaylightSavings = inDaylightSavings; final RawRiseSet riseSet = calculateRiseSet(location, date, useDaylightTime, inDaylightSavings, TwilightType.NO); riseSetYear.addRiseSet(riseSet); if (twilight != null) { final RawRiseSet twilights = calculateRiseSet(location, date, useDaylightTime, inDaylightSavings, twilight); riseSetYear.addTwilight(twilights); } } // Create band for twilight, clock-shift taken into account createBands(riseSetYear, DaylightBandType.twilight); // Create band, clock-shift taken into account createBands(riseSetYear, DaylightBandType.with_clock_shift); // Create band, without clock shift createBands(riseSetYear, DaylightBandType.without_clock_shift); return riseSetYear; }
From source file:org.openmhealth.shim.misfit.mapper.MisfitStepCountDataPointMapper.java
@Override public Optional<DataPoint<StepCount>> asDataPoint(JsonNode summaryNode) { checkNotNull(summaryNode);/*ww w . ja va 2 s. c om*/ Long stepCount = asRequiredLong(summaryNode, "steps"); if (stepCount == 0) { return Optional.empty(); } StepCount.Builder builder = new StepCount.Builder(stepCount); // this property isn't listed in the table, but does appear in the second Example section where detail is true LocalDate localDate = asRequiredLocalDate(summaryNode, "date"); // FIXME fix the time zone offset once Misfit add it to the API OffsetDateTime startDateTime = localDate.atStartOfDay().atOffset(UTC); DurationUnitValue durationUnitValue = new DurationUnitValue(DAY, 1); builder.setEffectiveTimeFrame(ofStartDateTimeAndDuration(startDateTime, durationUnitValue)); StepCount measure = builder.build(); return Optional.of(newDataPoint(measure, RESOURCE_API_SOURCE_NAME, null, null)); }
From source file:org.openhab.binding.openuv.internal.handler.OpenUVBridgeHandler.java
public @Nullable OpenUVResult getUVData(String latitude, String longitude, @Nullable String altitude) { StringBuilder urlBuilder = new StringBuilder(BASE_URL).append("?lat=").append(latitude).append("&lng=") .append(longitude);/*w w w. j ava 2 s.c o m*/ if (altitude != null) { urlBuilder.append("&alt=").append(altitude); } String errorMessage = null; try { String jsonData = HttpUtil.executeUrl("GET", urlBuilder.toString(), header, null, null, REQUEST_TIMEOUT); OpenUVResponse uvResponse = gson.fromJson(jsonData, OpenUVResponse.class); if (uvResponse.getError() == null) { updateStatus(ThingStatus.ONLINE); return uvResponse.getResult(); } else { errorMessage = uvResponse.getError(); } } catch (IOException e) { errorMessage = e.getMessage(); } if (errorMessage.startsWith(ERROR_QUOTA_EXCEEDED)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, errorMessage); LocalDate today = LocalDate.now(); LocalDate tomorrow = today.plusDays(1); LocalDateTime tomorrowMidnight = tomorrow.atStartOfDay().plusMinutes(2); logger.warn("Quota Exceeded, going OFFLINE for today, will retry at : {} ", tomorrowMidnight); scheduler.schedule(this::initiateConnexion, Duration.between(LocalDateTime.now(), tomorrowMidnight).toMinutes(), TimeUnit.MINUTES); } else if (errorMessage.startsWith(ERROR_WRONG_KEY)) { logger.error("Error occured during API query : {}", errorMessage); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, errorMessage); } return null; }
From source file:org.talend.dataprep.transformation.actions.date.DateParser.java
/** * Parse the date from the given patterns. * * @param value the text to parse./*from w w w. ja v a 2s .c o m*/ * @param patterns the patterns to use. * @return the parsed date-time */ public LocalDateTime parseDateFromPatterns(String value, List<DatePattern> patterns) { // take care of the null value if (value == null) { throw new DateTimeException("cannot parse null"); } for (DatePattern pattern : patterns) { final DateTimeFormatter formatter = new DateTimeFormatterBuilder().parseCaseInsensitive() .append(pattern.getFormatter()).toFormatter(Locale.ENGLISH); // first try to parse directly as LocalDateTime try { return LocalDateTime.parse(value, formatter); } catch (DateTimeException e) { LOGGER.trace("Unable to parse date '{}' using LocalDateTime.", value, e); // if it fails, let's try the LocalDate first try { LocalDate temp = LocalDate.parse(value, formatter); return temp.atStartOfDay(); } catch (DateTimeException e2) { LOGGER.trace("Unable to parse date '{}' using LocalDate.", value, e2); // nothing to do here, just try the next formatter } } } throw new DateTimeException("'" + value + "' does not match any known pattern"); }
From source file:nc.noumea.mairie.appock.services.impl.DatePrevisionnelleCommandeServiceImpl.java
@Override public DatePrevisionnelleCommande create(LocalDate date) { if (date == null) { throw new ValidationException("La date ne peut pas tre nulle"); }// w w w. j a v a 2 s .c om if (datePrevisionnelleCommandeRepository.findOneByDatePrevisionnelle(date.atStartOfDay()) != null) { throw new ValidationException("La date prvisionnelle existe dj"); } DatePrevisionnelleCommande datePrevisionnelleCommande = new DatePrevisionnelleCommande(); datePrevisionnelleCommande.setDatePrevisionnelle(date.atStartOfDay()); datePrevisionnelleCommande.setCreateUser(authHelper.getCurrentUser().getNomComplet()); return this.save(datePrevisionnelleCommande); }
From source file:net.bis5.slack.command.gcal.SlashCommandApi.java
private EventDateTime toDateTime(LocalDate date, LocalTime time) { if (time != null) { DateTime dateTime = new DateTime( Date.from(LocalDateTime.of(date, time).toInstant(ZoneOffset.ofHours(+9)))); return new EventDateTime().setDateTime(dateTime); } else {// www.jav a 2 s.c o m DateTime dateTime = new DateTime(true, Date.from(date.atStartOfDay().toInstant(ZoneOffset.UTC)).getTime(), 9); return new EventDateTime().setDate(dateTime); } }
From source file:jef.tools.DateUtils.java
/** * Convert LocalDate to jud/*from w w w . ja v a 2s .c om*/ * * @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:com.bdb.weather.display.day.DayXYPlotPane.java
/** * Update the domain axis of the plot to the day passed in. This can be used to change the plot * to show a different day/*from w w w .j av a 2 s. c om*/ * * @param date The date */ private void updateDomainAxis(LocalDate date) { plot.clearRangeMarkers(); LocalDateTime midnight = date.atStartOfDay(); LocalDateTime endOfDay = midnight.plusDays(1).minusSeconds(1); dateAxis.setRange(TimeUtils.localDateTimeToDate(midnight), TimeUtils.localDateTimeToDate(endOfDay)); }
From source file:org.nuxeo.apidoc.browse.Distribution.java
protected Map<String, Serializable> readFormData(FormData formData) { Map<String, Serializable> properties = new HashMap<>(); // Release date String released = formData.getString("released"); if (StringUtils.isNotBlank(released)) { LocalDate date = LocalDate.parse(released); Instant instant = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(); properties.put(PROP_RELEASED, Date.from(instant)); }/*from w w w . j a va 2 s . c om*/ return properties; }