Java Code Examples for org.apache.commons.lang.time.DateUtils#isSameDay()

The following examples show how to use org.apache.commons.lang.time.DateUtils#isSameDay() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeLineController.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
@PostMapping("postTimeline")
@ResponseBody
public Object postTimeline(UserTimeLine timeLine){
    BaseResult result = new BaseResult();
    if(timeLine.getUserId() == null){
        result.setResult(ResultEnum.USER_NOT_LOGIN);
        return result;
    }
    if(StringUtils.isBlank(timeLine.getContent())){
        result.setResult(ResultEnum.PARAM_NULL);
        return result;
    }
    UserTimeLineExample example = new UserTimeLineExample();
    example.setOrderByClause("create_time desc");
    example.createCriteria().andUserIdEqualTo(timeLine.getUserId());
    UserTimeLine line = timeLineService.selectFirstByExample(example);
    if(line != null && DateUtils.isSameDay(line.getCreateTime(),new Date())){
        result.setResult(ResultEnum.TIME_LINE_SAME_DAY);
        return result;
    }
    timeLine.setCreateTime(new Date());
    timeLine.setDelFlag(YesNoEnum.NO.getValue());
    timeLineService.insert(timeLine);
    return result;

}
 
Example 2
Source File: SourceForgeManager.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public CommunicationChannelDelta getDelta(DB db, Discussion discussion, Date date) throws Exception {

	java.util.Date day = date.toJavaDate();

	Cache<SourceForgeArticle, String> articleCache = articleCaches.getCache(discussion, true);
	Iterable<SourceForgeArticle> articles = articleCache.getItemsAfterDate(day);

	SourceForgeCommunicationChannelDelta delta = new SourceForgeCommunicationChannelDelta();
	delta.setNewsgroup(discussion);
	for (SourceForgeArticle article : articles) {
		java.util.Date articleDate = article.getDate();
		if (article.getUpdateDate() != null)
			articleDate = article.getUpdateDate();
		if (DateUtils.isSameDay(articleDate, day)) {
			article.setText(getContents(db, discussion, article));
			delta.getArticles().add(article);
		}
	}
	System.err.println("Delta for date " + date + " contains " + delta.getArticles().size());
	return delta;
}
 
Example 3
Source File: CheckBase.java    From kfs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see org.kuali.kfs.fp.businessobject.Check#isLike(org.kuali.kfs.fp.businessobject.Check)
 */
