/** * Converts this object to a DateTime using a LocalTime to fill in the * missing fields and using the default time zone. * <p> * The resulting chronology is determined by the chronology of this * LocalDate. The chronology of the time must match. * <p> * If the time is null, this method delegates to {@link #toDateTimeAtCurrentTime(DateTimeZone)} * and the following documentation does not apply. * <p> * When the time zone is applied, the local date-time may be affected by daylight saving. * In a daylight saving gap, when the local time does not exist, * this method will throw an exception. * In a daylight saving overlap, when the same local time occurs twice, * this method returns the first occurrence of the local time. * <p> * This instance is immutable and unaffected by this method call. * * @param time the time of day to use, null uses current time * @return the DateTime instance * @throws IllegalArgumentException if the chronology of the time does not match * @throws IllegalInstantException if the local time does not exist when the time zone is applied */ public DateTime toDateTime(LocalTime time) { return toDateTime(time, null); }
/** * Converts this object to a DateTime using a LocalTime to fill in the * missing fields and using the default time zone. * <p> * The resulting chronology is determined by the chronology of this * LocalDate. The chronology of the time must match. * <p> * If the time is null, this method delegates to {@link #toDateTimeAtCurrentTime(DateTimeZone)} * and the following documentation does not apply. * <p> * When the time zone is applied, the local date-time may be affected by daylight saving. * In a daylight saving gap, when the local time does not exist, * this method will throw an exception. * In a daylight saving overlap, when the same local time occurs twice, * this method returns the first occurrence of the local time. * <p> * This instance is immutable and unaffected by this method call. * * @param time the time of day to use, null uses current time * @return the DateTime instance * @throws IllegalArgumentException if the chronology of the time does not match * @throws IllegalInstantException if the local time does not exist when the time zone is applied */ public DateTime toDateTime(LocalTime time) { return toDateTime(time, null); }
/** * Converts this object to a DateTime using a LocalTime to fill in the * missing fields and using the default time zone. * <p> * The resulting chronology is determined by the chronology of this * LocalDate. The chronology of the time must match. * If the time is null, the current time in the date's chronology is used. * <p> * This method will throw an exception if the datetime that would be * created does not exist when the time zone is taken into account. * <p> * This instance is immutable and unaffected by this method call. * * @param time the time of day to use, null means current time * @return the DateTime instance * @throws IllegalArgumentException if the chronology of the time does not match */ public DateTime toDateTime(LocalTime time) { return toDateTime(time, null); }
@Test(groups = "slow") public void testCreateWithRequestedDate() throws SubscriptionBaseApiException { final LocalDate init = clock.getUTCToday(); final LocalDate requestedDate = init.minusYears(1); final String productName = "Shotgun"; final BillingPeriod term = BillingPeriod.MONTHLY; final String planSetName = PriceListSet.DEFAULT_PRICELIST_NAME; testListener.pushExpectedEvent(NextEvent.PHASE); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, productName, term, planSetName, requestedDate); assertNotNull(subscription); // // In addition to Alignment phase we also test SubscriptionBaseTransition eventIds and created dates. // Keep tracks of row events to compare with ids and created dates returned by SubscriptionBaseTransition later. // final List<SubscriptionBaseEvent> events = subscription.getEvents(); Assert.assertEquals(events.size(), 2); final SubscriptionBaseEvent trialEvent = events.get(0); final SubscriptionBaseEvent phaseEvent = events.get(1); assertEquals(subscription.getBundleExternalKey(), bundle.getExternalKey()); assertEquals(subscription.getStartDate().compareTo(requestedDate.toDateTime(accountData.getReferenceTime())), 0); assertListenerStatus(); final SubscriptionBaseTransition transition = subscription.getPreviousTransition(); assertEquals(transition.getPreviousEventId(), trialEvent.getId()); assertEquals(transition.getNextEventId(), phaseEvent.getId()); assertEquals(transition.getPreviousEventCreatedDate().compareTo(trialEvent.getCreatedDate()), 0); assertEquals(transition.getNextEventCreatedDate().compareTo(phaseEvent.getCreatedDate()), 0); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription3() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); subscription.cancelWithPolicy(BillingActionPolicy.IMMEDIATE, callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription1() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); // The code will be smart to infer the cancelation date as being the future startDate subscription.cancel(callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
@Test(groups = "slow") public void testCancelPlanOnPendingSubscription2() throws SubscriptionBaseApiException { final String baseProduct = "Shotgun"; final BillingPeriod baseTerm = BillingPeriod.MONTHLY; final String basePriceList = PriceListSet.DEFAULT_PRICELIST_NAME; final LocalDate startDate = clock.getUTCToday().plusDays(5); final DefaultSubscriptionBase subscription = testUtil.createSubscription(bundle, baseProduct, baseTerm, basePriceList, startDate); assertEquals(subscription.getState(), Entitlement.EntitlementState.PENDING); assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0); try { subscription.cancelWithDate(null, callContext); fail("Cancel plan should have failed : subscription PENDING"); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode()); } try { subscription.cancelWithDate(subscription.getStartDate().minusDays(1), callContext); fail("Cancel plan should have failed : subscription PENDING"); } catch (SubscriptionBaseApiException e) { assertEquals(e.getCode(), ErrorCode.SUB_INVALID_REQUESTED_DATE.getCode()); } subscription.cancelWithDate(subscription.getStartDate(), callContext); testListener.pushExpectedEvents(NextEvent.CREATE, NextEvent.CANCEL); clock.addDays(5); assertListenerStatus(); final DefaultSubscriptionBase subscription2 = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext); assertEquals(subscription2.getStartDate().compareTo(subscription.getStartDate()), 0); assertEquals(subscription2.getState(), Entitlement.EntitlementState.CANCELLED); assertNull(subscription2.getCurrentPlan()); }
assertEquals(subscription.getStartDate().compareTo(startDate.toDateTime(accountData.getReferenceTime())), 0);
public MockDateTimeSource(LocalDate localDate) { this(localDate.toDateTime(LocalTime.MIDNIGHT)); }
LocalDate date = new LocalDate(); LocalTime time = LocalTime.MIDNIGHT; DateTimeZone zone = DateTimeZone.getDefault(); Instant instant = date.toDateTime(time, zone).toInstant();
public void setEndTime(LocalTime endTime) { DateTime dateTime = new DateTime(endTimestamp); LocalDate localDate = new LocalDate(endTimestamp); endTimestamp = new Timestamp(localDate.toDateTime(endTime, dateTime.getZone()).getMillis()); }
LocalDate localDate = new LocalDate().withMonthOfYear(3).withDayOfMonth(10); LocalTime localTime = new LocalTime().withHourOfDay(2); DateTime dateTime = localDate.toDateTime(localTime, DateTimeZone.UTC); DateTime dt = new DateTime(DateTimeZone.UTC.getMillisKeepLocal(DateTimeZone.getDefault(), dateTime.getMillis())); System.out.println(dateTime); System.out.println(dt);
public static String CalculateUTC_Time(String Date, String Time) { String X[] = Time.split(":"); int Hours = Integer.parseInt(X[0]); int Minutes = Integer.parseInt(X[1]); LocalDate date = new LocalDate(Date); LocalTime time = new LocalTime(Hours, Minutes); DateTime dt = date.toDateTime(time); SimpleDateFormat f2 = new SimpleDateFormat("HH:mm"); f2.setTimeZone(TimeZone.getTimeZone("UTC")); return (f2.format(dt.toDate())); }
@Nonnull public Cell addCell (@Nonnull final LocalDate aValue, @Nullable final ExcelStyle aStyle) { return addCell (aValue.toDateTime (CPDT.NULL_LOCAL_TIME), aStyle); }
public void setBeginTime(LocalTime beginTime) { DateTime dateTime = new DateTime(beginTimestamp); LocalDate localDate = new LocalDate(beginTimestamp); //LocalTime localTime = new LocalTime(beginTime); beginTimestamp = new Timestamp(localDate.toDateTime(beginTime, dateTime.getZone()).getMillis()); }
public void setBeginDate(Date beginDate) { DateTime dateTime = new DateTime(beginTimestamp); LocalDate localDate = new LocalDate(beginDate); LocalTime localTime = new LocalTime(beginTimestamp); beginTimestamp = new Timestamp(localDate.toDateTime(localTime, dateTime.getZone()).getMillis()); }
public void setEndDate(Date endDate) { DateTime dateTime = new DateTime(endTimestamp); LocalDate localDate = new LocalDate(endDate); LocalTime localTime = new LocalTime(endTimestamp); endTimestamp = new Timestamp(localDate.toDateTime(localTime, dateTime.getZone()).getMillis()); }
public void setBeginDate(Date beginDate) { DateTime dateTime = new DateTime(beginTimestamp); LocalDate localDate = new LocalDate(beginDate); LocalTime localTime = new LocalTime(beginTimestamp); beginTimestamp = new Timestamp(localDate.toDateTime(localTime, dateTime.getZone()).getMillis()); }
public DateTime fromLocalDateAndReferenceTime(final LocalDate requestedDate, final DateTime referenceDateTime, final DateTimeZone accountTimeZone) { final LocalDate localDateNowInAccountTimezone = new LocalDate(requestedDate, accountTimeZone); // Datetime from local date in account timezone and with given reference time final DateTime t1 = localDateNowInAccountTimezone.toDateTime(referenceDateTime.toLocalTime(), accountTimeZone); // Datetime converted back in UTC final DateTime t2 = new DateTime(t1, DateTimeZone.UTC); // // Ok, in the case of a LocalDate of today we expect any change to be immediate, so we check that DateTime returned is not in the future // (which means that reference time might not be honored, but this is not very important). // return adjustDateTimeToNotBeInFutureIfLocaDateIsToday(t2, accountTimeZone); }
public void setActionDate(Date actionDate) { setLocalDate(actionDate != null ? LocalDate.fromDateFields(actionDate) : null); //LocalTime localTime = actionDateTime != null ? LocalTime.fromDateFields(actionDateTime) : LocalTime.MIDNIGHT; if (localDate != null && localTime != null) { actionDateTime = localDate.toDateTime(localTime).toDate(); } }