Example usage for org.joda.time DateMidnight DateMidnight

List of usage examples for org.joda.time DateMidnight DateMidnight

Introduction

In this page you can find the example usage for org.joda.time DateMidnight DateMidnight.

Prototype

public DateMidnight() 

Source Link

Document

Constructs an instance set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:com.liteoc.logic.expressionTree.OpenClinicaVariableNode.java

License:LGPL

private String testCalculateVariable() {
    if (number.equals("_CURRENT_DATE")) {
        DateMidnight dm = new DateMidnight();
        DateTimeFormatter fmt = ISODateTimeFormat.date();
        return fmt.print(dm);
    }//from w  w  w .j  a v  a  2  s. c o  m
    return null;
}

From source file:com.naver.mage4j.core.util.PhpDateUtils.java

License:Open Source License

public static Date parseDate(String dateString, boolean reverseInterpretDate) {
    if (StringUtils.isBlank(dateString)) {
        return null;
    }/*from w w w . j a  va 2  s  .  c  o  m*/

    if (dateString.equals("0")) {
        return new DateMidnight().toDate();
    } else if (dateString.startsWith("-")) {
        return new DateMidnight().minusDays(Integer.parseInt(dateString.substring(1))).toDate();
    } else if (dateString.startsWith("+")) {
        return new DateMidnight().plusDays(Integer.parseInt(dateString.substring(1))).toDate();
    }

    Calendar calendar = Calendar.getInstance();
    String[] dateStrings = dateString.trim().split(" |T");
    if (dateStrings.length == 1) {
        if (dateString.contains(":")) {
            setTime(calendar, dateStrings[0]);
        } else {
            setDate(calendar, dateStrings[0], reverseInterpretDate);
            clearTime(calendar);
        }
    } else if (dateStrings.length == 2) {
        setDate(calendar, dateStrings[0], reverseInterpretDate);
        setTime(calendar, dateStrings[1]);
    } else {
        throw new IllegalArgumentException();
    }

    return calendar.getTime();
}

From source file:com.netflix.ice.basic.BasicReservationService.java

License:Apache License

private void pollAPI() throws Exception {
    long currentTime = new DateMidnight().getMillis();

    DescribeReservedInstancesOfferingsRequest req = new DescribeReservedInstancesOfferingsRequest().withFilters(
            new com.amazonaws.services.ec2.model.Filter().withName("marketplace").withValues("false"));
    String token = null;// w ww  .j a  va 2s.c o  m
    boolean hasNewPrice = false;
    AmazonEC2Client ec2Client = new AmazonEC2Client(AwsUtils.awsCredentialsProvider, AwsUtils.clientConfig);

    for (Region region : Region.getAllRegions()) {
        ec2Client.setEndpoint("ec2." + region.name + ".amazonaws.com");
        do {
            if (!StringUtils.isEmpty(token))
                req.setNextToken(token);
            DescribeReservedInstancesOfferingsResult offers = ec2Client.describeReservedInstancesOfferings(req);
            token = offers.getNextToken();

            for (ReservedInstancesOffering offer : offers.getReservedInstancesOfferings()) {
                if (offer.getProductDescription().indexOf("Amazon VPC") >= 0)
                    continue;
                ReservationUtilization utilization = ReservationUtilization.get(offer.getOfferingType());
                Ec2InstanceReservationPrice.ReservationPeriod term = offer.getDuration() / 24 / 3600 > 366
                        ? Ec2InstanceReservationPrice.ReservationPeriod.threeyear
                        : Ec2InstanceReservationPrice.ReservationPeriod.oneyear;
                if (term != this.term)
                    continue;

                double hourly = offer.getUsagePrice();
                if (hourly <= 0) {
                    for (RecurringCharge recurringCharge : offer.getRecurringCharges()) {
                        if (recurringCharge.getFrequency().equals("Hourly")) {
                            hourly = recurringCharge.getAmount();
                            break;
                        }
                    }
                }
                UsageType usageType = getUsageType(offer.getInstanceType(), offer.getProductDescription());
                hasNewPrice = setPrice(utilization, currentTime,
                        Zone.getZone(offer.getAvailabilityZone()).region, usageType, offer.getFixedPrice(),
                        hourly) || hasNewPrice;

                logger.info("Setting RI price for " + Zone.getZone(offer.getAvailabilityZone()).region + " "
                        + utilization + " " + usageType + " " + offer.getFixedPrice() + " " + hourly);
            }
        } while (!StringUtils.isEmpty(token));
    }

    ec2Client.shutdown();
    if (hasNewPrice) {
        for (ReservationUtilization utilization : files.keySet()) {
            File file = files.get(utilization);
            DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
            try {
                Serializer.serialize(out, this.ec2InstanceReservationPrices.get(utilization));
                AwsUtils.upload(config.workS3BucketName, config.workS3BucketPrefix, file);
            } finally {
                out.close();
            }
        }
    }
}