@Override
public boolean isLike(Check other) {
    boolean like = false;

    if (StringUtils.equals(checkNumber, other.getCheckNumber())) {
        if (StringUtils.equals(description, other.getDescription())) {
            if (StringUtils.equals(financialDocumentTypeCode, other.getFinancialDocumentTypeCode()) && StringUtils.equals(cashieringStatus, other.getCashieringStatus())) {
                if (StringUtils.equals(documentNumber, other.getDocumentNumber())) {
                    if (ObjectUtils.nullSafeEquals(sequenceId, other.getSequenceId())) {
                        if (ObjectUtils.nullSafeEquals(financialDocumentDepositLineNumber, other.getFinancialDocumentDepositLineNumber())) {

                            if (DateUtils.isSameDay(checkDate, other.getCheckDate())) {
                                if ((amount != null) && amount.equals(other.getAmount())) {
                                    like = true;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return like;
}
 
Example 4
Source File: HighchartPoint.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
public static HighchartPoint getFromAppCommandStats(AppCommandStats appCommandStats, Date currentDate, int diffDays) throws ParseException {
    Date collectDate = getDateTime(appCommandStats.getCollectTime());
    if (!DateUtils.isSameDay(currentDate, collectDate)) {
        return null;
    }
    
    //显示用的时间
    String date = null;
    try {
        date = DateUtil.formatDate(collectDate, "yyyy-MM-dd HH:mm");
    } catch (Exception e) {
        date = DateUtil.formatDate(collectDate, "yyyy-MM-dd HH");
    }
    // y坐标
    long commandCount = appCommandStats.getCommandCount();
    // x坐标
    //为了显示在一个时间范围内
    if (diffDays > 0) {
        collectDate = DateUtils.addDays(collectDate, diffDays);
    }
    
    return new HighchartPoint(collectDate.getTime(), commandCount, date);
}
 
Example 5
Source File: JournalQueryService.java    From symphonyx with Apache License 2.0 6 votes vote down vote up
/**
 * Section generated today?
 *
 * @return {@code true} if section generated, returns {@code false} otherwise
 */
public synchronized boolean hasSectionToday() {
    try {
        final Query query = new Query().addSort(Keys.OBJECT_ID, SortDirection.DESCENDING).
                setCurrentPageNum(1).setPageSize(1);

        query.setFilter(new PropertyFilter(Article.ARTICLE_TYPE, FilterOperator.EQUAL,
                Article.ARTICLE_TYPE_C_JOURNAL_SECTION));

        final JSONObject result = articleRepository.get(query);
        final List<JSONObject> journals = CollectionUtils.<JSONObject>jsonArrayToList(result.optJSONArray(Keys.RESULTS));

        if (journals.isEmpty()) {
            return false;
        }

        final JSONObject maybeToday = journals.get(0);
        final long created = maybeToday.optLong(Article.ARTICLE_CREATE_TIME);

        return DateUtils.isSameDay(new Date(created), new Date());
    } catch (final RepositoryException e) {
        LOGGER.log(Level.ERROR, "Check section generated failed", e);

        return false;
    }
}
 
Example 6
Source File: ReleaseObject.java    From ezScrum with GNU General Public License v2.0 5 votes vote down vote up
public boolean containsSprint(SprintObject sprint) {
	Date sprintStartDate = DateUtil.dayFilter(sprint.getStartDateString());
	Date sprintDueDate = DateUtil.dayFilter(sprint.getDueDateString());
	boolean isContains = sprintStartDate.after(mStartDate)
			|| DateUtils.isSameDay(sprintStartDate, mStartDate);
	isContains &= sprintDueDate.before(mDueDate)
			|| DateUtils.isSameDay(sprintDueDate, mDueDate);
	return isContains;
}
 
Example 7
Source File: ActivityQueryService.java    From symphonyx with Apache License 2.0 5 votes vote down vote up
/**
 * Did collect 1A0001 today?
 *
 * @param userId the specified user id
 * @return {@code true} if collected, returns {@code false} otherwise
 */
public synchronized boolean isCollected1A0001Today(final String userId) {
    final Date now = new Date();

    final List<JSONObject> records = pointtransferQueryService.getLatestPointtransfers(userId,
            Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_1A0001_COLLECT, 1);
    if (records.isEmpty()) {
        return false;
    }

    final JSONObject maybeToday = records.get(0);
    final long time = maybeToday.optLong(Pointtransfer.TIME);

    return DateUtils.isSameDay(now, new Date(time));
}
 
Example 8
Source File: ActivityQueryService.java    From symphonyx with Apache License 2.0 5 votes vote down vote up
/**
 * Does participate 1A0001 today?
 *
 * @param userId the specified user id
 * @return {@code true} if participated, returns {@code false} otherwise
 */
public synchronized boolean is1A0001Today(final String userId) {
    final Date now = new Date();

    final List<JSONObject> records = pointtransferQueryService.getLatestPointtransfers(userId,
            Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_1A0001, 1);
    if (records.isEmpty()) {
        return false;
    }

    final JSONObject maybeToday = records.get(0);
    final long time = maybeToday.optLong(Pointtransfer.TIME);

    return DateUtils.isSameDay(now, new Date(time));
}
 
Example 9
Source File: ActivityQueryService.java    From symphonyx with Apache License 2.0 5 votes vote down vote up
/**
 * Does checkin today?
 *
 * @param userId the specified user id
 * @return {@code true} if checkin succeeded, returns {@code false} otherwise
 */
public synchronized boolean isCheckedinToday(final String userId) {
    final Calendar calendar = Calendar.getInstance();
    final int hour = calendar.get(Calendar.HOUR_OF_DAY);
    if (hour < Symphonys.getInt("activityDailyCheckinTimeMin")
            || hour > Symphonys.getInt("activityDailyCheckinTimeMax")) {
        return true;
    }

    final Date now = new Date();

    JSONObject user = userCache.getUser(userId);

    try {
        if (null == user) {
            user = userRepository.get(userId);
        }
    } catch (final RepositoryException e) {
        LOGGER.log(Level.ERROR, "Checks checkin failed", e);

        return true;
    }

    final List<JSONObject> records = pointtransferQueryService.getLatestPointtransfers(userId,
            Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_CHECKIN, 1);
    if (records.isEmpty()) {
        return false;
    }

    final JSONObject maybeToday = records.get(0);
    final long time = maybeToday.optLong(Pointtransfer.TIME);

    return DateUtils.isSameDay(now, new Date(time));
}
 
Example 10
Source File: HighchartPoint.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
public static HighchartPoint getFromAppStats(AppStats appStat, String statName, Date currentDate, int diffDays) throws ParseException {
    Date collectDate = getDateTime(appStat.getCollectTime());
    if (!DateUtils.isSameDay(currentDate, collectDate)) {
        return null;
    }
    //显示用的时间
    String date = null;
    try {
        date = DateUtil.formatDate(collectDate, "yyyy-MM-dd HH:mm");
    } catch (Exception e) {
        date = DateUtil.formatDate(collectDate, "yyyy-MM-dd HH");
    }
    // y坐标
    long count = 0;
    if ("hits".equals(statName)) {
        count = appStat.getHits();
    } else if ("misses".equals(statName)) {
        count = appStat.getMisses();
    } else if ("usedMemory".equals(statName)) {
        count = appStat.getUsedMemory() / 1024 / 1024;
    } else if ("netInput".equals(statName)) {
        count = appStat.getNetInputByte();
    } else if ("netOutput".equals(statName)) {
        count = appStat.getNetOutputByte();
    } else if ("connectedClient".equals(statName)) {
        count = appStat.getConnectedClients();
    } else if ("objectSize".equals(statName)) {
        count = appStat.getObjectSize();
    } else if ("hitPercent".equals(statName)) {
        count = appStat.getHitPercent();
    }
    //为了显示在一个时间范围内
    if (diffDays > 0) {
        collectDate = DateUtils.addDays(collectDate, diffDays);
    }
    
    return new HighchartPoint(collectDate.getTime(), count, date);
}
 
Example 11
Source File: RedmineManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public BugTrackingSystemDelta getDelta(DB db, RedmineBugIssueTracker bugTracker, Date date) throws Exception {
	java.util.Date day = date.toJavaDate();

	Cache<RedmineIssue, String> issueCache = issueCaches
			.getCache(bugTracker, true);
	Iterable<RedmineIssue> issues = issueCache.getItemsAfterDate(day);

	RedmineBugTrackingSystemDelta delta = new RedmineBugTrackingSystemDelta();
	delta.setBugTrackingSystem(bugTracker);
	for (RedmineIssue issue : issues) {

		if (DateUtils.isSameDay(issue.getCreationTime(), day)) {
			delta.getNewBugs().add(issue);
		} else if (DateUtils.isSameDay(issue.getUpdateDate(), day)) {
			delta.getUpdatedBugs().add(issue);
		} 

		// Store updated comments in delta
		for (BugTrackingSystemComment comment : issue.getComments()) {
			RedmineComment redmineComment = (RedmineComment) comment;
			java.util.Date created = redmineComment.getCreationTime();

			if (DateUtils.isSameDay(created, day)) {
				delta.getComments().add(comment);
			}
		}
	}

	return delta;
}
 
Example 12
Source File: CacheProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * returns true if one of dates matches date.
 * 
 * @param date
 * @param dates
 * @return
 */
public static boolean findMatchOnDate(Date date, Date... dates) {
	for (Date d : dates) {
		if (null != d && DateUtils.isSameDay(date, d)) {
			return true;
		}
	}

	return false;
}
 
Example 13
Source File: CacheProvider.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * returns true if one of dates matches date.
 * 
 * @param date
 * @param dates
 * @return
 */
public static boolean findMatchOnDate(Date date, Date... dates) {
	for (Date d : dates) {
		if (null != d && DateUtils.isSameDay(date, d)) {
			return true;
		}
	}

	return false;
}
 
Example 14
Source File: SourceForgeManager.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public BugTrackingSystemDelta getDelta(DB db, SourceForgeBugTrackingSystem bugTracker, Date date) throws Exception {

	java.util.Date day = date.toJavaDate();

	Cache<SourceForgeTicket, String> ticketCache = ticketCaches
			.getCache(bugTracker, true);
	Iterable<SourceForgeTicket> tickets = ticketCache
			.getItemsAfterDate(day);

	SourceForgeTrackingSystemDelta delta = new SourceForgeTrackingSystemDelta();
	
	delta.setBugTrackingSystem(bugTracker);
	
	for (SourceForgeTicket ticket : tickets) {

		if (DateUtils.isSameDay(ticket.getUpdateDate(), day)) {
			delta.getUpdatedBugs().add(ticket);
		} else if (DateUtils.isSameDay(ticket.getCreationTime(), day)) {
			delta.getNewBugs().add(ticket);
		}

		// Store updated comments in delta
		for (BugTrackingSystemComment comment : ticket.getComments()) {
			SourceForgeComment sfComment = (SourceForgeComment) comment;

			if(sfComment.isHexId())
			{
				String commentHexId=sfComment.getCommentId();
				
				if(commentHexId.contains("/"))									//In Sourceforge the comments can reply a previous message, and the last number indicates the true ID
				{
					Matcher m = replyComment.matcher(commentHexId); 
					if(m.find())
					{
						commentHexId=m.group(1);
					}
				}
				
				long commentLongId = Long.parseLong(commentHexId,16); 			//It seems to be in base 16
				
				sfComment.setCommentId(String.valueOf(commentLongId));
				sfComment.setHexId(false);
			}
			java.util.Date updated = sfComment.getUpdateDate();
			java.util.Date created = sfComment.getCreationTime();

			if (DateUtils.isSameDay(created, day)) {
				delta.getComments().add(comment);
			} else if (updated != null && DateUtils.isSameDay(updated, day)) {
				delta.getComments().add(comment);
			}
		}
	}

	return delta;
}
 
Example 15
Source File: WeeklyCalendarComponentRenderer.java    From olat with Apache License 2.0 4 votes vote down vote up
private void renderEventTooltip(final CalendarEntryRenderWrapper eventWrapper, final String escapedSubject, final boolean hideSubject, final StringOutput sb,
        final URLBuilder ubu, final Locale locale) {
    final CalendarEntry event = eventWrapper.getEvent();
    // Tooltip content
    sb.append("<div class=\"o_cal_wv_event_tooltip");
    if (event.isAllDayEvent()) {
        // add marker css class used in js code to identify all day events
        sb.append(" o_cal_allday");
    }
    sb.append("\">");
    // time
    sb.append("<div class=\"o_cal_time\">\n");
    final Translator translator = PackageUtil.createPackageTranslator(CalendarController.class, locale);
    final Calendar cal = CalendarUtils.createCalendarInstance(locale);
    final Date begin = event.getBegin();
    final Date end = event.getEnd();
    cal.setTime(begin);
    sb.append(StringHelper.formatLocaleDateFull(begin.getTime(), locale));
    if (!event.isAllDayEvent()) {
        sb.append("<br />").append(StringHelper.formatLocaleTime(begin.getTime(), locale));
        sb.append(" - ");
        if (!DateUtils.isSameDay(begin, end)) {
            sb.append(StringHelper.formatLocaleDateFull(end.getTime(), locale)).append(", ");
        }
        sb.append(StringHelper.formatLocaleTime(end.getTime(), locale));
    }
    sb.append("</div>\n");
    if (!hideSubject) {
        sb.append("<div class=\"o_cal_wv_event_tooltip_content\">");
        sb.append(escapedSubject);
    }

    // location
    if (StringHelper.containsNonWhitespace(event.getLocation())) {
        sb.append("<div class=\"o_cal_location\">\n");
        if (!hideSubject) {
            sb.append("<b>").append(translator.translate("cal.form.location")).append("</b>:");
            sb.append(event.getLocation());
        }
        sb.append("</div>\n");
    }
    // links
    if (!hideSubject) {
        renderEventLinks(event, sb);
    }

    if (eventWrapper.getCalendarAccess() == CalendarRenderWrapper.ACCESS_READ_WRITE) {
        // edit link
        sb.append("<div class=\"o_cal_tooltip_buttons\"><a class=\"b_button b_xsmall\" href=\"");
        ubu.buildURI(sb, new String[] { WeeklyCalendarComponent.ID_CMD, WeeklyCalendarComponent.ID_PARAM }, new String[] {
                WeeklyCalendarComponent.CMD_EDIT,
                event.getCalendar().getCalendarID() + WeeklyCalendarComponent.ID_PARAM_SEPARATOR + event.getID() + WeeklyCalendarComponent.ID_PARAM_SEPARATOR
                        + event.getBegin().getTime() }, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
        sb.append("\" ");
        if (isIframePostEnabled) {
            ubu.appendTarget(sb);
        }
        sb.append("><span>");
        sb.append(translator.translate("edit"));
        sb.append("</span></a></div>");
    }

    // tooltip_content
    if (!hideSubject) {
        sb.append("</div>");
    }
    // event_tooltip
    sb.append("</div>");
}
 
Example 16
Source File: WeeklyCalendarComponentRenderer.java    From olat with Apache License 2.0 4 votes vote down vote up
private void renderEventTooltip(final CalendarEntryRenderWrapper eventWrapper, final String escapedSubject, final boolean hideSubject, final StringOutput sb,
        final URLBuilder ubu, final Locale locale) {
    final CalendarEntry event = eventWrapper.getEvent();
    // Tooltip content
    sb.append("<div class=\"o_cal_wv_event_tooltip");
    if (event.isAllDayEvent()) {
        // add marker css class used in js code to identify all day events
        sb.append(" o_cal_allday");
    }
    sb.append("\">");
    // time
    sb.append("<div class=\"o_cal_time\">\n");
    final Translator translator = PackageUtil.createPackageTranslator(CalendarController.class, locale);
    final Calendar cal = CalendarUtils.createCalendarInstance(locale);
    final Date begin = event.getBegin();
    final Date end = event.getEnd();
    cal.setTime(begin);
    sb.append(StringHelper.formatLocaleDateFull(begin.getTime(), locale));
    if (!event.isAllDayEvent()) {
        sb.append("<br />").append(StringHelper.formatLocaleTime(begin.getTime(), locale));
        sb.append(" - ");
        if (!DateUtils.isSameDay(begin, end)) {
            sb.append(StringHelper.formatLocaleDateFull(end.getTime(), locale)).append(", ");
        }
        sb.append(StringHelper.formatLocaleTime(end.getTime(), locale));
    }
    sb.append("</div>\n");
    if (!hideSubject) {
        sb.append("<div class=\"o_cal_wv_event_tooltip_content\">");
        sb.append(escapedSubject);
    }

    // location
    if (StringHelper.containsNonWhitespace(event.getLocation())) {
        sb.append("<div class=\"o_cal_location\">\n");
        if (!hideSubject) {
            sb.append("<b>").append(translator.translate("cal.form.location")).append("</b>:");
            sb.append(StringHelper.escapeHtml(event.getLocation()));
        }
        sb.append("</div>\n");
    }
    // links
    if (!hideSubject) {
        renderEventLinks(event, sb);
    }

    if (eventWrapper.getCalendarAccess() == CalendarRenderWrapper.ACCESS_READ_WRITE) {
        // edit link
        sb.append("<div class=\"o_cal_tooltip_buttons\"><a class=\"b_button b_xsmall\" href=\"");
        ubu.buildURI(sb, new String[] { WeeklyCalendarComponent.ID_CMD, WeeklyCalendarComponent.ID_PARAM }, new String[] {
                WeeklyCalendarComponent.CMD_EDIT,
                event.getCalendar().getCalendarID() + WeeklyCalendarComponent.ID_PARAM_SEPARATOR + event.getID() + WeeklyCalendarComponent.ID_PARAM_SEPARATOR
                        + event.getBegin().getTime() }, isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
        sb.append("\" ");
        if (isIframePostEnabled) {
            ubu.appendTarget(sb);
        }
        sb.append("><span>");
        sb.append(translator.translate("edit"));
        sb.append("</span></a></div>");
    }

    // tooltip_content
    if (!hideSubject) {
        sb.append("</div>");
    }
    // event_tooltip
    sb.append("</div>");
}
 
Example 17
Source File: DateTimeUtils.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Returns true, if two calendar objects are on the same day ignoring time.
 */
public static boolean isSameDay(Calendar cal1, Calendar cal2) {
    return cal1 != null && cal2 != null && DateUtils.isSameDay(cal1, cal2);
}
 
Example 18
Source File: DateTimeUtils.java    From openhab1-addons with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Returns true, if two calendar objects are on the same day ignoring time.
 */
public static boolean isSameDay(Calendar cal1, Calendar cal2) {
    return cal1 != null && cal2 != null && DateUtils.isSameDay(cal1, cal2);
}
 
Example 19
Source File: JiraManager.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public BugTrackingSystemDelta getDelta(DB db, JiraBugTrackingSystem bugTracker, Date date) throws Exception {

	newAndUpdatesIssuesIds = new HashSet<String>();
	
	boolean commentAdded;
	
	java.util.Date day = date.toJavaDate();

	Cache<JiraIssue, String> issueCache = issueCaches
			.getCache(bugTracker, true);
	Iterable<JiraIssue> issues = issueCache.getItemsAfterDate(day);

	JiraBugTrackingSystemDelta delta = new JiraBugTrackingSystemDelta();
	delta.setBugTrackingSystem(bugTracker);
	
	for (JiraIssue issue : issues) {

		if (DateUtils.isSameDay(issue.getUpdateDate(), day)) {
			delta.getUpdatedBugs().add(issue);
			newAndUpdatesIssuesIds.add(issue.getBugId());
		} else if (DateUtils.isSameDay(issue.getCreationTime(), day)) {
			delta.getNewBugs().add(issue);
			newAndUpdatesIssuesIds.add(issue.getBugId());
		}

		// Store updated comments in delta
		for (BugTrackingSystemComment comment : issue.getComments()) {
			JiraComment jiraComment = (JiraComment) comment;

			java.util.Date updated = jiraComment.getUpdateDate();
			java.util.Date created = jiraComment.getCreationTime();
			commentAdded=false;
			if (DateUtils.isSameDay(created, day)) {
				commentAdded=true;
				delta.getComments().add(comment);
			} else if (updated != null && DateUtils.isSameDay(updated, day)) {
				commentAdded=true;
				delta.getComments().add(comment);
			}
			if(commentAdded && !(newAndUpdatesIssuesIds.contains(issue.getBugId())))
			{
				newAndUpdatesIssuesIds.add(issue.getBugId());
				delta.getUpdatedBugs().add(issue);
			}
		}
	}

	return delta;
}