List of usage examples for org.joda.time DateTime toDateTime
public DateTime toDateTime(Chronology chronology)
this
if possible. From source file:org.killbill.billing.entitlement.api.EntitlementDateHelper.java
License:Apache License
public DateTime fromLocalDateAndReferenceTime(final LocalDate requestedDate, final DateTime referenceDateTime, final InternalTenantContext callContext) throws EntitlementApiException { try {/*ww w.jav a 2s . com*/ final Account account = accountApi.getAccountByRecordId(callContext.getAccountRecordId(), callContext); return ClockUtil.computeDateTimeWithUTCReferenceTime(requestedDate, referenceDateTime.toDateTime(DateTimeZone.UTC).toLocalTime(), account.getTimeZone(), clock); } catch (AccountApiException e) { throw new EntitlementApiException(e); } }
From source file:org.killbill.billing.junction.plumbing.billing.BillCycleDayCalculator.java
License:Apache License
@VisibleForTesting int calculateBcdFromSubscription(final SubscriptionBase subscription, final Plan plan, final Account account, final Catalog catalog, final InternalCallContext context) throws AccountApiException, CatalogApiException { // Retrieve the initial phase type for that subscription // TODO - this should be extracted somewhere, along with this code above final PhaseType initialPhaseType; final List<EffectiveSubscriptionInternalEvent> transitions = subscriptionApi.getAllTransitions(subscription, context);/*from w ww . ja va 2s . co m*/ if (transitions.size() == 0) { initialPhaseType = null; } else { final DateTime requestedDate = subscription.getStartDate(); final String initialPhaseString = transitions.get(0).getNextPhase(); if (initialPhaseString == null) { initialPhaseType = null; } else { final PlanPhase initialPhase = catalog.findPhase(initialPhaseString, requestedDate, subscription.getStartDate()); if (initialPhase == null) { initialPhaseType = null; } else { initialPhaseType = initialPhase.getPhaseType(); } } } final DateTime date = plan.dateOfFirstRecurringNonZeroCharge(subscription.getStartDate(), initialPhaseType); final int bcdUTC = date.toDateTime(DateTimeZone.UTC).getDayOfMonth(); final int bcdLocal = date.toDateTime(account.getTimeZone()).getDayOfMonth(); log.info("Calculated BCD: subscription id {}, subscription start {}, timezone {}, bcd UTC {}, bcd local {}", subscription.getId(), date.toDateTimeISO(), account.getTimeZone(), bcdUTC, bcdLocal); return bcdLocal; }
From source file:org.killbill.clock.ClockUtil.java
License:Apache License
/** * The method will convert the provided LocalDate into an instant (DateTime). * The conversion will use a reference time that should be interpreted from a UTC standpoint. * * The the provided LocalDate overlaps with the present, the current point in time is returned (to make sure we don't * end up with future instant)./* ww w.j a v a 2 s.c o m*/ * * If not, we use both the provide LocalDate and LocalTime to return the DateTime in UTC * * @param inputDateInTargetTimeZone The input LocalDate as interpreted in the specified targetTimeZone * @param inputTimeInUTCTimeZone The referenceTime in UTC * @param targetTimeZone The target timeZone * @param clock The current clock * @return */ public static DateTime computeDateTimeWithUTCReferenceTime(final LocalDate inputDateInTargetTimeZone, final LocalTime inputTimeInUTCTimeZone, final DateTimeZone targetTimeZone, final Clock clock) { final Interval interval = inputDateInTargetTimeZone.toInterval(targetTimeZone); // If the input date overlaps with the present, we return NOW. if (interval.contains(clock.getUTCNow())) { return clock.getUTCNow(); } // If not, we convert the inputTimeInUTCTimeZone -> inputTimeInTargetTimeZone, compute the resulting DateTime in targetTimeZone, and convert into a UTC DateTime: final LocalTime inputTimeInTargetTimeZone = inputTimeInUTCTimeZone .plusMillis(targetTimeZone.getOffset(clock.getUTCNow())); final DateTime resultInTargetTimeZone = new DateTime(inputDateInTargetTimeZone.getYear(), inputDateInTargetTimeZone.getMonthOfYear(), inputDateInTargetTimeZone.getDayOfMonth(), inputTimeInTargetTimeZone.getHourOfDay(), inputTimeInTargetTimeZone.getMinuteOfHour(), inputTimeInTargetTimeZone.getSecondOfMinute(), targetTimeZone); return resultInTargetTimeZone.toDateTime(DateTimeZone.UTC); }
From source file:org.kuali.kpme.core.util.TKUtils.java
License:Educational Community License
public static List<Interval> createDaySpan(DateTime beginDateTime, DateTime endDateTime, DateTimeZone zone) { beginDateTime = beginDateTime.toDateTime(zone); endDateTime = endDateTime.toDateTime(zone); List<Interval> dayIntervals = new ArrayList<Interval>(); DateTime currDateTime = beginDateTime; while (currDateTime.isBefore(endDateTime)) { DateTime prevDateTime = currDateTime; currDateTime = currDateTime.plusDays(1); Interval daySpan = new Interval(prevDateTime, currDateTime); dayIntervals.add(daySpan);//from w ww . j a va2s .c om } return dayIntervals; }
From source file:org.n52.sos.ext.deleteobservation.DeleteObservationDAO.java
License:Open Source License
private AbstractObservation getObservationCriteriaFor(String procedure, String observableProperty, DateTime resultTime, Session session) { resultTime = resultTime.toDateTime(DateTimeZone.UTC); Date date = new Date(resultTime.getMillis()); Criteria criteria;/*www . j a v a 2 s. c o m*/ if (HibernateHelper.isEntitySupported(SeriesObservation.class, session)) { criteria = session.createCriteria(SeriesObservation.class) .add(Restrictions.eq(AbstractObservation.RESULT_TIME, date)); Criteria seriesCriteria = criteria.createCriteria(SeriesObservation.SERIES); seriesCriteria.createCriteria(AbstractObservation.PROCEDURE).add(eq(Procedure.IDENTIFIER, procedure)); seriesCriteria.createCriteria(Series.OBSERVABLE_PROPERTY) .add(eq(ObservableProperty.IDENTIFIER, observableProperty)); } else { criteria = session.createCriteria(Observation.class) .add(Restrictions.eq(AbstractObservation.RESULT_TIME, date)); criteria.createCriteria(AbstractObservation.PROCEDURE).add(eq(Procedure.IDENTIFIER, procedure)); criteria.createCriteria(AbstractObservation.OBSERVABLE_PROPERTY) .add(eq(ObservableProperty.IDENTIFIER, observableProperty)); } LOGGER.debug("QUERY getCriteria(): {}", HibernateHelper.getSqlString(criteria)); return (AbstractObservation) criteria.uniqueResult(); }
From source file:org.n52.svalbard.encode.UVFEncoder.java
License:Apache License
private DateTime checkTimeZone(DateTime time) { if (timeZone != null) { return time.toDateTime(timeZone); }/*from w w w .j av a 2 s . c o m*/ return time; }
From source file:org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.java
License:Apache License
/** * Creates a {@link Timestamp} object from the given string. * @param s//from www . j a v a 2s. c o m * String of the pattern <code>YYYY[MM[DD[HH[MM[SS[.S[S[S[S]]]]]]]]][+/-ZZZZ]</code>. * Milliseconds will be ignored. * @return * a {@link Timestamp} object, or <code>null</code> if the parameter is <code>null</code> or empty. */ public static Timestamp fromHL7(String s) { if (StringUtils.isEmpty(s)) { return null; } int pos = Math.max(s.indexOf('-'), s.indexOf('+')); int len = (pos >= 0) ? pos : s.length(); // determine precision Precision precision; if (len >= 14) { precision = Precision.SECOND; } else if (len >= 12) { precision = Precision.MINUTE; } else if (len >= 10) { precision = Precision.HOUR; } else if (len >= 8) { precision = Precision.DAY; } else if (len >= 6) { precision = Precision.MONTH; } else { precision = Precision.YEAR; } // default time zone is UTC if (pos < 0) { s += "+0000"; } // parse timestamp try { CommonTS ts = new CommonTS(s); DateTime dateTime = new DateTime(ts.getYear(), (ts.getMonth() == 0) ? 1 : ts.getMonth(), (ts.getDay() == 0) ? 1 : ts.getDay(), ts.getHour(), ts.getMinute(), ts.getSecond(), DateTimeZone.forOffsetHoursMinutes(ts.getGMTOffset() / 100, ts.getGMTOffset() % 100)); return new Timestamp(dateTime.toDateTime(DateTimeZone.UTC), precision); } catch (DataTypeException e) { throw new XDSMetaDataException(ValidationMessage.INVALID_TIME, s); } }
From source file:org.openehealth.ipf.commons.ihe.xds.core.metadata.Timestamp.java
License:Apache License
public void setDateTime(DateTime dateTime) { this.dateTime = (dateTime != null) ? dateTime.toDateTime(DateTimeZone.UTC) : null; }
From source file:org.openhab.binding.plugwise.protocol.ClockSetRequestMessage.java
License:Open Source License
public ClockSetRequestMessage(String MAC, DateTime stamp) { super(MAC, ""); type = MessageType.CLOCK_SET_REQUEST; // Circles expect clock info to be in the UTC timezone this.stamp = stamp.toDateTime(DateTimeZone.UTC); }
From source file:org.opensaml.saml.metadata.resolver.impl.AbstractDynamicMetadataResolver.java
License:Open Source License
/** * Compute the effective expiration time for the specified metadata. * /*from w w w . j a v a2 s .c o m*/ * @param entityDescriptor the EntityDescriptor instance to evaluate * @param now the current date time instant * @return the effective expiration time for the metadata */ @Nonnull protected DateTime computeExpirationTime(@Nonnull final EntityDescriptor entityDescriptor, @Nonnull final DateTime now) { DateTime lowerBound = now.toDateTime(ISOChronology.getInstanceUTC()).plus(getMinCacheDuration()); DateTime expiration = SAML2Support.getEarliestExpiration(entityDescriptor, now.plus(getMaxCacheDuration()), now); if (expiration.isBefore(lowerBound)) { expiration = lowerBound; } return expiration; }