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

The following examples show how to use org.apache.commons.lang3.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: ArtifactVersionNotification.java    From artifact-listener with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(ArtifactVersionNotification other) {
	if (this.equals(other)) {
		return 0;
	}
	int result;
	if (DateUtils.isSameDay(this.getCreationDate(), other.getCreationDate())) {
		result = this.getArtifactVersion().getArtifact().compareTo(other.getArtifactVersion().getArtifact());
		if (result == 0) {
			result = this.getArtifactVersion().compareTo(other.getArtifactVersion());
		}
	} else {
		result = (this.getCreationDate().before(other.getCreationDate()) ? -1 : 1);
	}
	return result;
}
 
Example 2
Source File: GetWorkCalendarEndTimeCmd.java    From FoxBPM with Apache License 2.0 6 votes vote down vote up
/**
 * 根据日期拿到对应的规则
 * @param date
 * @return
 */
private CalendarRuleEntity getCalendarRuleByDate(Date date) {
	CalendarRuleEntity calendarRuleEntity = null;
	for (CalendarRuleEntity calendarRuleEntity2 : calendarTypeEntity.getCalendarRuleEntities()) {
		if(calendarRuleEntity2.getWeek()==DateCalUtils.dayForWeek(date)) {
			calendarRuleEntity = calendarRuleEntity2;
		}
		if(calendarRuleEntity2.getWorkdate()!=null && DateUtils.isSameDay(calendarRuleEntity2.getWorkdate(), date) && calendarRuleEntity2.getCalendarPartEntities().size()!=0) {
			calendarRuleEntity = calendarRuleEntity2;
		}
	}
	//如果这天没有规则则再加一天
	if(calendarRuleEntity==null) {
		date = DateUtils.addDays(date, 1);
		return getCalendarRuleByDate(date);
	}
	return calendarRuleEntity;
}
 
Example 3
Source File: WxMaAnalysisServiceImplTest.java    From weixin-java-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetWeeklyVisitTrend() throws Exception {
  Calendar calendar = Calendar.getInstance();
  calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
  Date now = new Date();
  Date lastSunday = calendar.getTime();
  if (DateUtils.isSameDay(lastSunday, now)) {
    lastSunday = DateUtils.addDays(lastSunday, -7);
  }
  Date lastMonday = DateUtils.addDays(lastSunday, -6);

  final WxMaAnalysisService service = wxMaService.getAnalysisService();
  List<WxMaVisitTrend> trends = service.getWeeklyVisitTrend(lastMonday, lastSunday);
  assertEquals(1, trends.size());
  System.out.println(trends);
}
 
Example 4
Source File: ArtifactVersionLastUpdateDateModel.java    From artifact-listener with Apache License 2.0 6 votes vote down vote up
@Override
protected Map<Date, Set<ArtifactVersion>> load() {
	Map<Date, Set<ArtifactVersion>> result = Maps.newTreeMap(Collections.reverseOrder());
	List<ArtifactVersion> versionList = artifactVersionService.listRecentReleases(configurer.getLastUpdatesArtifactsLimit());

	Date previousDate = null;
	int daysCount = 0;
	for (ArtifactVersion version : versionList) {
		if (previousDate == null || !DateUtils.isSameDay(previousDate, version.getLastUpdateDate())) {
			if (daysCount >= configurer.getLastUpdatesDaysLimit()) {
				break;
			}
			previousDate = version.getLastUpdateDate();
			result.put(previousDate, Sets.<ArtifactVersion>newTreeSet());
			daysCount++;
		}
		result.get(previousDate).add(version);
	}
	return result;
}
 
Example 5
Source File: DailyCheckInService.java    From star-zone with Apache License 2.0 5 votes vote down vote up
public boolean isChecked(long userId){
    boolean checked = false;
    Date date = dailyCheckInRepository.getLatestTime(userId);

    if (date!=null) {
        checked = DateUtils.isSameDay(new Date(), date);
    }
    return checked;
}
 
Example 6
Source File: CalendarController.java    From es with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/move", method = RequestMethod.POST)
@ResponseBody
public String moveCalendar(
        @RequestParam("id") Long id,
        @RequestParam(value = "start", required = false) @DateTimeFormat(pattern = dataFormat) Date start,
        @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = dataFormat) Date end
) {
    Calendar calendar = calendarService.findOne(id);

    if(end == null) {
        end = start;
    }

    calendar.setStartDate(start);
    calendar.setLength((int)Math.ceil(1.0 * (end.getTime() - start.getTime()) / oneDayMillis));
    if(DateUtils.isSameDay(start, end)) {
        calendar.setLength(1);
    }
    if(!"00:00:00".equals(DateFormatUtils.format(start, "HH:mm:ss"))) {
        calendar.setStartTime(start);
    }
    if(!"00:00:00".equals(DateFormatUtils.format(end, "HH:mm:ss"))) {
        calendar.setEndTime(end);
    }
    calendarService.copyAndRemove(calendar);

    return "ok";
}
 
