Example usage for org.apache.commons.lang.time DateUtils toCalendar

List of usage examples for org.apache.commons.lang.time DateUtils toCalendar

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils toCalendar.

Prototype

public static Calendar toCalendar(Date date) 

Source Link

Document

Convert a Date into a Calendar .

Usage

From source file:com.sammyun.util.DateUtil.java

/**
 * ? date yyyy-MM-dd?// ww w. j a  v  a2 s  .  c  o  m
 * 
 * @param date
 * @param listDate
 * @return ?
 * @throws ParseException
 */
public static List<Date> getSubtraction(Date date, List<Date> singleDate) throws ParseException {
    List<Date> listDate = new ArrayList<Date>();
    Calendar calendar = DateUtils.toCalendar(date);
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH) + 1;
    int maxDay = calendar.get(Calendar.DAY_OF_MONTH);
    if (DateUtil.isEqualYM(date)) {
        for (int day = 1; day < maxDay; day++) {
            Boolean isday = true;
            for (Date sDate : singleDate) {
                if (DateUtils.toCalendar(sDate).get(Calendar.DAY_OF_MONTH) == day) {
                    isday = false;
                }
            }
            if (isday) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date lDate = simpleDateFormat.parse(year + "-" + month + "-" + day);
                listDate.add(lDate);
            }
        }
    } else {
        for (int day = 1; day <= maxDay; day++) {
            Boolean isday = true;
            for (Date sDate : singleDate) {
                if (DateUtils.toCalendar(sDate).get(Calendar.DAY_OF_MONTH) == day) {
                    isday = false;
                }
            }
            if (isday) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date lDate = simpleDateFormat.parse(year + "-" + month + "-" + day);
                listDate.add(lDate);
            }
        }
    }
    return listDate;
}

From source file:ch.algotrader.simulation.SimulationExecutorImpl.java

private SimulationResultVO getSimulationResultVO(final long startTime) {

    SimulationResultVO resultVO = new SimulationResultVO();
    resultVO.setMins(((double) (System.currentTimeMillis() - startTime)) / 60000);

    Engine engine = this.serverEngine;
    if (!engine.isDeployed("INSERT_INTO_PERFORMANCE_KEYS")) {
        resultVO.setAllTrades(new TradesVO(0, 0, 0, 0));
        return resultVO;
    }//from w  w  w.ja v a  2s .c o  m

    @SuppressWarnings("unchecked")
    List<PeriodPerformanceVO> monthlyPerformances = engine.getAllEvents("KEEP_MONTHLY_PERFORMANCE");
    if (monthlyPerformances.size() == 0) {
        resultVO.setAllTrades(new TradesVO(0, 0, 0, 0));
        return resultVO;
    }

    PerformanceKeysVO performanceKeys = (PerformanceKeysVO) engine.getLastEvent("INSERT_INTO_PERFORMANCE_KEYS");
    MaxDrawDownVO maxDrawDown = (MaxDrawDownVO) engine.getLastEvent("INSERT_INTO_MAX_DRAW_DOWN");
    TradesVO allTrades = (TradesVO) engine.getLastEvent("INSERT_INTO_ALL_TRADES");
    TradesVO winningTrades = (TradesVO) engine.getLastEvent("INSERT_INTO_WINNING_TRADES");
    TradesVO losingTrades = (TradesVO) engine.getLastEvent("INSERT_INTO_LOOSING_TRADES");

    // increase last monthlyPerformance date by one month
    PeriodPerformanceVO lastMonthlyPerformance = monthlyPerformances.get(monthlyPerformances.size() - 1);
    Date lastMonthlyPerformanceDate = DateUtils.addMonths(lastMonthlyPerformance.getDate(), 1);
    lastMonthlyPerformance.setDate(lastMonthlyPerformanceDate);

    // compile yearly performance
    List<PeriodPerformanceVO> yearlyPerformances = null;
    Date lastDate = null;
    if (monthlyPerformances.size() != 0) {
        yearlyPerformances = new ArrayList<PeriodPerformanceVO>();
        double currentPerformance = 1.0;
        for (PeriodPerformanceVO monthlyPerformance : monthlyPerformances) {
            if (lastDate != null && DateUtils.toCalendar(monthlyPerformance.getDate())
                    .get(Calendar.YEAR) != DateUtils.toCalendar(lastDate).get(Calendar.YEAR)) {
                PeriodPerformanceVO yearlyPerformance = new PeriodPerformanceVO();
                yearlyPerformance.setDate(lastDate);
                yearlyPerformance.setValue(currentPerformance - 1.0);
                yearlyPerformances.add(yearlyPerformance);
                currentPerformance = 1.0;
            }
            currentPerformance *= 1.0 + monthlyPerformance.getValue();
            lastDate = monthlyPerformance.getDate();
        }

        if (DateUtils.toCalendar(lastMonthlyPerformance.getDate()).get(Calendar.MONTH) != 11) {
            PeriodPerformanceVO yearlyPerformance = new PeriodPerformanceVO();
            yearlyPerformance.setDate(lastMonthlyPerformance.getDate());
            yearlyPerformance.setValue(currentPerformance - 1.0);
            yearlyPerformances.add(yearlyPerformance);
        }
    }

    // assemble the result
    resultVO.setDataSet(this.commonConfig.getDataSet());
    resultVO.setNetLiqValue(this.portfolioService.getNetLiqValueDouble());
    resultVO.setMonthlyPerformances(monthlyPerformances);
    resultVO.setYearlyPerformances(yearlyPerformances);
    resultVO.setPerformanceKeys(performanceKeys);
    resultVO.setMaxDrawDown(maxDrawDown);
    resultVO.setAllTrades(allTrades);
    resultVO.setWinningTrades(winningTrades);
    resultVO.setLoosingTrades(losingTrades);

    // get potential strategy specific results
    Map<String, Object> strategyResults = new HashMap<>();
    for (SimulationResultsProducer resultsProducer : this.applicationContext
            .getBeansOfType(SimulationResultsProducer.class).values()) {
        strategyResults.putAll(resultsProducer.getSimulationResults());
    }
    resultVO.setStrategyResults(strategyResults);

    return resultVO;
}

From source file:org.jahia.services.content.AutoSplittingIT.java

private static void createEvent(JCRNodeWrapper node, final String eventType, String location, Date date, int i)
        throws RepositoryException {
    final String name = eventType + i;
    final JCRNodeWrapper event = node.addNode(name, "jnt:event");
    event.setProperty("jcr:title", name);
    event.setProperty("eventsType", eventType);
    event.setProperty("location", location);
    event.setProperty("startDate", DateUtils.toCalendar(date));
}