From source file:com.pacoapp.paco.model.ExperimentProviderUtil.java

License:Open Source License

public List<Long> getJoinedExperimentServerIds() {
    List<Experiment> joinedExperiments = getJoinedExperiments();

    List<Experiment> stillRunningExperiments = Lists.newArrayList();
    DateMidnight tonightMidnight = new DateMidnight().plusDays(1);
    DateTime now = DateTime.now();//from w ww  . j a  v a  2 s  . c  o m
    for (Experiment experiment : joinedExperiments) {

        final ExperimentDAO experimentDAO = experiment.getExperimentDAO();
        if (experimentDAO != null && !ActionScheduleGenerator.isOver(now, experimentDAO)) {
            stillRunningExperiments.add(experiment);
        }
    }
    List<Long> experimentIds = Lists.transform(stillRunningExperiments, new Function<Experiment, Long>() {
        public Long apply(Experiment experiment) {
            return experiment.getServerId();
        }
    });
    return experimentIds;
}

From source file:com.sapienter.jbilling.server.order.db.OrderLineDAS.java

License:Open Source License

/**
 * Returns a list of all active and finished one time orders going back n number
 * of months, containing the given item id for the given user.
 *
 * @param userId user id of orders/*from  ww  w  .  j a  v a 2  s.  c om*/
 * @param itemId item id of order lines
 * @param months previous number of months to include (1 = this month plus the previous)
 * @return list of found one-time orders, empty list if none found
 */
@SuppressWarnings("unchecked")
public List<OrderLineDTO> findOnetimeByUserItem(Integer userId, Integer itemId, Integer months) {
    final String hql = "select line " + "  from OrderLineDTO line " + "where line.deleted = 0 "
            + "  and line.item.id = :itemId " + "  and line.purchaseOrder.baseUserByUserId.id = :userId "
            + "  and line.purchaseOrder.orderPeriod.id = :period "
            + "  and (line.purchaseOrder.orderStatus.id = :active_status"
            + "       or line.purchaseOrder.orderStatus.id = :finished_status)"
            + "  and line.purchaseOrder.deleted = 0 " + "  and line.purchaseOrder.createDate > :startdate";

    Query query = getSession().createQuery(hql);
    query.setParameter("itemId", itemId);
    query.setParameter("userId", userId);
    query.setParameter("period", Constants.ORDER_PERIOD_ONCE);
    query.setParameter("active_status", Constants.ORDER_STATUS_ACTIVE);
    query.setParameter("finished_status", Constants.ORDER_STATUS_FINISHED);

    DateMidnight startdate = new DateMidnight().minusMonths(months);
    query.setParameter("startdate", startdate.toDate());

    return query.list();
}

From source file:com.sapienter.jbilling.server.order.db.OrderLineDAS.java

License:Open Source License

/**
 * Returns a list of all active and finished one-time orders going back n number
 * of months, for all direct immediate of the given parent user id. This is useful for
 * determining usage across all child users.
 *
 * @param parentUserId parent user id/*from w  w w .  ja v  a2  s .  c om*/
 * @param itemId item id of order lines
 * @param months previous number of months to include (1 = 1 month period starting from today)
 * @return list of found one-time orders, empty list if none found
 */
