List of usage examples for java.time ZonedDateTime withZoneSameInstant
@Override
public ZonedDateTime withZoneSameInstant(ZoneId zone)
From source file:alfio.datamapper.QueryType.java
private static SqlParameterSource extractParameters(Method m, Object[] args) { Annotation[][] parameterAnnotations = m.getParameterAnnotations(); if (parameterAnnotations == null || parameterAnnotations.length == 0) { return new EmptySqlParameterSource(); }// ww w . j av a2 s.c o m MapSqlParameterSource ps = new MapSqlParameterSource(); Class<?>[] parameterTypes = m.getParameterTypes(); for (int i = 0; i < args.length; i++) { String name = parameterName(parameterAnnotations[i]); if (name != null) { if (args[i] != null && ZonedDateTime.class.isAssignableFrom(parameterTypes[i])) { ZonedDateTime dateTime = ZonedDateTime.class.cast(args[i]); final ZonedDateTime utc = dateTime.withZoneSameInstant(ZoneId.of("UTC")); Calendar c = Calendar.getInstance(); c.setTimeZone(TimeZone.getTimeZone("UTC")); c.setTimeInMillis(utc.toInstant().toEpochMilli()); ps.addValue(name, c, Types.TIMESTAMP); } else { ps.addValue(name, args[i], StatementCreatorUtils.javaTypeToSqlParameterType(parameterTypes[i])); } } } return ps; }
From source file:org.apache.jena.sparql.function.library.nowtz.java
private static String fromQueryTime(Context cxt) { // In UTC./*from ww w . j av a 2 s. c o m*/ Node n = cxt.get(ARQConstants.sysCurrentTime); String x = (n == null) ? DateTimeUtils.nowAsXSDDateTimeString() : n.getLiteralLexicalForm(); ZonedDateTime zdt = dtf.parse(x, ZonedDateTime::from); ZonedDateTime zdtLocal; // Convert to local timezone. (maybe should put the time into context as an Instant?) if (!zoneIdUTC.equals(ZoneId.systemDefault())) zdtLocal = zdt.withZoneSameInstant(ZoneId.systemDefault()); else zdtLocal = zdt; return dtf.format(zdtLocal); }
From source file:io.stallion.utils.GeneralUtils.java
@Deprecated public static String formatLocalDateFromZonedDate(ZonedDateTime date, String formatPattern) { if (date == null) { return ""; }//from www . j av a 2 s . c o m ZonedDateTime localDt = date.withZoneSameInstant(Context.getSettings().getTimeZoneId()); DateTimeFormatter formatter; if (StringUtils.isEmpty(formatPattern)) { formatter = DEFAULT_FORMAT; } else if ("iso".equals(formatPattern.toLowerCase())) { formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; } else { formatter = DateTimeFormatter.ofPattern(formatPattern); } return localDt.format(formatter); }
From source file:alfio.util.TemplateResource.java
public static Map<String, Object> prepareModelForConfirmationEmail(Organization organization, Event event, TicketReservation reservation, Optional<String> vat, List<Ticket> tickets, OrderSummary orderSummary, String reservationUrl, String reservationShortID, Optional<String> invoiceAddress, Optional<String> bankAccountNr, Optional<String> bankAccountOwner) { Map<String, Object> model = new HashMap<>(); model.put("organization", organization); model.put("event", event); model.put("ticketReservation", reservation); model.put("hasVat", vat.isPresent()); model.put("vatNr", vat.orElse("")); model.put("tickets", tickets); model.put("orderSummary", orderSummary); model.put("reservationUrl", reservationUrl); model.put("locale", reservation.getUserLanguage()); ZonedDateTime confirmationTimestamp = Optional.ofNullable(reservation.getConfirmationTimestamp()) .orElseGet(ZonedDateTime::now); model.put("confirmationDate", confirmationTimestamp.withZoneSameInstant(event.getZoneId())); if (reservation.getValidity() != null) { model.put("expirationDate", ZonedDateTime.ofInstant(reservation.getValidity().toInstant(), event.getZoneId())); }/*from w w w. j a v a 2s . com*/ model.put("reservationShortID", reservationShortID); model.put("hasInvoiceAddress", invoiceAddress.isPresent()); invoiceAddress.ifPresent(addr -> { model.put("invoiceAddress", StringUtils.replace(addr, "\n", ", ")); model.put("invoiceAddressAsList", Arrays.asList(StringUtils.split(addr, '\n'))); }); model.put("hasBankAccountNr", bankAccountNr.isPresent()); bankAccountNr.ifPresent(nr -> { model.put("bankAccountNr", nr); }); model.put("isOfflinePayment", reservation.getStatus() == TicketReservation.TicketReservationStatus.OFFLINE_PAYMENT); model.put("paymentReason", event.getShortName() + " " + reservationShortID); model.put("hasBankAccountOnwer", bankAccountOwner.isPresent()); bankAccountOwner.ifPresent(owner -> { model.put("bankAccountOnwer", StringUtils.replace(owner, "\n", ", ")); model.put("bankAccountOnwerAsList", Arrays.asList(StringUtils.split(owner, '\n'))); }); return model; }
From source file:com.example.app.support.AppUtil.java
/** * Convert the given Date from UTC to a ZonedDateTime at the given TimeZone * * @param date the UTC date/*from www . j a v a2 s . c om*/ * @param zone the TimeZone to convert the time to * * @return a ZonedDateTime that represents the same instant as the UTC date, but at the given TimeZone. */ @Nullable public static ZonedDateTime convertFromPersisted(@Nullable Date date, @Nullable TimeZone zone) { if (date == null || zone == null) return null; ZonedDateTime from = ZonedDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC); return from.withZoneSameInstant(zone.toZoneId()); }
From source file:com.example.app.support.AppUtil.java
/** * Convert the given ZonedDateTime to a UTC date for persistence * * @param dt the ZonedDateTime to convert to UTC * * @return a Date object that represents the same instant as the ZonedDateTime, but at UTC. *//*from w w w . ja va 2 s . co m*/ @Nullable public static Date convertForPersistence(@Nullable ZonedDateTime dt) { if (dt == null) return null; ZonedDateTime atUtc = dt.withZoneSameInstant(ZoneOffset.UTC); return new Date(atUtc.toInstant().toEpochMilli()); }
From source file:com.example.app.support.service.AppUtil.java
/** * Convert the given Date from UTC to a ZonedDateTime at the given TimeZone * * @param date the UTC date//from ww w .ja v a2s.c o m * @param zone the TimeZone to convert the time to * * @return a ZonedDateTime that represents the same instant as the UTC date, but at the given TimeZone. */ @Nullable @Contract(value = "null,_->null;_,null->null;!null,!null->!null", pure = true) public static ZonedDateTime convertFromPersisted(@Nullable Date date, @Nullable TimeZone zone) { if (date == null || zone == null) return null; ZonedDateTime from = ZonedDateTime.ofInstant(date.toInstant(), ZoneOffset.UTC); return from.withZoneSameInstant(zone.toZoneId()); }
From source file:com.example.app.support.service.AppUtil.java
/** * Convert the given ZonedDateTime to a UTC date for persistence * * @param dt the ZonedDateTime to convert to UTC * * @return a Date object that represents the same instant as the ZonedDateTime, but at UTC. *///w w w. j a v a 2s . c o m @Nullable @Contract(value = "!null->!null;null->null", pure = true) public static Date convertForPersistence(@Nullable ZonedDateTime dt) { if (dt == null) return null; ZonedDateTime atUtc = dt.withZoneSameInstant(ZoneOffset.UTC); return new Date(atUtc.toInstant().toEpochMilli()); }
From source file:com.github.ibm.domino.resource.EventTime.java
public void setDateTime(ZonedDateTime zonedDateTime) { String s = zonedDateTime.withZoneSameInstant(ZoneId.of("GMT")).toString(); seteDate(s.substring(0, 10));// w ww.j av a2 s . c o m seteTime(s.substring(11, 19)); setUtc(true); }
From source file:com.github.ibm.domino.client.DominoRestClient.java
public DominoRestClient since(ZonedDateTime value) { parameters.put("since", getDateParameter(value.withZoneSameInstant(ZoneId.of("GMT")))); return this; }