List of usage examples for org.apache.commons.lang.time DateUtils isSameDay
public static boolean isSameDay(Calendar cal1, 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.dspace.app.util.DailyFileAppender.java
protected void subAppend(LoggingEvent pobjEvent) { Date dtNow = new Date(System.currentTimeMillis()); boolean rollover = false; if (mMonthOnly) { Calendar now = Calendar.getInstance(); Calendar cur = Calendar.getInstance(); now.setTime(dtNow);//from ww w . jav a 2 s.c o m cur.setTime(mstrDate); rollover = !(now.get(Calendar.YEAR) == cur.get(Calendar.YEAR) && now.get(Calendar.MONTH) == cur.get(Calendar.MONTH)); } else { rollover = !(DateUtils.isSameDay(dtNow, mstrDate)); } if (rollover) { try { rollOver(dtNow); } catch (IOException IOEx) { LogLog.error("rollOver() failed!", IOEx); } } super.subAppend(pobjEvent); }
From source file:org.dspace.content.DCDateTest.java
/** * Test of getCurrent method, of class DCDate. *//*from w w w.j ava2 s. c o m*/ @Test public void testGetCurrent() { assertTrue("testGetCurrent 0", DateUtils.isSameDay(DCDate.getCurrent().toDate(), new Date())); }
From source file:org.dspace.content.ItemTest.java
/** * Test of getLastModified method, of class Item. *///from w ww . j a v a 2s . c o m @Test public void testGetLastModified() { assertThat("testGetLastModified 0", it.getLastModified(), notNullValue()); assertTrue("testGetLastModified 1", DateUtils.isSameDay(it.getLastModified(), new Date())); }
From source file:org.eclipse.smarthome.binding.astro.internal.calc.SunCalc.java
private Sun getSunInfo(Calendar calendar, double latitude, double longitude, Double altitude, boolean onlyAstro) { double lw = -longitude * DEG2RAD; double phi = latitude * DEG2RAD; double j = DateTimeUtils.midnightDateToJulianDate(calendar) + 0.5; double n = getJulianCycle(j, lw); double js = getApproxSolarTransit(0, lw, n); double m = getSolarMeanAnomaly(js); double c = getEquationOfCenter(m); double lsun = getEclipticLongitude(m, c); double d = getSunDeclination(lsun); double jtransit = getSolarTransit(js, m, lsun); double w0 = getHourAngle(H0, phi, d); double w1 = getHourAngle(H0 + SUN_DIAMETER, phi, d); double jset = getSunsetJulianDate(w0, m, lsun, lw, n); double jsetstart = getSunsetJulianDate(w1, m, lsun, lw, n); double jrise = getSunriseJulianDate(jtransit, jset); double jriseend = getSunriseJulianDate(jtransit, jsetstart); double w2 = getHourAngle(H1, phi, d); double jnau = getSunsetJulianDate(w2, m, lsun, lw, n); double jciv2 = getSunriseJulianDate(jtransit, jnau); double w3 = getHourAngle(H2, phi, d); double w4 = getHourAngle(H3, phi, d); double jastro = getSunsetJulianDate(w3, m, lsun, lw, n); double jdark = getSunsetJulianDate(w4, m, lsun, lw, n); double jnau2 = getSunriseJulianDate(jtransit, jastro); double jastro2 = getSunriseJulianDate(jtransit, jdark); Sun sun = new Sun(); sun.setAstroDawn(new Range(DateTimeUtils.toCalendar(jastro2), DateTimeUtils.toCalendar(jnau2))); sun.setAstroDusk(new Range(DateTimeUtils.toCalendar(jastro), DateTimeUtils.toCalendar(jdark))); if (onlyAstro) { return sun; }//from w w w .j av a 2 s .c om sun.setNoon(new Range(DateTimeUtils.toCalendar(jtransit), DateTimeUtils.toCalendar(jtransit + JD_ONE_MINUTE_FRACTION))); sun.setRise(new Range(DateTimeUtils.toCalendar(jrise), DateTimeUtils.toCalendar(jriseend))); sun.setSet(new Range(DateTimeUtils.toCalendar(jsetstart), DateTimeUtils.toCalendar(jset))); sun.setCivilDawn(new Range(DateTimeUtils.toCalendar(jciv2), DateTimeUtils.toCalendar(jrise))); sun.setCivilDusk(new Range(DateTimeUtils.toCalendar(jset), DateTimeUtils.toCalendar(jnau))); sun.setNauticDawn(new Range(DateTimeUtils.toCalendar(jnau2), DateTimeUtils.toCalendar(jciv2))); sun.setNauticDusk(new Range(DateTimeUtils.toCalendar(jnau), DateTimeUtils.toCalendar(jastro))); boolean isSunUpAllDay = isSunUpAllDay(calendar, latitude, longitude, altitude); // daylight Range daylightRange = new Range(); if (sun.getRise().getStart() == null && sun.getRise().getEnd() == null) { if (isSunUpAllDay) { daylightRange = new Range(DateTimeUtils.truncateToMidnight(calendar), DateTimeUtils.truncateToMidnight(addDays(calendar, 1))); } } else { daylightRange = new Range(sun.getRise().getEnd(), sun.getSet().getStart()); } sun.setDaylight(daylightRange); // morning night Sun sunYesterday = getSunInfo(addDays(calendar, -1), latitude, longitude, altitude, true); Range morningNightRange = null; if (sunYesterday.getAstroDusk().getEnd() != null && DateUtils.isSameDay(sunYesterday.getAstroDusk().getEnd(), calendar)) { morningNightRange = new Range(sunYesterday.getAstroDusk().getEnd(), sun.getAstroDawn().getStart()); } else if (isSunUpAllDay || sun.getAstroDawn().getStart() == null) { morningNightRange = new Range(); } else { morningNightRange = new Range(DateTimeUtils.truncateToMidnight(calendar), sun.getAstroDawn().getStart()); } sun.setMorningNight(morningNightRange); // evening night Range eveningNightRange = null; if (sun.getAstroDusk().getEnd() != null && DateUtils.isSameDay(sun.getAstroDusk().getEnd(), calendar)) { eveningNightRange = new Range(sun.getAstroDusk().getEnd(), DateTimeUtils.truncateToMidnight(addDays(calendar, 1))); } else { eveningNightRange = new Range(); } sun.setEveningNight(eveningNightRange); // night if (isSunUpAllDay) { sun.setNight(new Range()); } else { Sun sunTomorrow = getSunInfo(addDays(calendar, 1), latitude, longitude, altitude, true); sun.setNight(new Range(sun.getAstroDusk().getEnd(), sunTomorrow.getAstroDawn().getStart())); } // eclipse SunEclipse eclipse = sun.getEclipse(); MoonCalc mc = new MoonCalc(); double partial = mc.getEclipse(calendar, MoonCalc.ECLIPSE_TYPE_SUN, j, MoonCalc.ECLIPSE_MODE_PARTIAL); eclipse.setPartial(DateTimeUtils.toCalendar(partial)); double ring = mc.getEclipse(calendar, MoonCalc.ECLIPSE_TYPE_SUN, j, MoonCalc.ECLIPSE_MODE_RING); eclipse.setRing(DateTimeUtils.toCalendar(ring)); double total = mc.getEclipse(calendar, MoonCalc.ECLIPSE_TYPE_SUN, j, MoonCalc.ECLIPSE_MODE_TOTAL); eclipse.setTotal(DateTimeUtils.toCalendar(total)); SunZodiacCalc zodiacCalc = new SunZodiacCalc(); sun.setZodiac(zodiacCalc.getZodiac(calendar)); SeasonCalc seasonCalc = new SeasonCalc(); sun.setSeason(seasonCalc.getSeason(calendar, latitude)); // phase for (Entry<SunPhaseName, Range> rangeEntry : sun.getAllRanges().entrySet()) { SunPhaseName entryPhase = rangeEntry.getKey(); if (rangeEntry.getValue().matches(Calendar.getInstance())) { if (entryPhase == SunPhaseName.MORNING_NIGHT || entryPhase == SunPhaseName.EVENING_NIGHT) { sun.getPhase().setName(SunPhaseName.NIGHT); } else { sun.getPhase().setName(entryPhase); } } } return sun; }
From source file:org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils.java
/** * Returns true, if two calendar objects are on the same day ignoring time. *//*ww w . j a v a 2 s . co m*/ public static boolean isSameDay(Calendar cal1, Calendar cal2) { return cal1 != null && cal2 != null && DateUtils.isSameDay(cal1, cal2); }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerWebAction.java
private String handleDuration() { String[] startTimeValue = getHttpRequest().getParameterValues(PARAM_STARTTIME); String durationTimeValue = getHttpRequest().getParameterValues("durationTime")[0]; Date startDateTime;// ww w .jav a 2 s .com try { startDateTime = DateTimeConverterUtil.stringTimeToDateTime(startTimeValue[0]); } catch (ParseException e) { message = INVALID_START_TIME; return INPUT; } if (!DateTimeConverterUtil.isValidTime(durationTimeValue)) { if (!DateTimeConverterUtil.isValidJiraTime(durationTimeValue)) { message = INVALID_DURATION_TIME; return INPUT; } else { timeSpent = durationTimeValue; int seconds = DateTimeConverterUtil.jiraDurationToSeconds(durationTimeValue); Date endTime = DateUtils.addSeconds(startDateTime, seconds); if (!DateUtils.isSameDay(startDateTime, endTime)) { message = INVALID_DURATION_TIME; return INPUT; } } } else { String result = handleValidDuration(startDateTime); if (!result.equals(SUCCESS)) { return result; } } return SUCCESS; }
From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerWebAction.java
private String handleValidDuration(final Date startDateTime) { String[] durationTimeValue = getHttpRequest().getParameterValues("durationTime"); Date durationDateTime;//from w w w. ja va 2 s .c o m try { durationDateTime = DateTimeConverterUtil.stringTimeToDateTimeGMT(durationTimeValue[0]); } catch (ParseException e) { message = INVALID_DURATION_TIME; return INPUT; } long seconds = durationDateTime.getTime() / DateTimeConverterUtil.MILLISECONDS_PER_SECOND; timeSpent = DateTimeConverterUtil.secondConvertToString(seconds); // check the duration time to not exceed the present day Date endTime = DateUtils.addSeconds(startDateTime, (int) seconds); if (!DateUtils.isSameDay(startDateTime, endTime)) { message = INVALID_DURATION_TIME; return INPUT; } return SUCCESS; }
From source file:org.everit.jira.timetracker.plugin.web.JiraTimetrackerWebAction.java
private String calculateTimeSpentForDuration(final String startTime, final String durationTime) { Date startDateTime;//from ww w . ja v a2s.co m try { startDateTime = DateTimeConverterUtil.stringTimeToDateTime(startTime); } catch (IllegalArgumentException e) { message = PropertiesKey.INVALID_START_TIME; return INPUT; } if (!DateTimeConverterUtil.isValidTime(durationTime)) { if (!DateTimeConverterUtil.isValidJiraTime(durationTime)) { message = PropertiesKey.INVALID_DURATION_TIME; return INPUT; } else { timeSpent = durationTime; int seconds = DateTimeConverterUtil.jiraDurationToSeconds(durationTime); workLogEndDateTime = DateUtils.addSeconds(startDateTime, seconds); if (!DateUtils.isSameDay(startDateTime, workLogEndDateTime)) { message = PropertiesKey.INVALID_DURATION_TIME; return INPUT; } } } else { Date durationDateTime; try { durationDateTime = DateTimeConverterUtil .stringTimeToDateTimeWithFixFormat(worklogValues.getDurationTime()); } catch (ParseException e) { message = PropertiesKey.INVALID_DURATION_TIME; return INPUT; } long seconds = durationDateTime.getTime() / DateTimeConverterUtil.MILLISECONDS_PER_SECOND; timeSpent = durationFormatter.exactDuration(seconds); // check the duration time to not exceed the present day workLogEndDateTime = DateUtils.addSeconds(startDateTime, (int) seconds); if (!DateUtils.isSameDay(startDateTime, workLogEndDateTime)) { message = PropertiesKey.INVALID_DURATION_TIME; return INPUT; } return SUCCESS; } return SUCCESS; }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImplTest.java
/** * @throws ParseException /*from w w w . ja v a 2 s .c om*/ * @throws InputFormatException * */ @Test public void testAvailable104() throws InputFormatException, ParseException { // get owner with meeting durations preference of 20 minutes IScheduleOwner owner = sampleOwners[3]; SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); SortedSet<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "11:40 AM", "MW", dateFormat.parse("20100830"), dateFormat.parse("20100903"), 1); availableScheduleDao.addToSchedule(owner, blocks); AvailableSchedule stored = availableScheduleDao.retrieve(owner); SortedSet<AvailableBlock> storedBlocks = stored.getAvailableBlocks(); Assert.assertEquals(2, storedBlocks.size()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-0900"), storedBlocks.first().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-1140"), storedBlocks.first().getEndTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-0900"), storedBlocks.last().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-1140"), storedBlocks.last().getEndTime()); SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(storedBlocks, 20); Assert.assertEquals(16, expanded.size()); Date originalStart = CommonDateOperations.getDateTimeFormat().parse("20100830-0900"); Date currentStart = originalStart; for (AvailableBlock e : expanded) { if (!DateUtils.isSameDay(e.getStartTime(), currentStart)) { currentStart = DateUtils.addDays(originalStart, 2); } Assert.assertEquals(currentStart, e.getStartTime()); currentStart = DateUtils.addMinutes(currentStart, 20); Assert.assertEquals(currentStart, e.getEndTime()); } }
From source file:org.jasig.schedassist.model.AvailableBlockBuilderTest.java
/** * @throws ParseException //w w w . j a va 2s .c om * @throws InputFormatException * */ @Test public void testTwentyMinuteDuration() throws InputFormatException, ParseException { SimpleDateFormat dateFormat = CommonDateOperations.getDateFormat(); SortedSet<AvailableBlock> blocks = AvailableBlockBuilder.createBlocks("9:00 AM", "11:40 AM", "MW", dateFormat.parse("20100830"), dateFormat.parse("20100903")); Assert.assertEquals(2, blocks.size()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-0900"), blocks.first().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100830-1140"), blocks.first().getEndTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-0900"), blocks.last().getStartTime()); Assert.assertEquals(CommonDateOperations.getDateTimeFormat().parse("20100901-1140"), blocks.last().getEndTime()); SortedSet<AvailableBlock> expanded = AvailableBlockBuilder.expand(blocks, 20); Assert.assertEquals(16, expanded.size()); Date originalStart = CommonDateOperations.getDateTimeFormat().parse("20100830-0900"); Date currentStart = originalStart; for (AvailableBlock e : expanded) { if (!DateUtils.isSameDay(e.getStartTime(), currentStart)) { currentStart = DateUtils.addDays(originalStart, 2); } Assert.assertEquals(currentStart, e.getStartTime()); currentStart = DateUtils.addMinutes(currentStart, 20); Assert.assertEquals(currentStart, e.getEndTime()); } }