List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:com.thoughtworks.xstream.converters.extended.ISO8601GregorianCalendarConverter.java
License:Open Source License
public Object fromString(String str) { for (int i = 0; i < formattersUTC.length; i++) { DateTimeFormatter formatter = formattersUTC[i]; try {/*from ww w .j av a2s .c o m*/ DateTime dt = formatter.parseDateTime(str); Calendar calendar = dt.toGregorianCalendar(); calendar.setTimeZone(TimeZone.getDefault()); return calendar; } catch (IllegalArgumentException e) { // try with next formatter } } String timeZoneID = TimeZone.getDefault().getID(); for (int i = 0; i < formattersNoUTC.length; i++) { try { DateTimeFormatter formatter = formattersNoUTC[i].withZone(DateTimeZone.forID(timeZoneID)); DateTime dt = formatter.parseDateTime(str); Calendar calendar = dt.toGregorianCalendar(); calendar.setTimeZone(TimeZone.getDefault()); return calendar; } catch (IllegalArgumentException e) { // try with next formatter } } throw new ConversionException("Cannot parse date " + str); }
From source file:com.thoughtworks.xstream.core.util.ISO8601JodaTimeConverter.java
License:Open Source License
@Override public Object fromString(final String str) { for (final DateTimeFormatter formatter : formattersUTC) { try {//from w w w . java 2 s . co m final DateTime dt = formatter.parseDateTime(str); final Calendar calendar = dt.toGregorianCalendar(); calendar.setTimeZone(TimeZone.getDefault()); return calendar; } catch (final IllegalArgumentException e) { // try with next formatter } } final DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TimeZone.getDefault()); for (final DateTimeFormatter element : formattersNoUTC) { try { final DateTimeFormatter formatter = element.withZone(dateTimeZone); final DateTime dt = formatter.parseDateTime(str); final Calendar calendar = dt.toGregorianCalendar(); calendar.setTimeZone(TimeZone.getDefault()); return calendar; } catch (final IllegalArgumentException e) { // try with next formatter } } final ConversionException exception = new ConversionException("Cannot parse date"); exception.add("date", str); throw exception; }
From source file:com.tkmtwo.timex.DateTimes.java
License:Apache License
public static List<DateTime> getDateTimes(DateTimeFormatter dtf, Pattern p, String s) { List<DateTime> dateTimes = new ArrayList<DateTime>(); Matcher m = p.matcher(s);/*from w ww .j av a2 s.com*/ while (m.find()) { dateTimes.add(dtf.parseDateTime(m.group())); } /* for (String dtString : Matchers.findAllMatches(s, p)) { dateTimes.add(dtf.parseDateTime(dtString)); } */ return dateTimes; }
From source file:com.trifork.stamdata.importer.jobs.autorisationsregister.AutorisationImporter.java
License:Mozilla Public License
protected DateTime getDateFromFilename(String filename) { DateTimeFormatter formatter = DateTimeFormat.forPattern(FILENAME_DATE_FORMAT); return formatter.parseDateTime(filename.substring(0, 8)); }
From source file:com.tripad.cootrack.erpCommon.process.PAUUpdateCustomerMaintenanceActivities.java
@Override protected JSONObject doExecute(Map<String, Object> parameters, String content) { JSONObject result = new JSONObject(); JSONArray actions = new JSONArray(); JSONObject msgInBPTab = new JSONObject(); JSONObject msgInBPTabAction = new JSONObject(); try {/*w w w . ja va2s . c o m*/ JSONObject request = new JSONObject(content); log.info(">> parameters: " + parameters); // log.info(">> content:" + content); log.info(">> request : " + request.toString()); // _selection contains the rows that the user selected. /* * JSONArray selection = new JSONArray( * request.getString(ApplicationConstants.SELECTION_PROPERTY)); */ JSONArray selection = request.getJSONObject("_params").getJSONObject("prm_pau_customer_maintenance") .getJSONArray(ApplicationConstants.SELECTION_PROPERTY); log.info(">> selected: " + selection); String id = null; for (int i = 0; i < selection.length(); i++) { log.info("LENGTH : " + selection.length()); log.info(">> Nilai id : " + selection.getJSONObject(i).get("id").toString()); log.info(">> Nilai p_gps_ditelpon : " + selection.getJSONObject(i).get("gPSDiTelepon").toString()); log.info(">> Nilai gPSDiSMS : " + selection.getJSONObject(i).get("gPSDiSMS").toString()); log.info(">> Nilai masaAktif : " + selection.getJSONObject(i).get("masaAktif").toString()); log.info(">> Nilai Sisa Pulsa : " + selection.getJSONObject(i).get("sisaPulsa").toString()); log.info(">> Nilai sisaQuota : " + selection.getJSONObject(i).get("sisaQuota").toString()); log.info( ">> Nilai analisaProblem : " + selection.getJSONObject(i).get("analisaProblem").toString()); log.info(">> Nilai solvingBySystem : " + selection.getJSONObject(i).get("solvingBySystem").toString()); log.info(">> Nilai result : " + selection.getJSONObject(i).get("result").toString()); log.info(">> Nilai byPhone : " + selection.getJSONObject(i).get("byPhone").toString()); log.info(">> Nilai bySms : " + selection.getJSONObject(i).get("bySMS").toString()); log.info(">> Nilai maintenanceDateFrom : " + selection.getJSONObject(i).get("maintenanceDateFrom").toString()); log.info(">> Nilai maintenanceDateTo : " + selection.getJSONObject(i).get("maintenanceDateTo").toString()); log.info(">> Nilai jawabanCustomer : " + selection.getJSONObject(i).get("jawabanCustomer").toString()); log.info(">> Nilai keterangan : " + selection.getJSONObject(i).get("keterangan").toString()); id = (String) selection.getJSONObject(i).get("id"); TmcDocumentUpdateLine tmcDocumentUpdateLine = OBDal.getInstance().get(TmcDocumentUpdateLine.class, id); if (!selection.getJSONObject(i).get("gPSDiTelepon").toString().equals("null")) { tmcDocumentUpdateLine .setGPSDiTelepon(selection.getJSONObject(i).get("gPSDiTelepon").toString()); } else { tmcDocumentUpdateLine.setGPSDiTelepon(null); } if (!selection.getJSONObject(i).get("gPSDiSMS").toString().equals("null")) { tmcDocumentUpdateLine.setGPSDiSMS(selection.getJSONObject(i).get("gPSDiSMS").toString()); } else { tmcDocumentUpdateLine.setGPSDiSMS(null); } if (!selection.getJSONObject(i).get("masaAktif").toString().equals("null")) { tmcDocumentUpdateLine.setMasaAktif(new SimpleDateFormat("yyyy-MM-dd") .parse(selection.getJSONObject(i).get("masaAktif").toString())); // 2016-01-07 } else { tmcDocumentUpdateLine.setMasaAktif(null); } if (!selection.getJSONObject(i).get("sisaPulsa").toString().equals("null")) { tmcDocumentUpdateLine .setSisaPulsa(new BigDecimal(selection.getJSONObject(i).get("sisaPulsa").toString())); } else { tmcDocumentUpdateLine.setSisaPulsa(null); } if (!selection.getJSONObject(i).get("sisaQuota").toString().equals("null")) { tmcDocumentUpdateLine .setSisaQuota(new Long(selection.getJSONObject(i).get("sisaQuota").toString())); } else { tmcDocumentUpdateLine.setSisaQuota(null); } if (!selection.getJSONObject(i).get("analisaProblem").toString().equals("null")) { tmcDocumentUpdateLine .setAnalisaProblem(selection.getJSONObject(i).get("analisaProblem").toString()); } else { tmcDocumentUpdateLine.setAnalisaProblem(null); } if (!selection.getJSONObject(i).get("solvingBySystem").toString().equals("null")) { tmcDocumentUpdateLine .setSolvingBySystem(selection.getJSONObject(i).get("solvingBySystem").toString()); } else { tmcDocumentUpdateLine.setSolvingBySystem(null); } if (!selection.getJSONObject(i).get("result").toString().equals("null")) { tmcDocumentUpdateLine.setResult(selection.getJSONObject(i).get("result").toString()); } else { tmcDocumentUpdateLine.setResult(null); } if (!selection.getJSONObject(i).get("byPhone").toString().equals("null")) { tmcDocumentUpdateLine .setByPhone(selection.getJSONObject(i).get("byPhone").equals("Y") ? true : false); } else { tmcDocumentUpdateLine.setByPhone(null); } if (!selection.getJSONObject(i).get("bySMS").toString().equals("null")) { tmcDocumentUpdateLine .setBySMS(selection.getJSONObject(i).get("bySMS").equals("Y") ? true : false); } else { tmcDocumentUpdateLine.setBySMS(null); } if (!selection.getJSONObject(i).get("maintenanceDateFrom").toString().equals("null")) { tmcDocumentUpdateLine.setMaintenanceDateFrom(new SimpleDateFormat("yyyy-MM-dd") .parse(selection.getJSONObject(i).get("maintenanceDateFrom").toString())); } else { tmcDocumentUpdateLine.setMaintenanceDateFrom(null); } if (!selection.getJSONObject(i).get("maintenanceDateTo").toString().equals("null")) { tmcDocumentUpdateLine.setMaintenanceDateTo(new SimpleDateFormat("yyyy-MM-dd") .parse(selection.getJSONObject(i).get("maintenanceDateTo").toString())); } else { tmcDocumentUpdateLine.setMaintenanceDateTo(null); } DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTime df = formatter .parseDateTime(selection.getJSONObject(i).get("maintenanceDateFrom").toString()); DateTime dt = formatter .parseDateTime(selection.getJSONObject(i).get("maintenanceDateTo").toString()); int selisihPengisian = (Months.monthsBetween(df, dt).getMonths()) + 1; // System.out.println("Selisih : " + selisihPengisian); // pengisian ke Long pengisianke = Long.parseLong(selection.getJSONObject(i).get("pengisianke").toString()); if (!selection.getJSONObject(i).get("pengisianke").toString().equals("null")) { tmcDocumentUpdateLine.setPengisianke(pengisianke); } else { tmcDocumentUpdateLine.setPengisianke(new Long("0")); pengisianke = new Long("0"); } if (selisihPengisian - pengisianke < 0) { // throw new Exception( // "Selisih Bulan Maintenance Date dikurangi pengisian, menghasilkan nilai minus !"); result.put("retryExecution", true); JSONObject msg = new JSONObject(); msg.put("severity", "error"); msg.put("text", "Selisih Bulan Maintenance Date dikurangi pengisian menghasilkan nilai minus !"); result.put("message", msg); OBDal.getInstance().rollbackAndClose(); return result; } if (!selection.getJSONObject(i).get("jawabanCustomer").toString().equals("null")) { tmcDocumentUpdateLine .setJawabanCustomer(selection.getJSONObject(i).get("jawabanCustomer").toString()); } else { tmcDocumentUpdateLine.setJawabanCustomer(null); } if (!selection.getJSONObject(i).get("keterangan").toString().equals("null")) { tmcDocumentUpdateLine.setKeterangan(selection.getJSONObject(i).get("keterangan").toString()); } else { tmcDocumentUpdateLine.setKeterangan(null); } // baru 18-maret-2016, penambahan 4 field baru if (!selection.getJSONObject(i).get("tGLIsiPulsaReg").toString().equals("null")) { tmcDocumentUpdateLine.setTGLIsiPulsaReg(new SimpleDateFormat("yyyy-MM-dd") .parse(selection.getJSONObject(i).get("tGLIsiPulsaReg").toString())); } else { tmcDocumentUpdateLine.setTGLIsiPulsaReg(null); } if (!selection.getJSONObject(i).get("nOMIsiPulsaReg").toString().equals("null")) { tmcDocumentUpdateLine.setNOMIsiPulsaReg( new BigDecimal(selection.getJSONObject(i).get("nOMIsiPulsaReg").toString())); } else { tmcDocumentUpdateLine.setNOMIsiPulsaReg(BigDecimal.ONE); } if (!selection.getJSONObject(i).get("tGLIsiPulsaQuota").toString().equals("null")) { tmcDocumentUpdateLine.setTGLIsiPulsaQuota(new SimpleDateFormat("yyyy-MM-dd") .parse(selection.getJSONObject(i).get("tGLIsiPulsaQuota").toString())); } else { tmcDocumentUpdateLine.setTGLIsiPulsaQuota(null); } if (!selection.getJSONObject(i).get("nOMIsiPulsaQuota").toString().equals("null")) { tmcDocumentUpdateLine.setNOMIsiPulsaQuota( new BigDecimal(selection.getJSONObject(i).get("nOMIsiPulsaQuota").toString())); } else { tmcDocumentUpdateLine.setNOMIsiPulsaQuota(BigDecimal.ONE); } tmcDocumentUpdateLine.setProcess(true); OBDal.getInstance().save(tmcDocumentUpdateLine); OBDal.getInstance().flush(); } OBDal.getInstance().commitAndClose(); msgInBPTab.put("msgType", "success"); msgInBPTab.put("msgTitle", "Process Update"); msgInBPTab.put("msgText", "Record Berhasil di Update"); msgInBPTabAction.put("showMsgInView", msgInBPTab); actions.put(msgInBPTabAction); // request.put("MESSAGE", "Sukses !"); result.put("responseActions", actions); return result; } catch (JSONException e) { OBDal.getInstance().rollbackAndClose(); return new JSONObject(); } catch (Exception t) { OBDal.getInstance().rollbackAndClose(); log.error("Error processing request: " + t.getMessage(), t); return errorMessage(result, t.getMessage()); } }
From source file:com.uumai.crawer.util.license.LicenseValidateHelper.java
License:Open Source License
private void validateInfo(LicenseInfo licenseInfo) throws Exception { //just check validate time DateTime in = new DateTime(); DateTimeFormatter joda_fmt = DateTimeFormat.forPattern("yyyy.MM.dd");//? DateTime license_time = joda_fmt.parseDateTime(licenseInfo.getValid_until()); if (!in.isBefore(license_time)) throw new Exception("license has expiried. please contact uumai!"); }
From source file:com.vangent.hieos.services.sts.model.SOAPHeaderData.java
License:Open Source License
/** * * @param securityHeader//from w w w.j a v a 2s .c o m * @return */ private DateTime getTimestampCreated(OMElement securityHeader) { DateTime time = null; try { OMElement timeNode = XPathHelper.selectSingleNode(securityHeader, "./ns:Timestamp/ns:Created[1]", STSConstants.WSSECURITY_UTILITY_NS); if (timeNode != null) { String timeString = timeNode.getText(); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); time = fmt.parseDateTime(timeString); } } catch (XPathHelperException ex) { // Do nothing - will be validated later. } return time; }
From source file:com.vangent.hieos.services.sts.model.SOAPHeaderData.java
License:Open Source License
/** * * @param securityHeader//from w w w . j a v a2s . c o m * @return */ private DateTime getTimestampExpires(OMElement securityHeader) { DateTime time = null; try { OMElement timeNode = XPathHelper.selectSingleNode(securityHeader, "./ns:Timestamp/ns:Expires[1]", STSConstants.WSSECURITY_UTILITY_NS); if (timeNode != null) { String timeString = timeNode.getText(); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); time = fmt.parseDateTime(timeString); } } catch (XPathHelperException ex) { // Do nothing - will be validated later. } return time; }
From source file:com.vaushell.superpipes.dispatch.ConfigProperties.java
License:Open Source License
/** * Get config. throws IllegalArgumentException if the key is not a datetime or doesn't exist. * * @param key Key of parameter.// w w w .ja v a 2s . com * @param fmt Format of the date. * @return the value. */ public DateTime getConfigDateTime(final String key, final DateTimeFormatter fmt) { final String value = getConfig(key, false); return fmt.parseDateTime(value); }
From source file:com.vaushell.superpipes.dispatch.ConfigProperties.java
License:Open Source License
/** * Get config.//from w w w. j av a 2 s .co m * * @param key Key of parameter. * @param fmt Format of the date. * @param defaultValue Default value if the key doesn't exist. * @return the value. */ public DateTime getConfigDateTime(final String key, final DateTimeFormatter fmt, final DateTime defaultValue) { final String value = getConfig(key, true); if (value == null) { return defaultValue; } else { return fmt.parseDateTime(value); } }