List of usage examples for org.joda.time DateTimeZone forTimeZone
public static DateTimeZone forTimeZone(TimeZone zone)
From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java
License:Open Source License
private static DateRange modifyWithTimestamp(final LocalTime timestamp, final DateTime simulationStart, final DateTime simulationEnd) { /* Nothing to do. */ if (timestamp == null) return new DateRange(simulationStart.toDate(), simulationEnd.toDate()); /* Convert to a date with the kalypso timezone. */ /* The date fields are ignored. */ final DateTime timestampUTC = timestamp .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$ final DateTime timestampDate = new DateTime(timestampUTC.toDate(), DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone())); /* Further adjust range by predefined time. */ final DateTime startWithTime = simulationStart.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); final DateTime endWithTime = simulationEnd.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); return new DateRange(startWithTime.toDate(), endWithTime.toDate()); }
From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java
License:Open Source License
/** * This function calculates the range for the timeseries to be generated. The range equals the range defined in the * simulation adjusted as follows:/*w w w . ja va 2 s. c o m*/ * <ul> * <li>1 timestep earlier</li> * <li>3 timesteps later</li> * </ul> * * @param control * The na control. * @param timestep * The timestep. * @param timestamp * The timestamp in UTC. * @return The date range. */ public static DateRange getRange(final NAControl control, final Period timestep, final LocalTime timestamp) { final Date simulationStart = control.getSimulationStart(); final Date simulationEnd = control.getSimulationEnd(); final DateTime start = new DateTime(simulationStart); final DateTime end = new DateTime(simulationEnd); final DateTime adjustedStart = start.minus(timestep); final DateTime adjustedEnd = end.plus(timestep).plus(timestep).plus(timestep); if (timestep.getDays() == 0 || timestamp == null) return new DateRange(adjustedStart.toDate(), adjustedEnd.toDate()); /* Convert to a date with the kalypso timezone. */ /* The date fields are ignored. */ final DateTime timestampUTC = timestamp .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$ final DateTime timestampDate = new DateTime(timestampUTC.toDate(), DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone())); /* Further adjust range by predefined time. */ final DateTime startWithTime = adjustedStart.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); final DateTime endWithTime = adjustedEnd.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); /* New start must always be before unadjusted start, fix, if this is not the case. */ DateTime startWithTimeFixed; if (startWithTime.isAfter(adjustedStart)) startWithTimeFixed = startWithTime.minus(timestep); else startWithTimeFixed = startWithTime; /* New end must always be after unadjusted end, fix, if this is not the case. */ DateTime endWithTimeFixed; if (endWithTime.isBefore(adjustedEnd)) endWithTimeFixed = endWithTime.plus(timestep); else endWithTimeFixed = endWithTime; return new DateRange(startWithTimeFixed.toDate(), endWithTimeFixed.toDate()); }
From source file:org.kegbot.app.util.DateUtils.java
License:Open Source License
/** * Returns a timestamp <em>in the local timezone</em> given an ISO8601-formatted timestamp. * * @param isoString the time stamp//from w ww. ja v a 2s. com * @param timeZone the time zone * @return a unix timestamp in milliseconds relative to the given time zone * @throws IllegalArgumentException if the timestamp cannot be parsed */ public static long dateFromIso8601String(String isoString, TimeZone timeZone) { DateTime dt = new DateTime(new DateTime(isoString), DateTimeZone.forTimeZone(timeZone)); return dt.getMillis(); }
From source file:org.lightjason.agentspeak.action.builtin.datetime.IBetween.java
License:LGPL
@Nonnull @Override/*from w w w .j ava2 s . com*/ public final IFuzzyValue<Boolean> execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List<ITerm> p_argument, @Nonnull final List<ITerm> p_return) { this.apply(StreamUtils.windowed( CCommon.flatten(p_argument).map(ITerm::<ZonedDateTime>raw) .map(i -> new DateTime(i.toInstant().toEpochMilli(), DateTimeZone.forTimeZone(TimeZone.getTimeZone(i.getZone())))) .map(Instant::new), 2, 2)).map(CRawTerm::from).forEach(p_return::add); return CFuzzyValue.from(true); }
From source file:org.mayocat.rest.jackson.DateTimeISO8601Deserializer.java
License:Mozilla Public License
@Override public DateTime deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException { String str = parser.getText().trim(); if (Strings.isNullOrEmpty(str)) { return null; }/*from w w w .j av a 2s. co m*/ ConfigurationService configurationService = Utils.getComponent(ConfigurationService.class); GeneralSettings settings = configurationService.getSettings(GeneralSettings.class); return new DateTime(str, DateTimeZone.forTimeZone(settings.getTime().getTimeZone().getValue())); }
From source file:org.mayocat.shop.billing.api.resource.OrderResource.java
License:Mozilla Public License
@GET @Authorized// w w w .ja v a 2 s . c o m public ResultSetRepresentation<OrderRepresentation> getAllOrders( @QueryParam("number") @DefaultValue("50") Integer number, @QueryParam("offset") @DefaultValue("0") Integer offset) { GeneralSettings settings = configurationService.getSettings(GeneralSettings.class); final DateTimeZone tenantTz = DateTimeZone.forTimeZone(settings.getTime().getTimeZone().getValue()); List<Order> orders = orderStore.get().findAllPaidOrAwaitingPayment(number, offset); Collection<OrderRepresentation> representations = Collections2.transform(orders, new Function<Order, OrderRepresentation>() { public OrderRepresentation apply(final Order order) { return new OrderRepresentation(tenantTz, order); } }); Integer total = this.orderStore.get().countAllPaidOrAwaitingPayment(); ResultSetRepresentation<OrderRepresentation> resultSet = new ResultSetRepresentation<>("/api/orders", number, offset, new ArrayList<>(representations), total); return resultSet; }
From source file:org.mayocat.shop.billing.api.resource.OrderResource.java
License:Mozilla Public License
@GET @Path("{slug}") @Authorized//from www . j a v a 2 s .c om public Response getOrder(@PathParam("slug") String slug) { Order order = orderStore.get().findBySlug(slug); if (order == null) { return Response.status(Response.Status.NOT_FOUND).entity("Order not found").build(); } GeneralSettings settings = configurationService.getSettings(GeneralSettings.class); final DateTimeZone tenantTz = DateTimeZone.forTimeZone(settings.getTime().getTimeZone().getValue()); return Response.ok(new OrderRepresentation(tenantTz, order)).build(); }
From source file:org.n52.svalbard.encode.UVFEncoder.java
License:Apache License
@Setting(UVFSettingsProvider.UVF_TIME_ZONE_SETTING_KEY) public void setTimeZone(String timeZone) { if (!Strings.isNullOrEmpty(timeZone)) { this.timeZone = DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZone.trim())); } else {/*from w w w . ja va2s . c o m*/ this.timeZone = null; } }
From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java
License:Open Source License
private ASSystemTime standardDate(TimeZone timeZone) { DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone); DateMidnight dateMidnight = new DateMidnight(DateTimeUtils.getInstantMillis(null), dateTimeZone); long firstDSTTransitionInstant = dateTimeZone.nextTransition(dateMidnight.getMillis()); long secondDSTTransitionInstant = dateTimeZone.nextTransition(firstDSTTransitionInstant); if (firstDSTTransitionInstant == secondDSTTransitionInstant) { return systemTimeFromInstant(0, DateTimeZone.UTC); }/*from w w w .ja v a2 s.c om*/ if (dateTimeZone.isStandardOffset(firstDSTTransitionInstant)) { return systemTimeFromInstant(firstDSTTransitionInstant, dateTimeZone); } return systemTimeFromInstant(secondDSTTransitionInstant, dateTimeZone); }
From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java
License:Open Source License
private ASSystemTime dayLightDate(TimeZone timeZone) { DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone); DateMidnight dateMidnight = new DateMidnight(DateTimeUtils.getInstantMillis(null), dateTimeZone); long firstDSTTransitionInstant = dateTimeZone.nextTransition(dateMidnight.getMillis()); long secondDSTTransitionInstant = dateTimeZone.nextTransition(firstDSTTransitionInstant); if (firstDSTTransitionInstant == secondDSTTransitionInstant) { return systemTimeFromInstant(0, DateTimeZone.UTC); }//from ww w . ja va 2 s.co m if (dateTimeZone.isStandardOffset(firstDSTTransitionInstant)) { return systemTimeFromInstant(secondDSTTransitionInstant, dateTimeZone); } return systemTimeFromInstant(firstDSTTransitionInstant, dateTimeZone); }