List of usage examples for org.joda.time LocalDateTime LocalDateTime
public LocalDateTime(Object instant)
From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java
License:Apache License
private void configureBeginDate(View view) { TextView beginDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_begin_date); beginDateTextView.setEnabled(isThisHoursRecordNotActive()); if (isThisHoursRecordActive()) { beginDateTextView/*from w w w . j a v a 2 s .c om*/ .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null)); } else { beginDateTextView .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null)); } beginDateTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fragmentManager = getFragmentManager(); // If there is already a Date displayed, use that. Date dateToUse = (mHours.getBegin() == null) ? new Date() : mHours.getBegin(); DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse, "Begin", DateTimePickerFragment.BOTH); datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_BEGIN_DATE_PICKER); datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG); } }); if (mHours.getBegin() != null) { LocalDateTime beginDateTime = new LocalDateTime(mHours.getBegin().getTime()); beginDateTextView.setText(beginDateTime.toString(DATE_FORMAT_PATTERN)); } }
From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java
License:Apache License
private void configureEndDate(View view) { TextView endDateTextView = (TextView) view.findViewById(R.id.textview_hours_detail_end_date); endDateTextView.setEnabled(isThisHoursRecordNotActive()); if (isThisHoursRecordActive()) { endDateTextView.setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.no_border, null)); } else {// w w w. ja v a 2s. c o m endDateTextView .setBackground(ResourcesCompat.getDrawable(getResources(), R.drawable.rounded_border, null)); } endDateTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fragmentManager = getFragmentManager(); // If there is already a Date displayed, use that. Date dateToUse = (mHours.getEnd() == null) ? new Date() : mHours.getEnd(); DateTimePickerFragment datePickerFragment = FragmentFactory.createDatePickerFragment(dateToUse, "End", DateTimePickerFragment.BOTH); datePickerFragment.setTargetFragment(HoursDetailFragment.this, REQUEST_END_DATE_PICKER); datePickerFragment.show(fragmentManager, DateTimePickerFragment.DIALOG_TAG); } }); if (mHours.getEnd() != null) { LocalDateTime endDateTime = new LocalDateTime(mHours.getEnd().getTime()); endDateTextView.setText(endDateTime.toString(DATE_FORMAT_PATTERN)); } }
From source file:com.mklinke.breakplanner.controller.MainController.java
License:Apache License
public void newBreak(String description, Date time) { try {//from www. j a v a 2s. c o m Break newBreak = new Break(description, new LocalDateTime(time.getTime())); newBreak.setEditable(true); model.addBreak(newBreak); view.addBreak(newBreak); view.setStatus("Created new break."); } catch (IOException e) { handleException("Error while adding break", e); } }
From source file:com.mycollab.vaadin.web.ui.field.DateTimeOptionField.java
License:Open Source License
private Date getDateValue() { Date selectDate = popupDateField.getValue(); if (selectDate == null) { return null; }//from www.j a v a 2 s . co m DateTime jodaSelectDate = new DateTime(selectDate) .toDateTime(DateTimeZone.forTimeZone(UserUIContext.getUserTimeZone())); Date baseDate = new LocalDate(jodaSelectDate).toDate(); if (hideTimeOption) { return new LocalDateTime(baseDate).toDateTime(DateTimeZone.forTimeZone(UserUIContext.getUserTimeZone())) .toDate(); } else { Integer hour = (hourPickerComboBox.getValue() != null) ? Integer.parseInt((String) hourPickerComboBox.getValue()) : 0; Integer minus = (minutePickerComboBox.getValue() != null) ? Integer.parseInt((String) minutePickerComboBox.getValue()) : 0; String timeFormat = (timeFormatComboBox.getValue() != null) ? (String) timeFormatComboBox.getValue() : "AM"; long milliseconds = calculateMilliSeconds(hour, minus, timeFormat); DateTime jodaTime = new DateTime(baseDate).plus(new Duration(milliseconds)); return new LocalDateTime(jodaTime.getMillis()) .toDateTime(DateTimeZone.forTimeZone(UserUIContext.getUserTimeZone())).toDate(); } }
From source file:com.mysema.query.sql.types.LocalDateTimeType.java
License:Apache License
@Override public LocalDateTime getValue(ResultSet rs, int startIndex) throws SQLException { Timestamp ts = rs.getTimestamp(startIndex); return ts != null ? new LocalDateTime(ts.getTime()) : null; }
From source file:com.restservice.database.Transactor.java
License:Open Source License
/** * Returns the count per Date for a specified search term * // ww w . j av a 2s .c om * @param id specified search term index * @param lang just select languages with this iso language code. All languages are selected if this parameter is null. * @param sentiment Just select given sentiment. Should be either "positive", "neutral" or "negative". All sentiments are selected if this parameter is null. * @return DTO containing a list of dates and a list of counts * @throws SQLException * thrown if a SQL-Error occurs */ public SearchTermsPerQueryPerDate getCountPerHour(Long id, String lang) throws SQLException { SearchTermsPerQueryPerDate result = new SearchTermsPerQueryPerDate(); try { String sqlQuery = "SELECT COUNT(tweets_id) AS count, created_at AS moment " + "FROM tweets_has_search_terms " + "WHERE search_terms_id = ? " + ((lang != null) ? "AND iso_language_code = ? " : "") + "GROUP BY YEAR(moment), MONTH(moment), DAY(moment), HOUR(moment) " + "ORDER BY YEAR(moment), MONTH(moment), DAY(moment), HOUR(moment);"; connect = DriverManager.getConnection(dbUrl); readStatement = connect.prepareStatement(readQuery); readStatement.execute(); prepStatement = connect.prepareStatement(sqlQuery); prepStatement.setLong(1, id); if (lang != null) { prepStatement.setString(2, lang); } ResultSet resultSet = prepStatement.executeQuery(); ArrayList<Integer> counts = new ArrayList<Integer>(); ArrayList<LocalDateTime> dates = new ArrayList<LocalDateTime>(); Query query = new Query(); if (resultSet.first()) { counts.add(resultSet.getInt("count")); java.sql.Timestamp tempSQLDate = resultSet.getTimestamp("moment"); LocalDateTime date = new LocalDateTime(tempSQLDate.getTime()); dates.add(date); while (resultSet.next()) { counts.add(resultSet.getInt("count")); tempSQLDate = resultSet.getTimestamp("moment"); date = new LocalDateTime(tempSQLDate.getTime()); dates.add(date); } result.setCounts(counts); result.setDates(dates); } resultSet = null; prepStatement = connect.prepareStatement("select id, term from search_terms where id = ?"); prepStatement.setLong(1, id); ResultSet resultSetQueries = prepStatement.executeQuery(); if (resultSetQueries.first()) { query.setId(resultSetQueries.getLong("id")); query.setString(resultSetQueries.getString("term")); result.setQuery(query); } else { result.setQuery(new Query(id, null)); } resultSetQueries = null; } catch (SQLException e) { throw e; } finally { close(); } return result; }
From source file:com.restservice.database.Transactor.java
License:Open Source License
/** * Returns count per Hour for positive and negative tweets seperately. Ignores neutral tweets. * //from w w w . j a v a 2 s .c om * @param id specified search term index * @param lang iso language code of the language (all languages are selected if this parameter is null) * @return DTO containing a list of dates and a list of counts * @throws SQLException thrown if a SQL-Error occurs */ public SentimentPerQueryPerDate getSentimentPerHour(Long id, String lang) throws SQLException { SentimentPerQueryPerDate result = new SentimentPerQueryPerDate(); SearchTermsPerQueryPerDate positiveResults = new SearchTermsPerQueryPerDate(); SearchTermsPerQueryPerDate negativeResults = new SearchTermsPerQueryPerDate(); try { String sqlQuery = "select sum(if(tweets_has_search_terms.sentiment >= ?, 1, 0)) as positive, " + "sum(if(tweets_has_search_terms.sentiment <= ?, 1, 0)) as negative, " + "created_at as moment, " + "search_terms_id " + "from tweets_has_search_terms " + "where search_terms_id = ? " + ((lang != null) ? "and tweets_has_search_terms.iso_language_code = ? " : "") + "group by year(moment), month(moment), day(moment), hour(moment) " + "order by year(moment), month(moment), day(moment), hour(moment);"; connect = DriverManager.getConnection(dbUrl); readStatement = connect.prepareStatement(readQuery); readStatement.execute(); prepStatement = connect.prepareStatement(sqlQuery); prepStatement.setFloat(1, RestUtil.SENTIMENT_UPPER_BORDER); prepStatement.setFloat(2, RestUtil.SENTIMENT_LOWER_BORDER); prepStatement.setLong(3, id); if (lang != null) { prepStatement.setString(4, lang); } ResultSet resultSet = prepStatement.executeQuery(); ArrayList<Integer> positiveCounts = new ArrayList<Integer>(); ArrayList<Integer> negativeCounts = new ArrayList<Integer>(); ArrayList<LocalDateTime> dates = new ArrayList<LocalDateTime>(); Query query = new Query(); if (resultSet.first()) { positiveCounts.add(resultSet.getInt("positive")); negativeCounts.add(resultSet.getInt("negative")); java.sql.Timestamp tempSQLTimestamp = resultSet.getTimestamp("moment"); LocalDateTime date = new LocalDateTime(tempSQLTimestamp.getTime()); dates.add(date); while (resultSet.next()) { positiveCounts.add(resultSet.getInt("positive")); negativeCounts.add(resultSet.getInt("negative")); tempSQLTimestamp = resultSet.getTimestamp("moment"); date = new LocalDateTime(tempSQLTimestamp.getTime()); dates.add(date); } positiveResults.setCounts(positiveCounts); positiveResults.setDates(dates); negativeResults.setCounts(negativeCounts); negativeResults.setDates(dates); } result.setPositiveCounts(positiveResults); result.setNegativeCounts(negativeResults); resultSet = null; prepStatement = connect.prepareStatement("select id, term from search_terms where id = ?"); prepStatement.setLong(1, id); ResultSet resultSetQueries = prepStatement.executeQuery(); if (resultSetQueries.first()) { query.setId(resultSetQueries.getLong("id")); query.setString(resultSetQueries.getString("term")); positiveResults.setQuery(query); negativeResults.setQuery(query); } else { query = new Query(id, ""); positiveResults.setQuery(query); negativeResults.setQuery(query); } resultSetQueries = null; } catch (SQLException e) { throw e; } finally { close(); } return result; }
From source file:com.sam.moca.server.expression.operators.arith.MinusExpression.java
License:Open Source License
protected MocaValue doOper(MocaValue left, MocaValue right) { if (left.getType() == MocaType.DATETIME) { if (right.getType() == MocaType.DOUBLE || right.getType() == MocaType.INTEGER) { Date d = left.asDate(); // If the left side is null, return a null result. if (d == null) { return new MocaValue(MocaType.DATETIME, null); }//from w w w. j ava2 s . co m LocalDateTime dt = new LocalDateTime(d); int wholeDays = right.asInt(); double dayPart = right.asDouble() - wholeDays; int msDiff = (int) (dayPart * 1000.0 * 3600.0 * 24.0); dt = dt.minusDays(wholeDays).minusMillis(msDiff); return new MocaValue(MocaType.DATETIME, dt.toDateTime().toDate()); } else if (right.getType() == MocaType.DATETIME) { Date leftDate = left.asDate(); Date rightDate = right.asDate(); // If either the left side or the right side is null, return null if (leftDate == null || rightDate == null) { return new MocaValue(MocaType.DOUBLE, null); } DateTime leftDt = new DateTime(leftDate); DateTime rightDt = new DateTime(rightDate); int fullDays = Days.daysBetween(rightDt, leftDt).getDays(); LocalTime leftTime = new LocalTime(leftDt); LocalTime rightTime = new LocalTime(rightDt); int ms = leftTime.getMillisOfDay() - rightTime.getMillisOfDay(); double partial = ((double) ms / (1000.0 * 3600.0 * 24.0)); if (partial < 0.0 && leftDate.after(rightDate)) { partial += 1.0; } else if (partial > 0.0 && rightDate.after(leftDate)) { partial -= 1.0; } double daysDiff = (double) fullDays + partial; return new MocaValue(MocaType.DOUBLE, daysDiff); } } else { if (left.getType() == MocaType.DOUBLE || right.getType() == MocaType.DOUBLE) { return new MocaValue(MocaType.DOUBLE, Double.valueOf(left.asDouble() - right.asDouble())); } else { return new MocaValue(MocaType.INTEGER, Integer.valueOf(left.asInt() - right.asInt())); } } return null; }
From source file:com.sam.moca.server.expression.operators.arith.PlusExpression.java
License:Open Source License
private MocaValue addToDate(MocaValue date, MocaValue days) { Date d = date.asDate();//from w ww . ja v a 2s . c o m // If the left side is null, return a null result. if (d == null) { return new MocaValue(MocaType.DATETIME, null); } MocaType daysType = days.getType(); if (daysType == MocaType.INTEGER || daysType == MocaType.DOUBLE) { LocalDateTime dt = new LocalDateTime(d); int wholeDays = days.asInt(); double dayPart = days.asDouble() - wholeDays; int msDiff = (int) (dayPart * 1000.0 * 3600.0 * 24.0); dt = dt.plusDays(wholeDays).plusMillis(msDiff); return new MocaValue(MocaType.DATETIME, dt.toDateTime().toDate()); } else { return date; } }
From source file:com.sandata.lab.common.utils.date.DateUtil.java
License:Open Source License
public static String convertJodaDateTimetoString(LocalDate localDate, LocalTime localTime, String dateFormat) { LocalDateTime localDateTime = new LocalDateTime(localDate.toString() + "T" + localTime.toString()); DateTimeFormatter fmt = DateTimeFormat.forPattern(dateFormat); return localDateTime.toString(fmt); }