List of usage examples for org.joda.time DateTime toDateTime
public DateTime toDateTime(Chronology chronology)
this
if possible. From source file:org.opensaml.saml.metadata.resolver.impl.AbstractDynamicMetadataResolver.java
License:Open Source License
/** * Compute the refresh trigger time./*www .ja v a 2s .c o m*/ * * @param expirationTime the time at which the metadata effectively expires * @param nowDateTime the current date time instant * * @return the time after which refresh attempt(s) should be made */ @Nonnull protected DateTime computeRefreshTriggerTime(@Nullable final DateTime expirationTime, @Nonnull final DateTime nowDateTime) { DateTime nowDateTimeUTC = nowDateTime.toDateTime(ISOChronology.getInstanceUTC()); long now = nowDateTimeUTC.getMillis(); long expireInstant = 0; if (expirationTime != null) { expireInstant = expirationTime.toDateTime(ISOChronology.getInstanceUTC()).getMillis(); } long refreshDelay = (long) ((expireInstant - now) * getRefreshDelayFactor()); // if the expiration time was null or the calculated refresh delay was less than the floor // use the floor if (refreshDelay < getMinCacheDuration()) { refreshDelay = getMinCacheDuration(); } return nowDateTimeUTC.plus(refreshDelay); }
From source file:org.opensaml.saml.metadata.resolver.impl.AbstractReloadingMetadataResolver.java
License:Open Source License
/** * Computes the delay until the next refresh time based on the current metadata's expiration time and the refresh * interval floor./* w w w . j a v a 2 s.c o m*/ * * @param expectedExpiration the time when the metadata is expected to expire and need refreshing * * @return delay, in milliseconds, until the next refresh time */ protected long computeNextRefreshDelay(DateTime expectedExpiration) { long now = new DateTime(ISOChronology.getInstanceUTC()).getMillis(); long expireInstant = 0; if (expectedExpiration != null) { expireInstant = expectedExpiration.toDateTime(ISOChronology.getInstanceUTC()).getMillis(); } long refreshDelay = (long) ((expireInstant - now) * getRefreshDelayFactor()); // if the expiration time was null or the calculated refresh delay was less than the floor // use the floor if (refreshDelay < getMinRefreshDelay()) { refreshDelay = getMinRefreshDelay(); } return refreshDelay; }
From source file:org.opensaml.util.storage.AbstractExpiringObject.java
License:Apache License
/** * Constructor./* ww w . ja v a 2 s . c o m*/ * * @param expirationTime time this object should expire */ public AbstractExpiringObject(DateTime expirationTime) { expiration = expirationTime.toDateTime(ISOChronology.getInstanceUTC()).getMillis(); }
From source file:org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.DlmsHelperService.java
License:Open Source License
/** * Creates a COSEM date-time object based on the given {@code dateTime}. * This COSEM date-time will be for the same instant in time as the given * {@code dateTime} but may be for another time zone. * <p>//from ww w . j a v a 2 s . c o m * Because the time zone with the {@code deviation} may be different than * the one with the {@code dateTime}, and the {@code deviation} alone does * not provide sufficient information on whether daylight savings is active * for the given instant in time, {@code dst} has to be provided to indicate * whether daylight savings are active. * <p> * If a DateTime for an instant in time is known with the correct time zone * set, you can use {@link #asDataObject(DateTime)} as a simpler * alternative. * * @param dateTime * a DateTime indicating an instant in time to be used for the * COSEM date-time. * @param deviation * the deviation in minutes of local time to GMT to be included * in the COSEM date-time. * @param dst * {@code true} if daylight savings are active for the instant of * the COSEM date-time, otherwise {@code false}. * @return a DataObject having a CosemDateTime for the instant of the given * DateTime, with the given deviation and DST status information, as * value. */ public DataObject asDataObject(final DateTime dateTime, final int deviation, final boolean dst) { /* * Create a date time that may not point to the right instant in time, * but that will give proper values getting the different fields for the * COSEM date and time objects. */ final DateTime dateTimeWithOffset = dateTime.toDateTime(DateTimeZone.UTC).minusMinutes(deviation); final CosemDate cosemDate = new CosemDate(dateTimeWithOffset.getYear(), dateTimeWithOffset.getMonthOfYear(), dateTimeWithOffset.getDayOfMonth()); final CosemTime cosemTime = new CosemTime(dateTimeWithOffset.getHourOfDay(), dateTimeWithOffset.getMinuteOfHour(), dateTimeWithOffset.getSecondOfMinute(), dateTimeWithOffset.getMillisOfSecond() / 10); final ClockStatus[] clockStatusBits; if (dst) { clockStatusBits = new ClockStatus[1]; clockStatusBits[0] = ClockStatus.DAYLIGHT_SAVING_ACTIVE; } else { clockStatusBits = new ClockStatus[0]; } final CosemDateTime cosemDateTime = new CosemDateTime(cosemDate, cosemTime, deviation, clockStatusBits); return DataObject.newDateTimeData(cosemDateTime); }
From source file:org.solovyev.android.messenger.messages.MessagesMock.java
License:Apache License
@Nonnull public static Message newMockMessage(@Nonnull DateTime sendDate, @Nonnull Entity from, @Nonnull Entity to, @Nonnull String accountId, @Nonnull String chatId) { final Message message = mock(Message.class); final String id = getMessageId(); when(message.getEntity()).thenReturn(newEntity(accountId, id)); when(message.getId()).thenReturn(String.valueOf(id)); when(message.getBody()).thenReturn("body_" + id); when(message.getTitle()).thenReturn("title_" + id); when(message.getAuthor()).thenReturn(from); when(message.getRecipient()).thenReturn(to); when(message.getState()).thenReturn(created); when(message.getSendDate()).thenReturn(sendDate); final DateTime localDateTime = sendDate.toDateTime(DateTimeZone.forTimeZone(TimeZone.getDefault())); when(message.getLocalSendDateTime()).thenReturn(localDateTime); when(message.getLocalSendDate()).thenReturn(localDateTime.toLocalDate()); final MutableAProperties properties = newProperties(Collections.<AProperty>emptyList()); properties.setProperty("property_1", "test"); properties.setProperty("property_2", "42"); when(message.getProperties()).thenReturn(properties); when(message.getChat()).thenReturn(newEntityFromEntityId(chatId)); return message; }
From source file:org.wso2.carbon.bpmn.people.substitution.UserSubstitutionUtils.java
License:Open Source License
private static Date getEndTimeMaxDate() { DateTime dateTime = new DateTime(SubstitutionDataHolder.getInstance().getSubstitutionMaxEpoch(), DateTimeZone.UTC);//from www. j ava 2 s. c om Date maxDate = new Date(dateTime.toDateTime(DateTimeZone.getDefault()).getMillis()); return maxDate; }
From source file:reflex.value.ReflexDateValue.java
License:Open Source License
public String toString(DateTimeFormatter formatter, DateTimeZone zone) { if (formatter == null) return toString(); // Without a corresponding Time value this is somewhat useless. See RAP-4182/RAP-4183 DateTime newDateTime = date.toDateTimeAtStartOfDay(DateTimeZone.UTC); String d = formatter.print(newDateTime.toDateTime((zone == null) ? DateTimeZone.UTC : zone)); return d;/*from ww w. j av a2 s.co m*/ }