List of usage examples for org.joda.time DateMidnight DateMidnight
public DateMidnight(Object instant)
From source file:org.openmrs.module.htmlformentryui.fragment.controller.htmlform.EnterHtmlFormFragmentController.java
License:Open Source License
private void keepTimeComponentOfEncounterIfDateComponentHasNotChanged(Date previousEncounterDate, Encounter formEncounter) {//from ww w .j a v a 2s . c o m if (previousEncounterDate != null && new DateMidnight(previousEncounterDate) .equals(new DateMidnight(formEncounter.getEncounterDatetime()))) { formEncounter.setEncounterDatetime(previousEncounterDate); } }
From source file:org.openvpms.archetype.rules.workflow.AppointmentRules.java
License:Open Source License
/** * Returns the number of days to charge boarding for. * * @param startTime the boarding start time * @param endTime the boarding end time * @return the number of days/*from w w w . j av a 2s. c o m*/ */ public int getBoardingDays(Date startTime, Date endTime) { DateMidnight end = new DateMidnight(endTime); int days = Days.daysBetween(new DateMidnight(startTime), end).getDays(); if (days < 0) { days = 0; } else if (DateRules.compareTo(endTime, end.toDate()) != 0) { // any time after midnight is another day days++; } return days; }
From source file:org.projectforge.web.calendar.HolidayEventsProvider.java
License:Open Source License
/** * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime) *//*from w w w . ja va 2 s .co m*/ @Override protected void buildEvents(final DateTime start, final DateTime end) { DateMidnight day = new DateMidnight(start); int idCounter = 0; int paranoiaCounter = 0; do { if (++paranoiaCounter > 1000) { log.error( "Paranoia counter exceeded! Dear developer, please have a look at the implementation of buildEvents."); break; } final DayHolder dh = new DayHolder(day.toDate()); String backgroundColor, color, textColor; if (dh.isHoliday() == true) { if (dh.isWorkingDay() == true) { backgroundColor = "#FFF0F0"; color = "#EEEEEE"; textColor = "#222222"; } else { backgroundColor = "#f9dfde"; color = "#EEEEEE"; textColor = "#FF2222"; } } else { day = day.plusDays(1); continue; } final Event event = new Event().setAllDay(true); final String id = "h-" + (++idCounter); event.setId(id); event.setStart(day.toDateTime()); String title; final String holidayInfo = dh.getHolidayInfo(); if (holidayInfo != null && holidayInfo.startsWith("calendar.holiday.") == true) { title = getString(holidayInfo); } else { title = holidayInfo; } event.setTitle(title); event.setBackgroundColor(backgroundColor); event.setColor(color); event.setTextColor(textColor); events.put(id, event); day = day.plusDays(1); } while (day.isAfter(end) == false); }
From source file:org.projectforge.web.wicket.converter.JodaDateConverter.java
License:Open Source License
public JodaDateConverter() { this.userDateFormat = getPattern(); this.timeZone = PFUserContext.getDateTimeZone(); this.currentYear = new DateMidnight(timeZone).getYear(); }
From source file:org.sonatype.nexus.timeline.internal.DefaultTimeline.java
License:Open Source License
/** * Purges old clusters based on {@code days} ("older than days") parameters. If input is {@code 0}, all clusters will * be removed, meaning all the timeline is purged. As Orient DDL is not atomic, this method must be mutually * exclusive/*from ww w . j a v a2 s . co m*/ * with {@link #maybeAddNewCluster(ODatabaseDocumentTx, long)}, hence both are synchronized. */ @Override public synchronized void purgeOlderThan(final int days) { if (!isStarted()) { return; } try (ODatabaseDocumentTx db = openDb()) { final DateMidnight nowDm = new DateMidnight(DateTimeZone.UTC); final int prefixLen = DB_CLUSTER_PREFIX.length(); final int[] cids = db.getMetadata().getSchema().getClass(DB_CLASS).getClusterIds(); for (int cid : cids) { final String name = db.getClusterNameById(cid); log.debug("Cluster: {} {}", cid, name); if (name.startsWith(DB_CLUSTER_PREFIX)) { final int year = Integer.parseInt(name.substring(prefixLen, prefixLen + 4)); final int month = Integer.parseInt(name.substring(prefixLen + 4, prefixLen + 6)); final int day = Integer.parseInt(name.substring(prefixLen + 6, prefixLen + 8)); final DateMidnight clusterDm = new DateMidnight(year, month, day, DateTimeZone.UTC); if (Days.daysBetween(clusterDm, nowDm).getDays() >= days) { log.info("Cluster {}, is {} days old, purging it", name, Days.daysBetween(clusterDm, nowDm).getDays()); OSchema schema = db.getMetadata().getSchema(); OClass type = schema.getClass(DB_CLASS); type.removeClusterId(cid); db.dropCluster(cid, true); } } } } }
From source file:org.wicketstuff.calendarviews.exampleapp.RandomTestEventProvider.java
License:Apache License
private IEvent createRandomEvent(Date current, int id) { // TODO: add support for events that last from a certain time today to a certain time // tomorrow/*from ww w.ja v a 2 s . com*/ boolean multiDay = mRandom.nextInt(4) == 1; Date start = new DateMidnight(current).toDate(); if (multiDay) { // a multi-day event (always all-day) Date end = new DateTime(start).plusDays(mRandom.nextInt(9)).toDate(); return createEvent(id, true, start, end); } boolean allDay = mRandom.nextInt(3) == 1; if (allDay) { // an all day, single-day event return createEvent(id, true, start, null); } // this is a partial day event int startHour = mRandom.nextInt(13); int startMinutes = (mRandom.nextInt(4) * 15); int durationHours = mRandom.nextInt(5); int durationMinutes = (mRandom.nextInt(4) * 15); start = new DateTime(new DateMidnight(current)).plusHours(startHour).plusMinutes(startMinutes).toDate(); Date end = new DateTime(start).plusHours(durationHours).plusMinutes(durationMinutes).toDate(); return createEvent(id, false, start, end); }
From source file:org.wicketstuff.calendarviews.logic.DateMidnightIterator.java
License:Apache License
public DateMidnight next() { DateMidnight dm = new DateMidnight(mCurrent); mCurrent = mCurrent.plusDays(1); return dm; }
From source file:se.streamsource.streamflow.client.ui.workspace.table.PerspectivePeriodModel.java
License:Apache License
private String getSearchPeriod(Date fromDate, int direction, String periodName, String datePattern, String separator) {/*from w w w . ja v a 2 s .co m*/ DateMidnight from = new DateMidnight(fromDate); DateMidnight to = null; DateTimeFormatter format = DateTimeFormat.forPattern(datePattern); switch (Period.valueOf(periodName)) { case one_day: return format.print(from); case three_days: to = (direction == 1) ? from.plusDays(2) : from.minusDays(2); break; case one_week: to = (direction == 1) ? from.plusWeeks(1).minusDays(1) : from.minusWeeks(1).plusDays(1); break; case two_weeks: to = (direction == 1) ? from.plusWeeks(2).minusDays(1) : from.minusWeeks(2).plusDays(1); break; case one_month: to = (direction == 1) ? from.plusMonths(1).minusDays(1) : from.minusMonths(1).plusDays(1); break; case six_months: to = (direction == 1) ? from.plusMonths(6).minusDays(1) : from.minusMonths(6).plusDays(1); break; case one_year: to = (direction == 1) ? from.plusYears(1).minusDays(1) : from.minusYears(1).plusDays(1); break; } return (direction == 1) ? format.print(from) + separator + format.print(to) : format.print(to) + separator + format.print(from); }
From source file:za.co.bayport.rules.PolicyRules.java
/** * Checks Applicant's Age Limit<br/> * <br/>/*from w w w .j ava 2 s . c om*/ * * @param minVal * : Applicant's Minimum Age * @param maxVal * : Applicant's Maximum Age * @param val * : Applicant's age * @throws ServiceException * : Would throw ServiceException containing <errorCode>, <fieldName> and <fieldValue> if: <li> * <minVal> is zero or null</li><li><maxVal> is zero or null</li> <li><val> is zero or null</li> <li>if <val> is less * than <minVal> or greater than <maxVal><br/> * <br/> * <b>Suggestion:</b> Applicant must be 18 years of age or older but not older than 63 years of age. Unless: The employer can provide * confirmation in writing that the applicant will be employed after reaching 63 to a maximum of 65 years of age */ public static ServiceException checkAgeLimit(Integer minVal, Integer maxVal, Date dob) { ServiceException ServiceException = checkIsNullOrZero("RUL002", "AGE", "Minimum Age: Is Null Or Zero", minVal); if (ServiceException == null) ServiceException = checkIsNullOrZero("RUL002", "AGE", "Maximum Age: Is Null Or Zero", maxVal); if (ServiceException == null) ServiceException = checkIsNullOrEmpty("RUL001", "AGE", "Date of Birth Is Null or Empty", dob); if (ServiceException == null) { DateMidnight birthdate = new DateMidnight(dob); DateTime now = new DateTime(); Years age = Years.yearsBetween(birthdate, now); int val = age.getYears(); if (val < minVal || val > maxVal) ServiceException = new ServiceException("POL002", "AGE", "Applicant must be 18 years of age or older but not older than 63 years of age. Unless: The employer can provide confirmation in writing that the applicant will be employed after reaching 63 to a maximum of 65 years of age"); } return ServiceException; }