List of usage examples for org.apache.commons.lang3.time DateUtils isSameDay
public static boolean isSameDay(final Calendar cal1, final Calendar cal2)
Checks if two calendar objects are on the same day ignoring time.
28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.
From source file:org.foxbpm.calendar.mybatis.cmd.GetWorkCalendarEndTimeCmd.java
/** * ???/*from w ww . j ava2s .com*/ * @param begin2 * @return */ private boolean isHoliday(Date begin2) { boolean isHoliday = false; for (CalendarRuleEntity calendarRuleEntity : calendarTypeEntity.getCalendarRuleEntities()) { if (calendarRuleEntity.getStatus() == FREESTATUS && calendarRuleEntity.getWorkdate() != null && calendarRuleEntity.getYear() == year && DateUtils.isSameDay(calendarRuleEntity.getWorkdate(), begin) && calendarRuleEntity.getCalendarPartEntities().size() == 0) { isHoliday = true; } } return isHoliday; }
From source file:org.foxbpm.calendar.mybatis.cmd.GetWorkCalendarEndTimeCmd.java
/** * ?/*from ww w . j a va 2 s. c o m*/ * @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; }
From source file:org.glenans.extractor.model.StageTest.java
/** * Test of getName method, of class Stage. *//* www. ja v a 2 s . co m*/ public void testconvertStringToDate() { System.out.println( "convertStringToDate in a static way, I know it's bad but it's just to illustrate how to Unit Test"); Date date = Stage.convertStringToDate(""); assertTrue(date == null); date = Stage.convertStringToDate("04/10/15"); Date date1 = Stage.convertStringToDate("18/07/15 15H00"); Date date2 = Stage.convertStringToDate("24/07/15 17H00"); Date date3 = Stage.convertStringToDate("01/08/15 15H00"); Date date4 = Stage.convertStringToDate("7/08/15 17H00"); Date date5 = Stage.convertStringToDate("7/08/15 17H01"); Date date6 = Stage.convertStringToDate("07/08/15 17H01"); Date date7 = Stage.convertStringToDate("07/8/15 17H01"); Date date8 = Stage.convertStringToDate("7/8/15 17H01"); Date date9 = Stage.convertStringToDate("12/09/15 14h30"); // System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(null)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date1)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date2)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date3)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date4)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date5)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date6)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date7)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date8)); System.out.println(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date9)); // Test conversion is OK assertNotNull(date); assertNotNull(date1); assertNotNull(date2); assertNotNull(date3); assertNotNull(date4); assertNotNull(date5); assertNotNull(date6); assertNotNull(date7); assertNotNull(date8); assertNotNull(date9); assertEquals(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date), "04/10/15 00:00"); // assertEquals(new SimpleDateFormat(Stage.DATE_PATTERN_OUTPUT, Locale.FRANCE).format(date1),"04/10/15 00:00"); //18/07/15 15:00 //24/07/15 17:00 //01/08/15 15:00 //07/08/15 17:00 //07/08/15 17:01 //07/08/15 17:01 //07/08/15 17:01 //07/08/15 17:01 //12/09/15 14:30 // test date is the same but time is not assertTrue(DateUtils.isSameDay(date4, date5)); assertFalse(DateUtils.isSameInstant(date4, date5)); // Comparison test assertTrue(date1.before(date2)); // Comparison Date with different format on day assertTrue(DateUtils.isSameInstant(date6, date5)); assertTrue(DateUtils.isSameInstant(date7, date5)); assertTrue(DateUtils.isSameInstant(date8, date5)); }
From source file:org.inheritsource.service.common.domain.Timeline.java
public TreeMap<Date, List<TimelineItem>> getTimelineByDay() { TreeMap<Date, List<TimelineItem>> timelineByDay = new TreeMap<Date, List<TimelineItem>>( new Comparator<Date>() { @Override//w w w .j a va2 s .co m public int compare(Date o1, Date o2) { int result = 0; if (o1 == null) { if (o2 == null) { return 0; } else { result = 1; } } else { if (o2 == null) { return -1; } else { result = -o1.compareTo(o2); } } return result; } }); if (!sorted) { sort(); } Date keyDay = null; List<TimelineItem> dayItems = null; if (items != null) { for (TimelineItem item : items) { if (item != null) { if (item.getTimestamp() == null) { log.error("Timestamp in TimelineItem is not expected to be null: " + item); } else { if (keyDay == null || !DateUtils.isSameDay(keyDay, item.getTimestamp())) { // new day in Map => create new day in map and a new list for that day keyDay = DateUtils.truncate(item.getTimestamp(), Calendar.DAY_OF_MONTH); dayItems = new ArrayList<TimelineItem>(); timelineByDay.put(keyDay, dayItems); } // always add item to current day in map if (dayItems != null) { dayItems.add(item); } else { log.error("dayItems should never be null on add"); } } } } } return timelineByDay; }
From source file:org.kalypso.model.hydrology.operation.evaporation.AbstractEvaporationCalculator.java
private TupleModelDataSet getDataSet(final ITimeseriesCache humidity, final Calendar ptr, final String type) { final TreeMap<Date, TupleModelDataSet[]> valueMap = humidity.getValueMap(); final Date base = ptr.getTime(); final SortedMap<Date, TupleModelDataSet[]> headMap = valueMap.headMap(base); final SortedMap<Date, TupleModelDataSet[]> tailMap = valueMap.tailMap(base); if (!headMap.isEmpty() && DateUtils.isSameDay(headMap.lastKey(), base)) return getDataSet(headMap.get(headMap.lastKey()), type); else if (!tailMap.isEmpty() && DateUtils.isSameDay(tailMap.firstKey(), base)) return getDataSet(tailMap.get(tailMap.firstKey()), type); return null;//from w ww . j a v a2s. c o m }
From source file:org.kalypso.model.hydrology.operation.evaporation.AbstractEvaporationCalculator.java
private IStatus calculateEvaporation(final IProgressMonitor monitor) { final IStatusCollector stati = new StatusCollector(ModelNA.PLUGIN_ID); final Calendar to = CalendarUtilities.getCalendar(getDateRange().getTo(), KalypsoCorePlugin.getDefault().getTimeZone()); final Calendar ptr = CalendarUtilities.getCalendar(getDateRange().getFrom(), KalypsoCorePlugin.getDefault().getTimeZone()); ptr.set(Calendar.HOUR_OF_DAY, 12); ptr.set(Calendar.MINUTE, 0);//w ww . ja va2 s .co m ptr.set(Calendar.SECOND, 0); ptr.set(Calendar.MILLISECOND, 0); // iterate over values inherit the given date range while (ptr.before(to) || DateUtils.isSameDay(ptr, to)) { final Double humidity = getValue( getDataSet(getHumidity(), ptr, ITimeseriesConstants.TYPE_MEAN_HUMIDITY)); final Double sunshine = getValue( getDataSet(getSunshine(), ptr, ITimeseriesConstants.TYPE_SUNSHINE_HOURS)); final Double temperature = getValue( getDataSet(getTemperature(), ptr, ITimeseriesConstants.TYPE_MEAN_TEMPERATURE)); final Double windVelocity = getValue( getDataSet(getWindVelocity(), ptr, ITimeseriesConstants.TYPE_MEAN_WIND_VELOCITY)); if (Doubles.isNaN(humidity, sunshine, temperature, windVelocity)) { final SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$ sdf.setTimeZone(KalypsoCorePlugin.getDefault().getTimeZone()); final String msg = String.format(Messages.getString("AbstractEvaporationCalculator_2"), // //$NON-NLS-1$ sdf.format(ptr.getTime()), // Objects.firstNonNull(humidity, Double.NaN), // Objects.firstNonNull(sunshine, Double.NaN), // Objects.firstNonNull(temperature, Double.NaN), // Objects.firstNonNull(windVelocity, Double.NaN)); stati.add(IStatus.WARNING, msg); } else { final Double evaporation = doCalculate(humidity, sunshine, temperature, windVelocity, ptr); if (Objects.isNotNull(evaporation)) addResult(ptr.getTime(), evaporation); } ptr.add(Calendar.DAY_OF_MONTH, 1); } monitor.done(); return stati.asMultiStatus(Messages.getString("AbstractEvaporationCalculator_3")); //$NON-NLS-1$ }
From source file:org.kuali.coeus.common.committee.impl.service.impl.CommitteeScheduleServiceImplBase.java
/** * Helper method to test if date is available (non conflicting). * @param committeeSchedules//from w ww . j ava2 s . c o m * @param date * @return */ protected Boolean isDateAvailable(List<CS> committeeSchedules, java.sql.Date date) { boolean retVal = true; for (CS committeeSchedule : committeeSchedules) { Date scheduledDate = committeeSchedule.getScheduledDate(); if ((scheduledDate != null) && DateUtils.isSameDay(scheduledDate, date)) { retVal = false; break; } } return retVal; }
From source file:org.openmrs.module.kenyaemr.util.EmrUtils.java
/** * Checks if a given date is today/*from w w w.j a v a 2 s . c o m*/ * @param date the date * @return true if date is today */ public static boolean isToday(Date date) { return DateUtils.isSameDay(date, new Date()); }
From source file:org.openmrs.module.openconceptlab.Utils.java
/** * Formats a date, automatically inferring the best format * @param date the date// w w w.j a v a2 s . c o m * @return the string value */ public static String formatDateAuto(Date date) { if (DateUtils.isSameDay(date, new Date())) { return "Today at " + formatTime(date); } else if (DateUtils.isSameDay(date, dateAddDays(new Date(), -1))) { return "Yesterday at " + formatTime(date); } else { return formatDateTime(date); } }
From source file:org.ossmeter.platform.bugtrackingsystem.github.GitHubManager.java
/** * /*from ww w . j a va 2 s .c o m*/ * Gets issues that have either been updated or created on the given date * * @param bugTracker * @param since * @param github * @param delta * @throws Exception */ private void getIssues(GitHubBugTracker bugTracker, Date on, GitHubSession github, GitHubBugTrackingSystemDelta delta) throws Exception { java.util.Date day = on.toJavaDate(); Cache<GitHubIssue, String> issuesCache = issueCaches.getCache(bugTracker, true); Iterable<GitHubIssue> issues = issuesCache.getItemsOnDate(day); for (GitHubIssue issue : issues) { if (DateUtils.isSameDay(issue.getCreationTime(), day)) { delta.getNewBugs().add(issue); } else { delta.getUpdatedBugs().add(issue); } } }