List of usage examples for org.joda.time MutableDateTime toDateTime
DateTime toDateTime();
From source file:org.gdg.frisbee.android.eventseries.EventListFragment.java
License:Apache License
private DateTime getMonthStart(int month) { MutableDateTime date = new MutableDateTime(); date.setDayOfMonth(1);//w ww .java 2 s. co m date.setMillisOfDay(0); date.setMonthOfYear(month); return date.toDateTime(); }
From source file:org.gdg.frisbee.android.eventseries.EventListFragment.java
License:Apache License
private DateTime getMonthEnd(int month) { MutableDateTime date = MutableDateTime.now(); date.setMillisOfDay(0);//from w w w. ja v a 2s. co m date.setMonthOfYear(month); return date.toDateTime().dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue(); }
From source file:org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils.java
License:Educational Community License
public static DateTime getLowerDateTimeBound(String dateRange) throws ParseException { Range range = SearchExpressionUtils.parseRange(dateRange); if (range == null) { throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange); }//from ww w. j a v a2 s. com if (range.getLowerBoundValue() != null) { java.util.Date lowerRangeDate = null; try { lowerRangeDate = CoreApiServiceLocator.getDateTimeService() .convertToDate(range.getLowerBoundValue()); } catch (ParseException pe) { GlobalVariables.getMessageMap().putError("dateFrom", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage()); } MutableDateTime dateTime = new MutableDateTime(lowerRangeDate); dateTime.setMillisOfDay(0); return dateTime.toDateTime(); } return null; }
From source file:org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils.java
License:Educational Community License
public static DateTime getUpperDateTimeBound(String dateRange) throws ParseException { Range range = SearchExpressionUtils.parseRange(dateRange); if (range == null) { throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange); }/*from www .java 2 s . c om*/ if (range.getUpperBoundValue() != null) { java.util.Date upperRangeDate = null; try { upperRangeDate = CoreApiServiceLocator.getDateTimeService() .convertToDate(range.getUpperBoundValue()); } catch (ParseException pe) { GlobalVariables.getMessageMap().putError("dateCreated", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage()); } MutableDateTime dateTime = new MutableDateTime(upperRangeDate); // set it to the last millisecond of the day dateTime.setMillisOfDay((24 * 60 * 60 * 1000) - 1); return dateTime.toDateTime(); } return null; }
From source file:org.kuali.rice.kew.docsearch.service.impl.DocumentSearchServiceImpl.java
License:Educational Community License
protected DocumentSearchCriteria applyCriteriaDefaults(DocumentSearchCriteria criteria) { DocumentSearchCriteria.Builder comparisonCriteria = createEmptyComparisonCriteria(criteria); boolean isCriteriaEmpty = criteria.equals(comparisonCriteria.build()); boolean isTitleOnly = false; boolean isDocTypeOnly = false; if (!isCriteriaEmpty) { comparisonCriteria.setTitle(criteria.getTitle()); isTitleOnly = criteria.equals(comparisonCriteria.build()); }//from w w w . jav a2s . co m if (!isCriteriaEmpty && !isTitleOnly) { comparisonCriteria = createEmptyComparisonCriteria(criteria); comparisonCriteria.setDocumentTypeName(criteria.getDocumentTypeName()); isDocTypeOnly = criteria.equals(comparisonCriteria.build()); } if (isCriteriaEmpty || isTitleOnly || isDocTypeOnly) { DocumentSearchCriteria.Builder criteriaBuilder = DocumentSearchCriteria.Builder.create(criteria); Integer defaultCreateDateDaysAgoValue = null; if (isCriteriaEmpty || isDocTypeOnly) { // if they haven't set any criteria, default the from created date to today minus days from constant variable defaultCreateDateDaysAgoValue = KewApiConstants.DOCUMENT_SEARCH_NO_CRITERIA_CREATE_DATE_DAYS_AGO; } else if (isTitleOnly) { // If the document title is the only field which was entered, we want to set the "from" date to be X // days ago. This will allow for a more efficient query. defaultCreateDateDaysAgoValue = KewApiConstants.DOCUMENT_SEARCH_DOC_TITLE_CREATE_DATE_DAYS_AGO; } if (defaultCreateDateDaysAgoValue != null) { // add a default create date MutableDateTime mutableDateTime = new MutableDateTime(); mutableDateTime.addDays(defaultCreateDateDaysAgoValue.intValue()); criteriaBuilder.setDateCreatedFrom(mutableDateTime.toDateTime()); } criteria = criteriaBuilder.build(); } return criteria; }
From source file:org.mongoste.core.impl.mongodb.MongoStatsEngine.java
License:Open Source License
private List<StatAction> getTargetStats(DBObject query) throws StatsEngineException { List<StatAction> result = new ArrayList<StatAction>(); DBCursor dbc = null;// ww w .jav a2s .c o m try { log.debug("Querying targets"); DBCollection targets = getTargetCollection(); long t = System.currentTimeMillis(); DBObject fields = MongoUtil.createDoc(EVENT_ACTION, 1, FIELD_COUNT, 1, EVENT_DATE, 1); dbc = targets.find(query, fields); t = System.currentTimeMillis() - t; if (t > 1000) { log.warn("getTargetStats query: {}\n took {}s", debugTrim(query), t / 1000.0); } BasicDBObject resultDoc; Map<String, StatAction> actions = new HashMap<String, StatAction>(); Map<String, Map<DateTime, StatCounter>> actionsDate = new HashMap<String, Map<DateTime, StatCounter>>(); Map<DateTime, StatCounter> dateCount; StatAction action; StatCounter dateCounter; String actionName; Long count; MutableDateTime dateTime = DateUtil.getDateTimeUTC(true).toMutableDateTime(); DateTime date; Date eventYearMonthTargetDate; int processed = 0; t = System.currentTimeMillis(); while (dbc.hasNext()) { resultDoc = (BasicDBObject) dbc.next(); actionName = resultDoc.getString(EVENT_ACTION); count = resultDoc.getLong(FIELD_COUNT); eventYearMonthTargetDate = (Date) resultDoc.get(EVENT_DATE); dateTime.setDate(eventYearMonthTargetDate.getTime()); date = dateTime.toDateTime(); action = actions.get(actionName); if (action == null) { actions.put(actionName, action = new StatAction(actionName, 0)); } action.add(count); dateCount = actionsDate.get(actionName); if (dateCount == null) { dateCount = new TreeMap<DateTime, StatCounter>(); actionsDate.put(actionName, dateCount); } dateCounter = dateCount.get(date); if (dateCounter == null) { dateCount.put(date, dateCounter = new StatCounter(actionName, 0, date.toDate())); } dateCounter.add(count); processed++; } //Build result list for (Entry<String, StatAction> entry : actions.entrySet()) { action = entry.getValue(); dateCount = actionsDate.get(action.getName()); List<StatCounter> targetList = action.getTargets(); for (Entry<DateTime, StatCounter> entryDate : dateCount.entrySet()) { StatCounter counter = entryDate.getValue(); targetList.add(counter); } result.add(action); } t = System.currentTimeMillis() - t; //TODO add warning level to X ms: if (t > 1000) { log.warn("getTargetStats query fetch: {}\n took {}s", debugTrim(query), t / 1000.0); } else { log.info("getTargetStats processed {} results in {}ms", processed, t); } } catch (Exception ex) { log.error("getTargetStats", ex); if (ex instanceof StatsEngineException) { throw (StatsEngineException) ex; } throw new StatsEngineException("getTargetStats", ex); } finally { MongoUtil.close(dbc); } return result; }
From source file:org.mongoste.model.StatEvent.java
License:Open Source License
public DateTime getYearMonthDate() { MutableDateTime dt = DateUtil.getDateTimeUTC().toMutableDateTime(); dt.setDateTime(getYear(), getMonth(), 1, 0, 0, 0, 0); return dt.toDateTime(); }
From source file:org.mongoste.util.DateUtil.java
License:Open Source License
public static DateTime trimTime(DateTime dateTime) { MutableDateTime mdt = dateTime.toMutableDateTime(); mdt.setTime(0, 0, 0, 0);//from w w w .j a v a 2 s. co m return mdt.toDateTime(); }
From source file:org.mongoste.util.DateUtil.java
License:Open Source License
public static DateTime toUTC(DateTime fromDate) { if (DateTimeZone.UTC.equals(fromDate.getZone())) { return fromDate; }//from www . j a v a2 s .com MutableDateTime dt = getDateTimeUTC().toMutableDateTime(); dt.setDateTime(fromDate.getYear(), fromDate.getMonthOfYear(), fromDate.getDayOfMonth(), fromDate.getHourOfDay(), fromDate.getMinuteOfHour(), fromDate.getSecondOfMinute(), fromDate.getMillisOfSecond()); return dt.toDateTime(); }
From source file:org.mongoste.util.DateUtil.java
License:Open Source License
public static DateTime buildUTCDate(int year, int month, int day) { MutableDateTime mdt = new DateTime(DateTimeZone.UTC).toMutableDateTime(); mdt.setDate(year, month, day);/*from w w w . ja v a 2 s .c o m*/ return trimTime(mdt.toDateTime()); }