List of usage examples for org.joda.time DateTime parse
public static DateTime parse(String str, DateTimeFormatter formatter)
From source file:org.jasig.portlet.cms.model.repository.schedule.ScheduledPostPublisher.java
License:Apache License
private void publishScheduledPostsForRepositoryRoot(final String root) throws JcrRepositoryException { final Collection<Post> scheduledPosts = getRepositoryDao().getScheduledPosts(root); if (scheduledPosts != null && scheduledPosts.size() > 0) for (final Post post : scheduledPosts) { final Calendar cldr = Calendar.getInstance(post.getLocale()); final DateTimeFormatter fmt = DateTimeFormat .forPattern(PortletPreferencesWrapper.DEFAULT_POST_DATE_FORMAT); final DateTime dt = DateTime.parse(post.getScheduledDate(), fmt); final DateTimeZone zone = DateTimeZone.forTimeZone(cldr.getTimeZone()); final DateTime today = new DateTime(zone); if (dt.isEqual(today) || dt.isBefore(today)) { if (logger.isDebugEnabled()) logger.debug("Scheduled for today " + post.getPath() + " at " + post.getScheduledDate()); getRepositoryDao().removePost(post.getPath()); post.setPath(root);// ww w . j a v a 2 s .c o m post.setRateCount(0); post.setRate(0); getRepositoryDao().setPost(post); if (logger.isDebugEnabled()) logger.debug("Published scheduled post " + post.getPath() + " at " + post.getScheduledDate() + " to " + post.getPath()); } } else ScheduledPostsManager.getInstance().removeRepositoryRoot(root); }
From source file:org.jevis.commons.dataprocessing.Options.java
License:Open Source License
/** * Returns the first and last timestamp of an task options * * @param task//from w w w .j a va 2 s .c om * @return */ public static DateTime[] getStartAndEnd(Task task) { DateTime[] result = new DateTime[2]; result[0] = null; result[1] = null; if (task.getOptions().containsKey(TS_START)) { try { result[0] = DateTime.parse(task.getOptions().get(TS_START), DateTimeFormat.forPattern(TS_PATTERN)); } catch (Exception e) { System.out.println("error while parsing " + TS_START + " option"); } } else { System.out.println("No " + TS_START + " option is missing"); } if (task.getOptions().containsKey(TS_END)) { try { result[1] = DateTime.parse(task.getOptions().get(TS_END), DateTimeFormat.forPattern(TS_PATTERN)); } catch (Exception ex) { System.out.println("error while parsing " + TS_END + " option"); } } else { System.out.println("No " + TS_END + " option is missing"); } return result; }
From source file:org.jevis.commons.dataprocessing.ProcessOptions.java
License:Open Source License
/** * Returns the first and last timestamp of an task options * * @param task/*from ww w . ja v a 2s . c o m*/ * @return */ public static DateTime[] getStartAndEnd(Process task) { DateTime[] result = new DateTime[2]; result[0] = null; result[1] = null; if (ContainsOption(task, TS_START)) { try { result[0] = DateTime.parse( GetLatestOption(task, TS_START, new BasicProcessOption(TS_START, "")).getValue(), DateTimeFormat.forPattern(TS_PATTERN)); // result[0] = DateTime.parse(task.getOptions().get(TS_START), DateTimeFormat.forPattern(TS_PATTERN)); } catch (Exception e) { System.out.println("error while parsing " + TS_START + " option"); } } else { System.out.println("No " + TS_START + " option is missing"); } if (ContainsOption(task, TS_END)) { try { result[1] = DateTime.parse( GetLatestOption(task, TS_END, new BasicProcessOption(TS_END, "")).getValue(), DateTimeFormat.forPattern(TS_PATTERN)); // result[1] = DateTime.parse(task.getOptions().get(TS_END), DateTimeFormat.forPattern(TS_PATTERN)); } catch (Exception ex) { System.out.println("error while parsing " + TS_END + " option"); } } else { System.out.println("No " + TS_END + " option is missing"); } return result; }
From source file:org.jevis.commons.dataprocessing.v2.DataProcessing.java
License:Open Source License
public static <T> T GetOptionValue(JEVisOption parent, String key, Object defaultvalue) { try {//from ww w . ja v a2 s. c om System.out.println("Gettring option value '" + key + "' from parent: " + parent.getKey() + " fallback value: '" + defaultvalue + "'"); if (Options.hasOption(key, parent)) { System.out.println("option exist"); String mString = Options.getFirstOption(key, parent).getValue(); if (defaultvalue instanceof Double) { return (T) (Double) Double.parseDouble(mString); } else if (defaultvalue instanceof Integer) { return (T) (Integer) Integer.parseInt(mString); } else if (defaultvalue instanceof String) { return (T) mString; } else if (defaultvalue instanceof DateTime) { DateTime dateTime = DateTime.parse(mString, ISODateTimeFormat.dateTime());//yyyy-MM-dd'T'HH:mm:ss.SSSZZ return (T) dateTime; } else if (defaultvalue instanceof Boolean) { return (T) Boolean.valueOf(mString); } else { System.out.println("Unsupportet Class '" + defaultvalue.getClass() + "' returning String"); return (T) mString; } } else { System.out.println("Paremeter not found returning default"); return (T) defaultvalue; } } catch (Exception ex) { System.out.println("error return default: " + ex); return (T) defaultvalue; } }
From source file:org.jimsey.projects.turbine.fuel.domain.TickJson.java
License:Open Source License
public TickJson(OffsetDateTime date, double open, double high, double low, double close, double volume, String symbol, String market, String timestamp) { super(DateTime.parse(date.toString(), ISODateTimeFormat.dateTimeParser()), open, high, low, close, volume); this.timestamp = date; this.symbol = symbol; this.market = market; try {/*from ww w .ja v a 2s . c om*/ this.date = date.toInstant().toEpochMilli(); } catch (Exception e) { logger.warn("Could not parse date: {}", date.toString()); } try { this.timestamp = OffsetDateTime.parse(timestamp); } catch (Exception e) { logger.warn("Could not parse timestamp: {}", timestamp); } }
From source file:org.jitsi.dnssec.unbound.rpl.RplParser.java
License:Open Source License
public Rpl parse() throws ParseException, IOException { BufferedReader r = new BufferedReader(new InputStreamReader(data)); String line;//from w ww. j a va 2s .c o m ParseState state = ParseState.Zero; Rpl rpl = new Rpl(); Message m = null; int section = -1; int step = -1; Check check = null; while ((line = r.readLine()) != null) { // comment or empty if (line.equals("") || line.startsWith(";")) { continue; } switch (state) { case Zero: if (line.startsWith("server:")) { state = ParseState.Server; } else if (line.startsWith("SCENARIO_BEGIN")) { rpl.scenario = line.substring(line.indexOf(" ")); rpl.replays = new LinkedList<Message>(); rpl.checks = new TreeMap<Integer, Check>(); } else if (line.startsWith("ENTRY_BEGIN")) { state = ParseState.ENTRY_BEGIN; m = new Message(); } else if (line.startsWith("STEP")) { String[] data = line.split("\\s"); step = Integer.parseInt(data[1]); m = new Message(); r.readLine(); if (data[2].equals("QUERY")) { state = ParseState.STEP_QUERY; check = new Check(); } else if (data[2].equals("CHECK_ANSWER")) { state = ParseState.STEP_CHECK_ANSWER; } } break; case Server: if (line.matches("\\s*trust-anchor:.*")) { SRRset rrset = new SRRset(); rrset.setSecurityStatus(SecurityStatus.SECURE); rrset.addRR(parseRecord(line.substring(line.indexOf("\"") + 1, line.length() - 1))); rpl.trustAnchors.add(rrset); } else if (line.matches("\\s*val-override-date:.*")) { rpl.date = DateTime.parse(line.substring(line.indexOf("\"") + 1, line.length() - 2), DateTimeFormat.forPattern("yyyyMMddHHmmss")); } else if (line.matches("\\s*val-nsec3-keysize-iterations:.*")) { String[] data = line.substring(line.indexOf("\"") + 1, line.length() - 1).split("\\s"); if (data.length % 2 != 0) { throw new ParseException("val-nsec3-keysize-iterations invalid", 0); } rpl.nsec3iterations = new TreeMap<Integer, Integer>(); for (int i = 0; i < data.length; i += 2) { rpl.nsec3iterations.put(Integer.parseInt(data[i]), Integer.parseInt(data[i + 1])); } } else if (line.matches("\\s*val-digest-preference:.*")) { rpl.digestPreference = line.substring(line.indexOf("\"") + 1, line.length() - 1); } else if (line.startsWith("CONFIG_END")) { state = ParseState.Zero; } break; case ENTRY_BEGIN: case STEP_CHECK_ANSWER: case STEP_QUERY: if (line.startsWith("MATCH") || line.startsWith("ADJUST")) { // ignore } else if (line.startsWith("REPLY")) { String[] flags = line.split("\\s"); if (state != ParseState.STEP_QUERY) { m.getHeader().setRcode(Rcode.value(flags[flags.length - 1])); } for (int i = 1; i < flags.length - (state == ParseState.STEP_QUERY ? 0 : 1); i++) { if (flags[i].equals("DO")) { // set on the resolver, not on the message } else { int flag = Flags.value(flags[i]); if (flag > -1) { m.getHeader().setFlag(flag); } else { throw new ParseException(flags[i] + ": not a Flag", i); } } } } else if (line.startsWith("SECTION QUESTION")) { section = Section.QUESTION; } else if (line.startsWith("SECTION ANSWER")) { section = Section.ANSWER; } else if (line.startsWith("SECTION AUTHORITY")) { section = Section.AUTHORITY; } else if (line.startsWith("SECTION ADDITIONAL")) { section = Section.ADDITIONAL; } else if (line.startsWith("ENTRY_END")) { if (state == ParseState.ENTRY_BEGIN) { rpl.replays.add(m); } else if (state == ParseState.STEP_CHECK_ANSWER) { check.response = m; rpl.checks.put(step, check); check = null; } else if (state == ParseState.STEP_QUERY) { check.query = m; } m = null; state = ParseState.Zero; } else { Record rec; if (section == Section.QUESTION) { rec = parseQuestion(line); } else { rec = parseRecord(line); } m.addRecord(rec, section); } break; } } return rpl; }
From source file:org.jobscheduler.dashboard.web.rest.SchedulerHistoryResource.java
License:Apache License
@RequestMapping("/schedulerHistories") @ApiOperation(value = "Get list scheduler history") public @ResponseBody ListDTO schedulerHistories(Model model, @RequestParam(value = "count") Integer count, @RequestParam(value = "page") Integer page, HttpServletRequest request) throws UnsupportedEncodingException { // Spring Data count from page 0, ngTable from page 1 page--;//from w w w . java2 s. c o m Enumeration<String> parametersNames = request.getParameterNames(); // Parameters String jobName = "%"; String spoolerId = "%"; BigDecimal error = null; DateTime startDT = DateTime.now().minusDays(100); DateTime endDT = DateTime.now(); // For sorting List<Order> orders = new ArrayList<Order>(); while (parametersNames.hasMoreElements()) { String parameterName = (String) parametersNames.nextElement(); // Filtering if (parameterName.startsWith(Constant.PARAM_FILTER)) { String filter = request.getParameter(parameterName); String parameterFilter = parameterName.substring(parameterName.indexOf("[") + 1, parameterName.indexOf("]")); String decodedFilter = URLDecoder.decode(filter, "UTF-8"); if (parameterFilter.equals("jobName")) { jobName = "%" + decodedFilter + "%"; } if (parameterFilter.equals("spoolerId")) { spoolerId = "%" + decodedFilter + "%"; } if (parameterFilter.equals("error")) { error = new BigDecimal(filter); } if (parameterFilter.equals("startTime")) { startDT = DateTime.parse(decodedFilter, fmt); } if (parameterFilter.equals("endTime")) { endDT = DateTime.parse(decodedFilter, fmt); } log.info("Filter in get list history : " + parameterName + "=" + filter); } // Sorting if (parameterName.startsWith(Constant.PARAM_SORT)) { String directionParameter = request.getParameter(parameterName); String sortByColumnName = parameterName.substring(parameterName.indexOf("[") + 1, parameterName.indexOf("]")); String direction = URLDecoder.decode(directionParameter, "UTF-8"); orders.add(new Order(Direction.fromString(direction), sortByColumnName)); } } PageRequest pageable; if (orders.size() == 0) pageable = new PageRequest(page, count); else pageable = new PageRequest(page, count, new Sort(orders)); ListDTO dto = new ListDTO(); Page<SchedulerHistory> scheduleJob; if (error != null) scheduleJob = schedulerHistoryRepository.findByStartTimeBetweenAndJobNameLikeAndSpoolerIdLikeAndError( new Timestamp(startDT.getMillis()), new Timestamp(endDT.getMillis()), jobName, spoolerId, error, pageable); else scheduleJob = schedulerHistoryRepository.findByStartTimeBetweenAndJobNameLikeAndSpoolerIdLike( new Timestamp(startDT.getMillis()), new Timestamp(endDT.getMillis()), jobName, spoolerId, pageable); dto.setResult(scheduleJob.getContent()); dto.setTotalElements(scheduleJob.getTotalElements()); dto.setTotalPages(scheduleJob.getTotalPages()); return dto; }
From source file:org.killbill.billing.plugin.moneris.MonerisPaymentTransactionInfoPlugin.java
License:Apache License
@Override public DateTime getEffectiveDate() { // TODO Timezone? Assume UTC? return DateTime.parse(getTransDate() + 'T' + getTransTime() + 'Z', ISODateTimeFormat.dateTimeNoMillis()); }
From source file:org.myorganisation.myproject.quickstart.backend.restful.war.DateTimeUtilities.java
License:Apache License
/** * Converts the supplied timestamp (given as a String), returning a DateTime if possible. * * @param timestampAsString The DateTime string form * @param nullTimestampYieldsNow if {@code true}, then a null value in the timestampAsString argument will * retrieve a DateTime for now. * @return A DateTime parsed from the supplied timestampAsString. */// w w w . ja v a 2s . co m public DateTime convert(final String timestampAsString, boolean nullTimestampYieldsNow) { if (nullTimestampYieldsNow && timestampAsString == null) { return new DateTime(); } // All done. return DateTime.parse(timestampAsString, formatter).withZone(dateTimeZone); }
From source file:org.mythtv.android.data.entity.mapper.serializers.DateTimeDeserializer.java
License:Open Source License
@Override public DateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if ("".equals(json.getAsJsonPrimitive().getAsString())) { return null; }//from w w w . j a v a2s. c o m return DateTime.parse(json.getAsJsonPrimitive().getAsString(), DateTimeFormat.forPattern(pattern).withZoneUTC()); }