Example 7
Source File: I50Message.java    From jBSBE with Apache License 2.0 5 votes vote down vote up
public synchronized static int generateStan() {
	Calendar today = Calendar.getInstance();
	Date now = new Date();
	today.setTime(now);
	if (!DateUtils.isSameDay(today, initday)) {
		stanGenerator = new SimpleTraceGenerator(1);
		initday = today;
	}
	return stanGenerator.nextTrace();
}
 
Example 8
Source File: ScreensHelper.java    From sample-timesheets with Apache License 2.0 5 votes vote down vote up
public static String getColumnCaption(String columnId, Date date) {
    String caption = messages.getMessage(WeeklyReportEntry.class, "WeeklyReportEntry." + columnId);
    String format = COMMON_DAY_CAPTION_STYLE;

    if (workdaysTools.isHoliday(date) || workdaysTools.isWeekend(date)) {
        format = String.format(HOLIDAY_CAPTION_STYLE, format);
    }
    if (DateUtils.isSameDay(timeSource.currentTimestamp(), date)) {
        format = String.format(TODAY_CAPTION_STYLE, format);
    }
    return String.format(format, caption, DateUtils.toCalendar(date).get(Calendar.DAY_OF_MONTH));
}
 
Example 9
Source File: CalendarController.java    From es with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String showNewForm(
        @RequestParam(value = "start", required = false) @DateTimeFormat(pattern = dataFormat) Date start,
        @RequestParam(value = "end", required = false) @DateTimeFormat(pattern = dataFormat) Date end,
        Model model) {

    setColorList(model);

    Calendar calendar = new Calendar();
    calendar.setLength(1);
    if(start != null) {
        calendar.setStartDate(start);
        calendar.setLength((int)Math.ceil(1.0 * (end.getTime() - start.getTime()) / oneDayMillis));
        if(DateUtils.isSameDay(start, end)) {
            calendar.setLength(1);
        }
        if(!"00:00:00".equals(DateFormatUtils.format(start, "HH:mm:ss"))) {
            calendar.setStartTime(start);
        }
        if(!"00:00:00".equals(DateFormatUtils.format(end, "HH:mm:ss"))) {
            calendar.setEndTime(end);
        }

    }
    model.addAttribute("model", calendar);
    return viewName("newForm");
}
 
Example 10
Source File: DailyCheckInService.java    From star-zone with Apache License 2.0 5 votes vote down vote up
public boolean isChecked(long userId){
    boolean checked = false;
    Date date = dailyCheckInRepository.getLatestTime(userId);

    if (date!=null) {
        checked = DateUtils.isSameDay(new Date(), date);
    }
    return checked;
}
 
Example 11
Source File: BaseWorkTime.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
protected long workDaysBetween(Calendar s, Calendar e) {
	long i = 0;
	if (s.before(e)) {
		Calendar sx = DateUtils.toCalendar(s.getTime());
		Calendar ex = DateUtils.toCalendar(e.getTime());
		while (!DateUtils.isSameDay(sx, ex)) {
			sx.add(Calendar.DATE, 1);
			if (!this.isHoliday(sx)) {
				i++;
			}
		}
	}
	return i;
}
 
Example 12
Source File: AbstractDashBoard.java    From MtgDesktopCompanion with GNU General Public License v3.0 4 votes vote down vote up
@Override
public synchronized EditionsShakers getShakesForEdition(MagicEdition edition) throws IOException {
	
	Date c = evaluator.getCacheDate(edition);
	Date d = new Date();
	
	logger.trace(edition + " cache : " + c);
	
	if(c==null || !DateUtils.isSameDay(c, d))
	{
		logger.debug(edition + " not in cache.Loading it");
		evaluator.initCache(edition,getOnlineShakesForEdition(edition));	
	}
	EditionsShakers ret = evaluator.loadFromCache(edition);
	
	
	convert(ret.getShakes());
	
	
	return ret;
}
 
