Example usage for org.joda.time.format DateTimeFormatter parseDateTime

List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter parseDateTime.

Prototype

public DateTime parseDateTime(String text) 

Source Link

Document

Parses a date-time from the given text, returning a new DateTime.

Usage

From source file:org.kuali.kpme.tklm.leave.batch.CarryOverSchedulerJob.java

License:Educational Community License

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    LocalDate asOfDate = LocalDate.now();
    List<LeavePlan> leavePlans = HrServiceLocator.getLeavePlanService()
            .getLeavePlansNeedsCarryOverScheduled(getLeavePlanPollingWindow(), asOfDate);
    try {/*w w w.j  ava  2  s  .c om*/
        if (leavePlans != null && !leavePlans.isEmpty()) {
            DateTime current = asOfDate.toDateTimeAtStartOfDay();
            DateTime windowStart = current.minusDays(getLeavePlanPollingWindow());
            DateTime windowEnd = current.plusDays(getLeavePlanPollingWindow());

            // schedule batch job for all LeavePlans who fall in leave polling window.
            for (LeavePlan leavePlan : leavePlans) {
                if (leavePlan.getBatchPriorYearCarryOverStartDate() != null
                        && leavePlan.getBatchPriorYearCarryOverStartTime() != null) {
                    DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd");
                    DateTime batchPriorYearCarryOverStartDateTime = formatter
                            .parseDateTime(leavePlan.getBatchPriorYearCarryOverStartDate())
                            .plus(leavePlan.getBatchPriorYearCarryOverStartTime().getTime());
                    if (batchPriorYearCarryOverStartDateTime.compareTo(windowStart) >= 0
                            && batchPriorYearCarryOverStartDateTime.compareTo(windowEnd) <= 0) {
                        getBatchJobService().scheduleLeaveCarryOverJobs(leavePlan);
                    }
                }
            }
        }
    } catch (SchedulerException se) {
        LOG.warn("Exception thrown during job scheduling of Carry over for Leave", se);
        //           throw new JobExecutionException("Exception thrown during job scheduling of Carry over for Leave", se);
    }
}

From source file:org.libreplan.importers.tim.TimDateTimeAdapter.java

License:Open Source License

@Override
public DateTime unmarshal(String dateTimeStr) throws Exception {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy HH:mm:ss.SSS");
    return fmt.parseDateTime(dateTimeStr);
}

From source file:org.libreplan.importers.tim.TimLocalDateAdapter.java

License:Open Source License

@Override
public LocalDate unmarshal(String dateStr) throws Exception {
    final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");
    return fmt.parseDateTime(dateStr).toLocalDate();
}

From source file:org.logstash.filters.parser.JodaParser.java

License:Apache License

private Instant parseAndGuessYear(DateTimeFormatter parser, String value) {
    // if we get here, we need to do some special handling at the time each event is handled
    // because things like the current year could be different, etc.
    DateTime dateTime;//from  w  w  w.j a v  a2  s . c o  m
    if (hasZone) {
        dateTime = parser.parseDateTime(value);
    } else {
        dateTime = parser.withZoneUTC().parseLocalDateTime(value).toDateTime(parser.getZone());
    }

    // The time format we have has no year listed, so we'll have to guess the year.
    int month = dateTime.getMonthOfYear();
    DateTime now = clock.read();
    int eventYear;

    if (month == 12 && now.getMonthOfYear() == 1) {
        // Now is January, event is December. Assume it's from last year.
        eventYear = now.getYear() - 1;
    } else if (month == 1 && now.getMonthOfYear() == 12) {
        // Now is December, event is January. Assume it's from next year.
        eventYear = now.getYear() + 1;
    } else {
        // Otherwise, assume it's from this year.
        eventYear = now.getYear();
    }

    return dateTime.withYear(eventYear).toInstant();
}

From source file:org.marketcetera.core.time.TimeFactoryImpl.java

@Override
public DateTime create(String inValue) {
    inValue = StringUtils.trimToNull(inValue);
    Validate.notNull(inValue);//  w  w  w.j  a  va  2  s .  c  o m
    DateTime value = null;
    for (DateTimeFormatter formatter : FORMATTERS) {
        try {
            value = formatter.parseDateTime(inValue);
        } catch (IllegalArgumentException ignored) {
        }
    }
    if (value != null && SECONDS_PATTERN.matcher(inValue).matches()) {
        value = value.plus(new LocalDate().toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis());
    }
    Validate.notNull(value);
    return value;
}

From source file:org.mifos.platform.accounting.ui.controller.AccountingDataController.java

License:Open Source License

@RequestMapping("renderAccountingData.ftl")
public final ModelAndView showAccountingDataFor(@RequestParam(value = FROM_DATE) String paramFromDate,
        @RequestParam(value = TO_DATE) String paramToDate) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
    LocalDate fromDate = fmt.parseDateTime(paramFromDate).toLocalDate();
    LocalDate toDate = fmt.parseDateTime(paramToDate).toLocalDate();
    Boolean hasAlreadyRanQuery = Boolean.FALSE;
    String fileName = null;/*from  w w w.ja  v a 2s.co  m*/

    List<AccountingDto> accountingData = new ArrayList<AccountingDto>();
    try {
        fileName = accountingService.getExportOutputFileName(fromDate, toDate).replace(".xml", "");
        hasAlreadyRanQuery = accountingService.hasAlreadyRanQuery(fromDate, toDate);
        accountingData = accountingService.getExportDetails(fromDate, toDate);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }

    ModelAndView mav = new ModelAndView("renderAccountingData");
    List<BreadCrumbsLinks> breadcrumbs = new AdminBreadcrumbBuilder()
            .withLink("accounting.viewaccountingexports", "renderAccountingDataCacheInfo.ftl")
            .withLink(fileName, "").build();
    mav.addObject("breadcrumbs", breadcrumbs);
    mav.addObject("accountingData", accountingData);
    mav.addObject("hasAlreadyRanQuery", hasAlreadyRanQuery);
    mav.addObject("fileName", fileName);
    mav.addObject("fromDate", fromDate);
    mav.addObject("toDate", toDate);

    return mav;
}

