List of usage examples for org.joda.time DateTime toLocalDateTime
public LocalDateTime toLocalDateTime()
LocalDateTime
with the same datetime and chronology. From source file:au.com.scds.chats.dom.attendance.Attend.java
License:Apache License
@Action() public Attend updateDatesAndTimes(@ParameterLayout(named = "Start Date Time") DateTime start, @ParameterLayout(named = "End Date Time") DateTime end) { if (start != null && end != null) { if (end.isBefore(start)) { container.warnUser("end date & time is earlier than start date & time"); return this; }/*from w w w . ja v a 2 s. c o m*/ if (end.getDayOfWeek() != start.getDayOfWeek()) { container.warnUser("end date and start date are different days of the week"); return this; } Period period = new Period(start.toLocalDateTime(), end.toLocalDateTime()); Float hours = ((float) period.toStandardMinutes().getMinutes()) / 60; if (hours > 12.0) { container.warnUser("end date & time and start date & time are not in the same 12 hour period"); return this; } setStartDateTime(start); setEndDateTime(end); setAttended(true); } return this; }
From source file:au.com.scds.chats.dom.volunteer.VolunteeredTime.java
License:Apache License
@Action() @MemberOrder(name = "enddatetime", sequence = "1") public VolunteeredTime updateDatesAndTimes(@ParameterLayout(named = "Start Date Time") DateTime start, @ParameterLayout(named = "End Date Time") DateTime end) { if (start != null && end != null) { if (end.isBefore(start)) { container.warnUser("end date & time is earlier than start date & time"); return this; }//from www . j a v a2s . co m if (end.getDayOfWeek() != start.getDayOfWeek()) { container.warnUser("end date and start date are different days of the week"); return this; } Period period = new Period(start.toLocalDateTime(), end.toLocalDateTime()); Float hours = ((float) period.toStandardMinutes().getMinutes()) / 60; if (hours > 12.0) { container.warnUser("end date & time and start date & time are not in the same 12 hour period"); return this; } setStartDateTime(start); setEndDateTime(end); } return this; }
From source file:au.edu.ausstage.mobile.GathererManager.java
License:Open Source License
/** * A method to process an SMS message/*from w w w .j av a 2 s. com*/ * * @param callerId the id of the caller, typically the mobile device / mobile phone number * @param time the time that the message was sent * @param date the date that the message was sent * @param message the content of the message * * @return the message in response to the input */ public String processSMS(String callerId, String time, String date, String message) { // check on the parameters if (InputUtils.isValid(callerId) == false || InputUtils.isValid(time) == false || InputUtils.isValid(date) == false || InputUtils.isValid(message) == false) { return null; } // url decode the message try { String tmp = java.net.URLDecoder.decode(message, "UTF-8"); message = tmp; } catch (java.io.UnsupportedEncodingException ex) { } // define helper variables Extractor extractHashTags = new Extractor(); // get the date and time that the message was recieved time = time.split(" ")[0]; if (time == null) { emailManager.sendSimpleMessage(EMAIL_SUBJECT, EMAIL_MESSAGE + "\nDetails: Incompatible time format detected\n" + buildException(callerId, null, message)); return "Error"; } DateTime messageReceived = inputDateTimeFormat.parseDateTime(date + " " + time); LocalDateTime localMessageReceived = messageReceived.toLocalDateTime(); // get a santised version of the callerId callerId = HashUtils.hashValue(callerId); // get the list of hash tags from the tweet List<String> hashtags = extractHashTags.extractHashtags(message); // check on what was returned if (hashtags.isEmpty() == true) { // no hashtags were found // send an exception report emailManager.sendSimpleMessage(EMAIL_SUBJECT, EMAIL_MESSAGE + "\nDetails: No hashtags found in the message\n" + buildException(callerId, localMessageReceived, message)); return "Error"; } // convert all of the found hash tags to lower case ListIterator<String> hashtagsIterator = hashtags.listIterator(); while (hashtagsIterator.hasNext() == true) { // get the next tage in the list String tmp = (String) hashtagsIterator.next(); tmp = tmp.toLowerCase(); // replace the value we retrieved with this updated one hashtagsIterator.set(tmp); } // see if this is a company performance if (isCompanyPerformance(hashtags, callerId, message, localMessageReceived) == false) { // this isn't a company performance // is it using a performance specific id? if (isPerformance(hashtags, callerId, message, localMessageReceived) == false) { // send an exception report emailManager.sendSimpleMessage(EMAIL_SUBJECT, EMAIL_MESSAGE + "\nDetails: Unable to find a matching performance\n" + buildException(callerId, localMessageReceived, message)); return "ERROR"; } } // if we get this far everything is ok return "OK"; }
From source file:au.edu.ausstage.tweetgatherer.MessageProcessor.java
License:Open Source License
/** * A private method to process a message containing a company hash tag * * @param hashtags a list of hashtags associated with this message * @param jsonTweetObject the message//from ww w . ja v a 2 s . co m * @param jsonUserObject the user object * @param tweetIdHash the hash of the message id * * @return true if, and only if, the message was processed successfully */ private boolean isCompanyPerformance(List<String> hashtags, JsonObject jsonTweetObject, JsonObject jsonUserObject, String tweetIdHash) { /* * get the date & time that the message was received */ JsonElement elem = jsonTweetObject.get("created_at"); DateTime messageCreated = inputDateTimeFormat.parseDateTime(elem.getAsString()); LocalDateTime localMessageCreated = messageCreated.toLocalDateTime(); /* * get the performance and question id */ String performanceId = null; String questionId = null; // define the sql String selectSql = "SELECT performance_id, question_id, SUBSTR(twitter_hash_tag, 2) " + "FROM mob_performances, mob_organisations, orgevlink " + "WHERE mob_performances.event_id = orgevlink.eventid " + "AND mob_organisations.organisation_id = orgevlink.organisationid " + "AND start_date_time < TO_DATE(?, '" + DB_DATE_TIME_FORMAT + "') " + "AND end_date_time + 1/12 > TO_DATE(?, '" + DB_DATE_TIME_FORMAT + "') "; // define the parameters array String[] sqlParameters = new String[2]; sqlParameters[0] = dateTimeFormat.print(messageCreated); sqlParameters[1] = dateTimeFormat.print(messageCreated); // get the data DbObjects results = database.executePreparedStatement(selectSql, sqlParameters); // double check the results if (results == null) { System.err.println("ERROR: Unable to execute the SQL to lookup performances"); // send an exception report if (emailManager.sendMessageWithAttachment(EMAIL_SUBJECT, EMAIL_MESSAGE, logFiles + "/" + tweetIdHash) == false) { System.err.println("ERROR: Unable to send the exception report"); } return false; } else { // look for performances matching the hash tag from the message ResultSet resultSet = results.getResultSet(); // loop through the resultset boolean found = false; // exit the loop early sqlParameters = new String[7]; // store the parameters try { while (resultSet.next() && found == false) { // see if the hashtags in the message match one in the DB if (hashtags.contains(resultSet.getString(3)) == true) { // yep sqlParameters[0] = resultSet.getString(1); sqlParameters[1] = resultSet.getString(2); found = true; } } } catch (java.sql.SQLException ex) { found = false; } if (found == false) { // no performance with a matching company id was found return false; } else { /* * write the message to the database */ // define the sql String insertSql = "INSERT INTO mob_feedback " + "(performance_id, question_id, source_type, received_date_time, received_from, source_id, short_content) " + "VALUES (?,?,?, TO_DATE(?, '" + DB_DATE_TIME_FORMAT + "'),?,?,?)"; // use the source id from the constant sqlParameters[2] = SOURCE_ID; // add the date and time sqlParameters[3] = dateTimeFormat.print(messageCreated); // add the user id elem = jsonUserObject.get("id"); sqlParameters[4] = elem.getAsString(); // add the source id elem = jsonTweetObject.get("id"); sqlParameters[5] = elem.getAsString(); // add the message elem = jsonUserObject.get("text"); sqlParameters[6] = elem.getAsString(); // insert the data if (database.executePreparedInsertStatement(insertSql, sqlParameters) == false) { System.err.println("ERROR: Unable to add the message to the database"); // send an exception report if (emailManager.sendMessageWithAttachment(EMAIL_SUBJECT, "Exception Report: The Tweet Gatherer was unable to store this message in the database", logFiles + "/" + tweetIdHash) == false) { System.err.println("ERROR: Unable to send the exception report"); } } else { System.out.println("INFO: Successfully added the message to the database"); return true; } } } // end performance check // if we get this far, something bad happend return false; }
From source file:br.com.caelum.vraptor.converter.jodatime.LocalDateTimeConverter.java
License:Open Source License
public LocalDateTime convert(String value, Class<? extends LocalDateTime> type, ResourceBundle bundle) { try {/*from w w w .j a v a 2 s . co m*/ DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDateTime()); if (out == null) { return null; } return out.toLocalDateTime(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_datetime"), value)); } }
From source file:com.axelor.apps.businessproduction.service.ProductionOrderWizardServiceBusinessImpl.java
License:Open Source License
@Override public Long validate(Context context) throws AxelorException { Map<String, Object> bomContext = (Map<String, Object>) context.get("billOfMaterial"); BillOfMaterial billOfMaterial = billOfMaterialRepo.find(((Integer) bomContext.get("id")).longValue()); BigDecimal qty = new BigDecimal((String) context.get("qty")); Product product = null;/*from w w w . ja va2s . c o m*/ if (context.get("product") != null) { Map<String, Object> productContext = (Map<String, Object>) context.get("product"); product = productRepo.find(((Integer) productContext.get("id")).longValue()); } else { product = billOfMaterial.getProduct(); } DateTime startDate; if (context.containsKey("_startDate") && context.get("_startDate") != null) { startDate = new DateTime(context.get("_startDate")); } else { startDate = generalService.getTodayDateTime().toDateTime(); } ProjectTask projectTask = null; if (context.get("business_id") != null) { projectTask = Beans.get(ProjectTaskRepository.class) .find(((Integer) context.get("business_id")).longValue()); } ProductionOrder productionOrder = productionOrderServiceBusinessImpl.generateProductionOrder(product, billOfMaterial, qty, projectTask, startDate.toLocalDateTime()); if (productionOrder != null) { return productionOrder.getId(); } else { throw new AxelorException(String.format(I18n.get(IExceptionMessage.PRODUCTION_ORDER_2)), IException.CONFIGURATION_ERROR); } }
From source file:com.axelor.apps.production.service.ProductionOrderWizardServiceImpl.java
License:Open Source License
public Long validate(Context context) throws AxelorException { Map<String, Object> bomContext = (Map<String, Object>) context.get("billOfMaterial"); BillOfMaterial billOfMaterial = billOfMaterialRepo.find(((Integer) bomContext.get("id")).longValue()); BigDecimal qty = new BigDecimal((String) context.get("qty")); Product product = null;//from w ww .j a v a2s .c om if (context.get("product") != null) { Map<String, Object> productContext = (Map<String, Object>) context.get("product"); product = productRepo.find(((Integer) productContext.get("id")).longValue()); } else { product = billOfMaterial.getProduct(); } DateTime startDate; if (context.containsKey("_startDate") && context.get("_startDate") != null) { startDate = new DateTime(context.get("_startDate")); } else { startDate = generalService.getTodayDateTime().toDateTime(); } ProductionOrder productionOrder = productionOrderService.generateProductionOrder(product, billOfMaterial, qty, startDate.toLocalDateTime()); if (productionOrder != null) { return productionOrder.getId(); } else { throw new AxelorException(String.format(I18n.get(IExceptionMessage.PRODUCTION_ORDER_2)), IException.CONFIGURATION_ERROR); } }
From source file:com.axelor.apps.production.web.ProductionOrderController.java
License:Open Source License
public void addManufOrder(ActionRequest request, ActionResponse response) throws AxelorException { Context context = request.getContext(); if (context.get("qty") == null || new BigDecimal(context.get("qty").toString()).compareTo(BigDecimal.ZERO) <= 0) { response.setFlash(I18n.get(IExceptionMessage.PRODUCTION_ORDER_3) + "!"); } else if (context.get("billOfMaterial") == null) { response.setFlash(I18n.get(IExceptionMessage.PRODUCTION_ORDER_4) + "!"); } else {// w w w .j a v a 2s . c om Map<String, Object> bomContext = (Map<String, Object>) context.get("billOfMaterial"); BillOfMaterial billOfMaterial = billOfMaterialRepo.find(((Integer) bomContext.get("id")).longValue()); BigDecimal qty = new BigDecimal(context.get("qty").toString()); Product product = null; if (context.get("product") != null) { Map<String, Object> productContext = (Map<String, Object>) context.get("product"); product = productRepo.find(((Integer) productContext.get("id")).longValue()); } else { product = billOfMaterial.getProduct(); } DateTime startDate; if (context.containsKey("_startDate") && context.get("_startDate") != null) { startDate = new DateTime(context.get("_startDate")); } else { startDate = generalService.getTodayDateTime().toDateTime(); } ProductionOrder productionOrder = request.getContext().asType(ProductionOrder.class); productionOrderService.addManufOrder(productionOrderRepo.find(productionOrder.getId()), product, billOfMaterial, qty, startDate.toLocalDateTime()); response.setReload(true); } }
From source file:com.axelor.data.adapter.JodaAdapter.java
License:Open Source License
@Override public Object adapt(Object value, Map<String, Object> context) { if (value == null || !(value instanceof String)) { return value; }//from w ww . jav a 2s. c o m String format = this.get("format", DEFAULT_FORMAT); DateTimeFormatter fmt = DateTimeFormat.forPattern(format); DateTime dt; try { dt = fmt.parseDateTime((String) value); } catch (Exception e) { throw new IllegalArgumentException("Invalid value: " + value, e); } String type = this.get("type", null); if ("LocalDate".equals(type)) { return dt.toLocalDate(); } if ("LocalTime".equals(type)) { return dt.toLocalTime(); } if ("LocalDateTime".equals(type)) { return dt.toLocalDateTime(); } return dt; }
From source file:com.coderoad.automation.common.util.DateUtil.java
License:Open Source License
/** * Convert timezone.// w w w .jav a 2 s . c o m * * @param date the date * @param srcTimeZone the src time zone * @param destTimeZone the dest time zone * @return the date */ public static Date convertTimezone(LocalDateTime date, String srcTimeZone, String destTimeZone) { DateTime srcDateTime = date.toDateTime(DateTimeZone.forID(srcTimeZone)); DateTime dstDateTime = srcDateTime.withZone(DateTimeZone.forID(destTimeZone)); return dstDateTime.toLocalDateTime().toDateTime().toDate(); }