@SuppressWarnings("unchecked")
public List<OrderLineDTO> findOnetimeByParentUserItem(Integer parentUserId, Integer itemId, Integer months) {
    UserDTO parent = new UserBL(parentUserId).getEntity();
    if (parent == null || parent.getCustomer() == null) {
        LOG.warn("Parent user " + parentUserId + " does not exist or is not a customer!");
        return Collections.emptyList();
    }

    final String hql = "select line " + " from OrderLineDTO line " + " where line.deleted = 0 "
            + "  and line.item.id = :itemId "
            + "  and line.purchaseOrder.baseUserByUserId.customer.parent.id = :parentId"
            + "  and line.purchaseOrder.orderPeriod.id = :period "
            + "  and (line.purchaseOrder.orderStatus.id = :active_status"
            + "       or line.purchaseOrder.orderStatus.id = :finished_status)"
            + "  and line.purchaseOrder.deleted = 0 " + "  and line.purchaseOrder.createDate > :startdate ";

    Query query = getSession().createQuery(hql);
    query.setParameter("itemId", itemId);
    query.setParameter("parentId", parent.getCustomer().getId());
    query.setParameter("period", Constants.ORDER_PERIOD_ONCE);
    query.setParameter("active_status", Constants.ORDER_STATUS_ACTIVE);
    query.setParameter("finished_status", Constants.ORDER_STATUS_FINISHED);

    DateMidnight startdate = new DateMidnight().minusMonths(months);
    query.setParameter("startdate", startdate.toDate());

    return query.list();
}

From source file:com.sapienter.jbilling.server.order.UsageBL.java

License:Open Source License

/**
 * Returns the current period end date for this customer. This customer will return
 * end of day today as the end date if the period end date is in the past (can occur
 * if we're processing before the customer's first billing run).
 *
 * @return current period end date/*from w  w  w . j  av  a2 s  .  com*/
 */
public Date getPeriodEnd() {
    // get the last period entry in the list - will be the most recent period
    PeriodOfTime end = usagePeriod.getBillingPeriods().get(usagePeriod.getBillingPeriods().size() - 1);

    // end of day today
    DateMidnight today = new DateMidnight().plusDays(1);

    if (new DateMidnight(end.getEnd().getTime()).isBefore(today)) {
        return today.toDate();
    } else {
        return end.getEnd();
    }
}

From source file:com.stackframe.sarariman.ServiceAgreements.java

License:GNU General Public License

public static Collection<BilledService> getMissingBillings(Sarariman sarariman, int serviceAgreement)
        throws SQLException {
    ServiceAgreement a = ServiceAgreement.lookup(sarariman, serviceAgreement);
    if (a.getPopStart().getDayOfMonth() != 1) {
        throw new AssertionError("not expecting pop start to be on day other than start of month dom="
                + a.getPopStart().getDayOfMonth());
    }//from  w  w w .j a  v a 2s .  c o m

    if (!a.getBillingPeriod().equals("monthly")) {
        throw new AssertionError("not expecting billing period other than monthly");
    }

    DateMidnight now = new DateMidnight();
    DateMidnight endOfThisMonth = new DateMidnight(now.getYear(), now.getMonthOfYear(), 1).plusMonths(1)
            .minusDays(1);
    Set<BilledService> shouldHave = new TreeSet<BilledService>();

    DateMidnight monthStart = a.getPopStart();
    while (true) {
        DateMidnight monthEnd = monthStart.plusMonths(1).minusDays(1);
        BilledService b = new BilledService(-1, a.getID(), monthStart, monthEnd, null);
        shouldHave.add(b);
        monthStart = monthStart.plusMonths(1);
        if (monthStart.isAfter(endOfThisMonth) || monthStart.isAfter(a.getPopEnd())) {
            break;
        }
    }

    List<BilledService> existing = BilledService.lookupByServiceAgreement(sarariman, serviceAgreement);
    shouldHave.removeAll(existing);
    return shouldHave;
}

From source file:com.thingsee.tracker.libs.SmartDateTimeUtil.java

License:Apache License

private static boolean isToday(DateTime dateTime) {
    DateMidnight today = new DateMidnight();
    return today.equals(dateTime.toDateMidnight());
}

From source file:com.thingsee.tracker.libs.SmartDateTimeUtil.java

License:Apache License

private static boolean isYesterday(DateTime dateTime) {
    DateMidnight yesterday = (new DateMidnight()).minusDays(1);
    return yesterday.equals(dateTime.toDateMidnight());
}