From source file:org.mifos.ui.core.controller.DateTimeUpdateController.java

License:Open Source License

@Override
@RequestMapping("/dateTimeUpdate.ftl")
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
    ModelAndView returnValue = new ModelAndView("pageNotFound");
    if (TestMode.MAIN == getTestingService().getTestMode()) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {//from  ww  w  .j  a v  a2  s. c  om
        String dateTimeString = request.getParameter("dateTime");
        String result = null;
        if (null == dateTimeString) {
            result = "Missing 'dateTime' parameter!";
        } else if ("system".equals(dateTimeString)) {
            getDateTimeService().resetToCurrentSystemDateTime();
            result = getDateTimeService().getCurrentDateTime().toString();
        } else {
            DateTimeFormatter formatter = ISODateTimeFormat.basicDateTimeNoMillis();
            DateTime dateTime = formatter.parseDateTime(dateTimeString);

            getDateTimeService().setCurrentDateTime(dateTime);
            result = dateTime.toString();
        }
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("updateResult", result);
        model.put("request", request);
        Map<String, Object> status = new HashMap<String, Object>();
        List<String> errorMessages = new ArrayList<String>();
        status.put("errorMessages", errorMessages);
        ModelAndView modelAndView = new ModelAndView("dateTimeUpdate", "model", model);
        modelAndView.addObject("status", status);
        returnValue = modelAndView;
    }
    return returnValue;
}

From source file:org.mot.common.math.TechnicalAnalysis.java

License:Open Source License

/**
 * This method is used to retrieve a timeseries from the database and convert it into a TA4J series, so that 
 * further technical analysis can be done. 
 * //  w w w .j a  v  a 2 s  . co  m
 * @param symbol - symbol to search for
 * @param startDate - start date (use pattern: yyyy-MM-dd)
 * @param endDate - end date (use pattern: yyyy-MM-dd)
 * @return a timeseries object
 */
@Cacheable(name = "TechnicalAnalysis", ttl = 600)
public TimeSeries getSeriesByDate(String symbol, String startDate, String endDate) {

    List<String> days = db.getDaysBetweenDates(startDate, endDate, pattern);
    List<Tick> taList = new ArrayList<Tick>();

    DateTimeFormatter formatter = DateTimeFormat.forPattern(pattern);

    // Loop over all days
    Iterator<String> i = days.iterator();
    while (i.hasNext()) {

        String sd = i.next();
        String ed = db.addDaysToDate(sd, pattern, 1);
        logger.trace("Start: " + sd + " - End: " + ed);

        ArrayList<Double> ticks = tpd.getPriceForSymbolByDate(symbol, sd, ed, "BID");

        if (ticks.size() > 0) {

            Double[] values = new Double[ticks.size()];
            values = ticks.toArray(values);

            Decimal open = Decimal.valueOf(ticks.get(0));
            Decimal close = Decimal.valueOf(ticks.get(ticks.size() - 1));
            Decimal high = Decimal.valueOf(cf.getMax(values));
            Decimal low = Decimal.valueOf(cf.getMin(values));

            // Default the volume to 0 for now - we dont listen to volume indication today
            Decimal volume = Decimal.valueOf(0.0);

            DateTime dt = formatter.parseDateTime(sd);

            taList.add(new Tick(dt, open, high, low, close, volume));
        }
    }
    TimeSeries series = new TimeSeries(taList);

    return series;
}

From source file:org.mrgeo.featurefilter.DateColumnFeatureFilter.java

License:Apache License

@Override
public Geometry filterInPlace(Geometry feature) {
    //should have already set a date format by this point for date filtering
    assert (!StringUtils.isEmpty(dateFormat));
    assert (dateFilterGranularity != null);

    feature = super.filterInPlace(feature);
    if (feature == null) {
        return null;
    }/*from  w  ww.  j av  a2s  .  c  o m*/

    try {
        DateTimeFormatter dateFormatter = DateTimeFormat.forPattern(dateFormat);
        DateTime filterDate = dateFormatter.parseDateTime(filterValue);
        DateTime featureAttributeDate = dateFormatter.parseDateTime(featureAttributeValue);
        if (datePassesFilter(featureAttributeDate, filterDate)) {
            return feature;
        }
    } catch (IllegalArgumentException e) {
        //couldn't parse the feature's date
        log.debug("Invalid date: " + featureAttributeValue + " for column: " + filterColumn);
        return null;
    }

    return null;
}

From source file:org.mrgeo.geometry.splitter.TimeSpanGeometrySplitter.java

License:Apache License

private static DateTime getTimeProperty(final Map<String, String> splitterProperties, final String propName,
        final DateTimeFormatter dtf) {
    String strValue = splitterProperties.get(propName);
    DateTime result = null;/*from w  ww.j  a v a 2 s. c  o m*/
    if (strValue == null) {
        throw new IllegalArgumentException("Missing " + propName + " property for time span geometry splitter");
    }
    try {
        result = dtf.parseDateTime(strValue);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Invalid " + propName + " property for time span geometry splitter");
    }
    return result;
}