Example 13
Source File: GetWorkCalendarEndTimeCmd.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Date execute(CommandContext commandContext) {
	//拿到参数中的时间
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(begin);
	year = calendar.get(Calendar.YEAR);
	month = calendar.get(Calendar.MONTH) + 1;
	day = calendar.get(Calendar.DATE);
	
	//拿到对应的工作日历方案
	calendarTypeEntity = getCalendarTypeById(ruleId);
	
	//初始化日历类型,找到里面所有的工作时间
	initCalendarType(calendarTypeEntity);
	
	CalendarRuleEntity calendarRuleEntity = null;
	//从日历类型拿到对应的工作时间
	for (int k=0; k<calendarTypeEntity.getCalendarRuleEntities().size();k++) {
		CalendarRuleEntity calRuleEntity = calendarTypeEntity.getCalendarRuleEntities().get(k);
		//先判断在不在假期时间里
		if(calRuleEntity.getStatus()==FREESTATUS && calRuleEntity.getWorkdate()!=null && calRuleEntity.getYear()==year && DateUtils.isSameDay(calRuleEntity.getWorkdate(), begin)) {
			//如果这天没有设置时间段则跳过这一整天
			if(calRuleEntity.getCalendarPartEntities().size()==0) {
				begin = DateUtils.addDays(begin, 1);
				calendar.setTime(begin);
				calendar.set(Calendar.HOUR, 0);
				calendar.set(Calendar.MINUTE, 0);
				calendar.set(Calendar.SECOND, 0);
				begin = calendar.getTime();
				year = calendar.get(Calendar.YEAR);
				month = calendar.get(Calendar.MONTH) + 1;
				day = calendar.get(Calendar.DATE);
				calendar.get(Calendar.HOUR);
				calendar.get(Calendar.MINUTE);
				calendar.get(Calendar.SECOND);
			}
			//如果有设置时间段 则算出这天的工作时间去除假期时间的时间段 然后再计算
			else {
				calendarRuleEntity = getCalendarRuleEntityWithHoliday(calRuleEntity);
			}
		}
		//判断在不在工作时间里
		if(calRuleEntity.getWeek()!=0 && calRuleEntity.getYear()==year && calRuleEntity.getWeek()==DateCalUtils.dayForWeek(begin)) {
			calendarRuleEntity = calRuleEntity;
		}
		//如果不在工作时间内则继续循环找
		if(calendarRuleEntity == null) {
			continue;
		}
		//当找到规则时开始算时间
		else {
			Calendar endCalendar = Calendar.getInstance();
			Date endDate = CalculateEndTime(calendarRuleEntity);
			endCalendar.setTime(endDate);
			log.debug("最终的计算结果为:" + endCalendar.getTime());
			return endDate;
		}
	}
	
	log.debug("所给时间不在工作时间内,计算出错");
	return null;
}
 
Example 14
Source File: LegacyDateComparisonUtils.java    From tutorials with MIT License 4 votes vote down vote up
public static boolean isSameDay(Date date, Date dateToCompare) {
    return DateUtils.isSameDay(date, dateToCompare);
}
 
Example 15
Source File: TimeSpan.java    From dsworkbench with Apache License 2.0 4 votes vote down vote up
public boolean isValidAtSpecificDay() {
    return !isValidAtEveryDay() && !isValidAtExactTime() &&
            DateUtils.isSameDay(new Date(exactSpan.getMinimum()), new Date(exactSpan.getMaximum()));
}
 
Example 16
Source File: DateComparisonUtils.java    From tutorials with MIT License 4 votes vote down vote up
public static boolean isSameDayUsingApacheCommons(Date date1, Date date2) {
    return DateUtils.isSameDay(date1, date2);
}
 
Example 17
Source File: DateUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 是否同一天.
 * 
 * @see DateUtils#isSameDay(Date, Date)
 */
public static boolean isSameDay(@NotNull final Date date1, @NotNull final Date date2) {
	return DateUtils.isSameDay(date1, date2);
}
 
Example 18
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 2 votes vote down vote up
/**
 * Returns <code>true</code> if this object represents a date that is today's date
 *
 * @throws NullPointerException
 *            if {@link #getValue()} returns <code>null</code>
 */
public boolean isToday() {
  Validate.notNull(getValue(), getClass().getSimpleName() + " contains null value");
  return DateUtils.isSameDay(new Date(), getValue());
}
 
Example 19
Source File: BaseDateTimeType.java    From org.hl7.fhir.core with Apache License 2.0 2 votes vote down vote up
/**
 * Returns <code>true</code> if this object represents a date that is today's date
 *
 * @throws NullPointerException
 *            if {@link #getValue()} returns <code>null</code>
 */
public boolean isToday() {
  Validate.notNull(getValue(), getClass().getSimpleName() + " contains null value");
  return DateUtils.isSameDay(new Date(), getValue());
}
 
Example 20
Source File: DateUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 判断指定的日期 <code>date</code>,是不是今天的日期.
 * 
 * <h3>示例:</h3>
 * <blockquote>
 * 
 * <pre class="code">
 * DateUtil.isToday(new Date()) = true
 * 
 * <span style="color:green">// 如果今天 是2017年12月14日</span>
 * DateUtil.isToday(toDate("2016-06-16 22:59:00", COMMON_DATE_AND_TIME)) = false
 * </pre>
 * 
 * </blockquote>
 * 
 * <h3>性能对比:</h3>
 * 
 * <blockquote>
 * 
 * 1000000 循环,
 * 
 * <ul>
 * <li>DateUtils#isSameDay(Date, Date) ,893毫秒;</li>
 * <li>isEquals(date, new Date(), DatePattern.COMMON_DATE),1秒335毫秒</li>
 * <li>DateExtensionUtil.getDayStartAndEndPair 1秒185毫秒</li>
 * </ul>
 * </blockquote>
 *
 * @param date
 *            指定的日期
 * @return 如果指定的日期是今天,那么返回true,否则返回false <br>
 *         如果 <code>date</code> 是null,抛出 {@link NullPointerException}<br>
 * @see DateUtils#isSameDay(Date, Date)
 * @since 1.10.6
 */
public static boolean isToday(Date date){
    Validate.notNull(date, "date can't be null!");
    return DateUtils.isSameDay(date, now());
}