List of usage examples for org.joda.time Period getDays
public int getDays()
From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java
License:Open Source License
/** * This function calculates the range for the timeseries to be generated. The range equals the range defined in the * simulation adjusted as follows:// w w w. java 2 s. com * <ul> * <li>1 timestep earlier</li> * <li>3 timesteps later</li> * </ul> * * @param control * The na control. * @param timestep * The timestep. * @param timestamp * The timestamp in UTC. * @return The date range. */ public static DateRange getRange(final NAControl control, final Period timestep, final LocalTime timestamp) { final Date simulationStart = control.getSimulationStart(); final Date simulationEnd = control.getSimulationEnd(); final DateTime start = new DateTime(simulationStart); final DateTime end = new DateTime(simulationEnd); final DateTime adjustedStart = start.minus(timestep); final DateTime adjustedEnd = end.plus(timestep).plus(timestep).plus(timestep); if (timestep.getDays() == 0 || timestamp == null) return new DateRange(adjustedStart.toDate(), adjustedEnd.toDate()); /* Convert to a date with the kalypso timezone. */ /* The date fields are ignored. */ final DateTime timestampUTC = timestamp .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$ final DateTime timestampDate = new DateTime(timestampUTC.toDate(), DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone())); /* Further adjust range by predefined time. */ final DateTime startWithTime = adjustedStart.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); final DateTime endWithTime = adjustedEnd.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); /* New start must always be before unadjusted start, fix, if this is not the case. */ DateTime startWithTimeFixed; if (startWithTime.isAfter(adjustedStart)) startWithTimeFixed = startWithTime.minus(timestep); else startWithTimeFixed = startWithTime; /* New end must always be after unadjusted end, fix, if this is not the case. */ DateTime endWithTimeFixed; if (endWithTime.isBefore(adjustedEnd)) endWithTimeFixed = endWithTime.plus(timestep); else endWithTimeFixed = endWithTime; return new DateRange(startWithTimeFixed.toDate(), endWithTimeFixed.toDate()); }
From source file:org.killbill.billing.jaxrs.json.OverdueStateJson.java
License:Apache License
public OverdueStateJson(final OverdueState overdueState, final PaymentConfig paymentConfig) { this.name = overdueState.getName(); this.externalMessage = overdueState.getExternalMessage(); this.daysBetweenPaymentRetries = paymentConfig.getPaymentFailureRetryDays(); this.disableEntitlementAndChangesBlocked = overdueState.isDisableEntitlementAndChangesBlocked(); this.blockChanges = overdueState.isBlockChanges(); this.isClearState = overdueState.isClearState(); Period reevaluationIntervalPeriod = null; try {//from w ww. j a v a 2 s . c om reevaluationIntervalPeriod = overdueState.getAutoReevaluationInterval(); } catch (final OverdueApiException ignored) { } if (reevaluationIntervalPeriod != null) { this.reevaluationIntervalDays = reevaluationIntervalPeriod.getDays(); } else { this.reevaluationIntervalDays = null; } }
From source file:org.kuali.kpme.tklm.time.batch.ClockedInEmployeeJob.java
License:Educational Community License
public void execute(JobExecutionContext context) throws JobExecutionException { //Get Configuration Settings BigDecimal hourLimit = getHourLimit(); String jobAction = getJobAction(); String batchJobPrincipalId = BatchJobUtil.getBatchUserPrincipalId(); // code to send one email per approver // Map<String, Map<String, String>> notificationMap = new HashMap<String, Map<String, String>>(); DateTime asOfDate = new LocalDate().toDateTimeAtStartOfDay(); List<CalendarEntry> calendarEntries = HrServiceLocator.getCalendarEntryService() .getCurrentCalendarEntriesNeedsScheduled(30, asOfDate); for (CalendarEntry calendarEntry : calendarEntries) { Calendar calendar = HrServiceLocator.getCalendarService().getCalendar(calendarEntry.getHrCalendarId()); if (StringUtils.equals(calendar.getCalendarTypes(), "Pay")) { DateTime beginDate = calendarEntry.getBeginPeriodFullDateTime(); DateTime endDate = calendarEntry.getEndPeriodFullDateTime(); List<TimesheetDocumentHeader> timesheetDocumentHeaders = TkServiceLocator .getTimesheetDocumentHeaderService().getDocumentHeaders(beginDate, endDate); for (TimesheetDocumentHeader timesheetDocumentHeader : timesheetDocumentHeaders) { String principalId = timesheetDocumentHeader.getPrincipalId(); List<Assignment> assignments = HrServiceLocator.getAssignmentService() .getAllAssignmentsByCalEntryForTimeCalendar(principalId, calendarEntry); for (Assignment assignment : assignments) { String groupKeyCode = assignment.getGroupKeyCode(); String jobNumber = String.valueOf(assignment.getJobNumber()); String workArea = String.valueOf(assignment.getWorkArea()); String task = String.valueOf(assignment.getTask()); ClockLog lastClockLog = TkServiceLocator.getClockLogService().getLastClockLog(groupKeyCode, principalId, jobNumber, workArea, task, calendarEntry); if (lastClockLog != null && TkConstants.ON_THE_CLOCK_CODES.contains(lastClockLog.getClockAction())) { DateTime lastClockLogDateTime = lastClockLog.getClockDateTime(); DateTime currentDate = new DateTime(); Period p = new Period(lastClockLogDateTime, currentDate); BigDecimal hoursBetween = new BigDecimal(p.getHours()); BigDecimal dayHours = new BigDecimal(p.getDays() * 24); hoursBetween = hoursBetween.add(dayHours); if (hoursBetween.compareTo(hourLimit) > 0) { if (jobAction.equals("NOTIFY")) { //code to send one notification per employee to all approvers of employee for (Person approver : getApprovers(assignment.getWorkArea())) { EntityNamePrincipalName employee = KimApiServiceLocator.getIdentityService() .getDefaultNamesForPrincipalId(principalId); String approverSubject = "Employee Clocked In Over " + hourLimit.toString() + " Hours Notification"; StringBuilder approverNotification = new StringBuilder(); approverNotification.append(employee.getPrincipalName() + " (" + principalId + ") has been clocked in since "); SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM d yyyy HH:mm a"); String dateTime = sdf.format( new java.sql.Date(lastClockLog.getClockDateTime().getMillis())); approverNotification.append(dateTime); approverNotification.append( " for work area " + assignment.getWorkAreaObj().getDescription()); HrServiceLocator.getKPMENotificationService().sendNotification( approverSubject, approverNotification.toString(), approver.getPrincipalId()); }//from w w w .j a va2 s . co m /* Code to send one email per approver - Create notification Map<String, String> hourInfo = new HashMap<String, String>(); hourInfo.put(principalId, hoursBetween.toString()); for (Person person : getApprovers(lastClockLog.getWorkArea())) { if (notificationMap.containsKey(person.getPrincipalId())) { notificationMap.get(person.getPrincipalId()).put(principalId, hoursBetween.toString()); } else { notificationMap.put(person.getPrincipalId(), hourInfo); } } */ } else if (jobAction.equals("CLOCK_OUT")) { //Clock User Out ClockLog clockOut = TkServiceLocator.getClockLogService().processClockLog( principalId, timesheetDocumentHeader.getDocumentId(), currentDate, assignment, calendarEntry, TKUtils.getIPNumber(), currentDate.toLocalDate(), "CO", true, batchJobPrincipalId); TkServiceLocator.getClockLogService().saveClockLog(clockOut); // Notify User String employeeSubject = "You have been clocked out of " + assignment.getAssignmentDescription(); StringBuilder employeeNotification = new StringBuilder(); employeeNotification.append( "You have been Clocked out of " + assignment.getAssignmentDescription() + " on " + clockOut.getClockDateTime()); HrServiceLocator.getKPMENotificationService().sendNotification(employeeSubject, employeeNotification.toString(), principalId); //add Note to time sheet Note.Builder builder = Note.Builder .create(timesheetDocumentHeader.getDocumentId(), batchJobPrincipalId); builder.setCreateDate(new DateTime()); builder.setText("Clock out from " + assignment.getAssignmentDescription() + " on " + clockOut.getClockDateTime() + " was initiated by the Clocked In Employee Batch Job"); KewApiServiceLocator.getNoteService().createNote(builder.build()); } } } } } } } /* code to send one email per approver for (Map.Entry<String, Map<String, String>> approverEntry : notificationMap.entrySet()) { String subject = "Users clocked in over " + hourLimit.toString() + " hours"; StringBuilder notification = new StringBuilder(); notification.append("The following users have been clocked in for over " + hourLimit.toString() + " hours:"); notification.append(SystemUtils.LINE_SEPARATOR); for (Map.Entry<String, String> employeeEntry : approverEntry.getValue().entrySet()) { notification.append(KimApiServiceLocator.getPersonService().getPerson(employeeEntry.getKey()).getPrincipalName()); notification.append(" (" + employeeEntry.getKey() + ") : " + employeeEntry.getValue() + " hours"); notification.append(SystemUtils.LINE_SEPARATOR); } HrServiceLocator.getKPMENotificationService().sendNotification(subject, notification.toString(), approverEntry.getKey()); } */ }
From source file:org.libreplan.importers.MPXJProjectFileConversor.java
License:Open Source License
/** * Private Method//from w w w. j ava2 s . co m * * Get {@link CalendarExceptionDTO} from a ProjectCalendarException * * @param projectCalendar * ProjectCalendarException to extract data from. * @return List<CalendarExceptionDTO> with the calendar exceptions that we want to import. */ private static List<CalendarExceptionDTO> toCalendarExceptionDTOs( ProjectCalendarException projectCalendarException) { List<CalendarExceptionDTO> calendarExceptionDTOs = new ArrayList<CalendarExceptionDTO>(); Date fromDate = projectCalendarException.getFromDate(); Date toDate = projectCalendarException.getToDate(); Period period = new Period(new DateTime(fromDate), new DateTime(toDate)); boolean working = projectCalendarException.getWorking(); int day = period.getDays(); Calendar cal = Calendar.getInstance(); cal.setTime(fromDate); List<Integer> duration = toHours(projectCalendarException); int hours; int minutes; if (duration != null) { hours = duration.get(0); minutes = duration.get(1); } else { if (working) { hours = 8; } else { hours = 0; } minutes = 0; } while (day > -1) { if (day == 0) { calendarExceptionDTOs.add(toCalendarExceptionDTO(cal.getTime(), hours, minutes, working)); } else { calendarExceptionDTOs.add(toCalendarExceptionDTO(cal.getTime(), hours, minutes, working)); cal.add(Calendar.DAY_OF_MONTH, +1); } day--; } return calendarExceptionDTOs; }
From source file:org.libreplan.importers.MPXJProjectFileConversor.java
License:Open Source License
/** * Private Method/*from w w w .j a v a 2 s . co m*/ * * Get the number of hours of a ProjectCalendarHours * * @param projectCalendarDateRanges * ProjectCalendarDateRanges to extract data from. * @return Integer with the total number of hours or null if the projectCalendarHours is null. */ private static List<Integer> toHours(ProjectCalendarDateRanges projectCalendarDateRanges) { if (projectCalendarDateRanges != null) { List<Integer> duration = new ArrayList<Integer>(); int hours = 0; int minutes = 0; for (DateRange dateRange : projectCalendarDateRanges) { DateTime start = new DateTime(dateRange.getStart()); DateTime end = new DateTime(dateRange.getEnd()); Period period = new Period(start, end); int days = period.getDays(); if (period.getDays() != 0) { hours += 24 * days; } hours += period.getHours(); minutes += period.getMinutes(); } duration.add(hours); duration.add(minutes); return duration; } else { return null; } }
From source file:org.libreplan.importers.MPXJProjectFileConverter.java
License:Open Source License
/** * Get {@link CalendarExceptionDTO} from a ProjectCalendarException. * * @param projectCalendarException/* w ww . j a va 2s. c om*/ * ProjectCalendarException to extract data from. * @return List<CalendarExceptionDTO> with the calendar exceptions that we want to import. */ private static List<CalendarExceptionDTO> toCalendarExceptionDTOs( ProjectCalendarException projectCalendarException) { List<CalendarExceptionDTO> calendarExceptionDTOs = new ArrayList<>(); Date fromDate = projectCalendarException.getFromDate(); Date toDate = projectCalendarException.getToDate(); Period period = new Period(new DateTime(fromDate), new DateTime(toDate)); boolean working = projectCalendarException.getWorking(); int day = period.getDays(); Calendar cal = Calendar.getInstance(); cal.setTime(fromDate); List<Integer> duration = toHours(projectCalendarException); int hours; int minutes; if (duration != null) { hours = duration.get(0); minutes = duration.get(1); } else { if (working) { hours = 8; } else { hours = 0; } minutes = 0; } while (day > -1) { if (day == 0) { calendarExceptionDTOs.add(toCalendarExceptionDTO(cal.getTime(), hours, minutes, working)); } else { calendarExceptionDTOs.add(toCalendarExceptionDTO(cal.getTime(), hours, minutes, working)); cal.add(Calendar.DAY_OF_MONTH, +1); } day--; } return calendarExceptionDTOs; }
From source file:org.libreplan.importers.MPXJProjectFileConverter.java
License:Open Source License
/** * Get the number of hours of a ProjectCalendarHours. * * @param projectCalendarDateRanges//from w w w . ja va 2 s. c o m * ProjectCalendarDateRanges to extract data from. * @return Integer with the total number of hours or null if the projectCalendarHours is null. */ private static List<Integer> toHours(ProjectCalendarDateRanges projectCalendarDateRanges) { if (projectCalendarDateRanges != null) { List<Integer> duration = new ArrayList<>(); int hours = 0; int minutes = 0; for (DateRange dateRange : projectCalendarDateRanges) { DateTime start = new DateTime(dateRange.getStart()); DateTime end = new DateTime(dateRange.getEnd()); Period period = new Period(start, end); int days = period.getDays(); if (period.getDays() != 0) { hours += 24 * days; } hours += period.getHours(); minutes += period.getMinutes(); } duration.add(hours); duration.add(minutes); return duration; } else { return null; } }
From source file:org.openmrs.module.chaiui.ChaiUiUtils.java
License:Open Source License
/** * Formats a person's age// ww w. j a v a2 s. c o m * @param person the person * @return the string value */ public String formatPersonAge(Person person) { String prefix = BooleanUtils.isTrue(person.isBirthdateEstimated()) ? "~" : ""; int ageYears = person.getAge(); if (ageYears < 1) { Period p = new Period(person.getBirthdate().getTime(), System.currentTimeMillis(), PeriodType.yearMonthDay()); return prefix + p.getMonths() + " month(s), " + p.getDays() + " day(s)"; } else { return prefix + ageYears + " year(s)"; } }
From source file:org.oscarehr.util.AgeCalculator.java
License:Open Source License
public static Age calculateAge(Calendar birthDate) { LocalDate birthdate = LocalDate.fromCalendarFields(birthDate); LocalDate now = new LocalDate(); //Today's date Period period = new Period(birthdate, now, PeriodType.yearMonthDay()); return new Age(period.getDays(), period.getMonths(), period.getYears()); }
From source file:org.projectforge.plugins.teamcal.event.TeamCalEventProvider.java
License:Open Source License
/** * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime) *//*from ww w .j a va2 s .c o m*/ @Override protected void buildEvents(final DateTime start, final DateTime end) { final TemplateEntry activeTemplateEntry = filter.getActiveTemplateEntry(); if (activeTemplateEntry == null) { // Nothing to build. return; } final Set<Integer> visibleCalendars = activeTemplateEntry.getVisibleCalendarIds(); if (CollectionUtils.isEmpty(visibleCalendars) == true) { // Nothing to build. return; } final TeamEventFilter eventFilter = new TeamEventFilter(); eventFilter.setTeamCals(visibleCalendars); eventFilter.setStartDate(start.toDate()); eventFilter.setEndDate(end.toDate()); eventFilter.setUser(PFUserContext.getUser()); final List<TeamEvent> teamEvents = teamEventDao.getEventList(eventFilter); boolean longFormat = false; days = Days.daysBetween(start, end).getDays(); if (days < 10) { // Week or day view: longFormat = true; } final TeamCalRight right = new TeamCalRight(); final PFUserDO user = PFUserContext.getUser(); final TimeZone timeZone = PFUserContext.getTimeZone(); if (CollectionUtils.isNotEmpty(teamEvents) == true) { for (final TeamEvent teamEvent : teamEvents) { final DateTime startDate = new DateTime(teamEvent.getStartDate(), PFUserContext.getDateTimeZone()); final DateTime endDate = new DateTime(teamEvent.getEndDate(), PFUserContext.getDateTimeZone()); final TeamEventDO eventDO; final TeamCalEventId id = new TeamCalEventId(teamEvent, timeZone); if (teamEvent instanceof TeamEventDO) { eventDO = (TeamEventDO) teamEvent; } else { eventDO = ((TeamRecurrenceEvent) teamEvent).getMaster(); } teamEventMap.put(id.toString(), teamEvent); final MyEvent event = new MyEvent(); event.setClassName( EVENT_CLASS_NAME + " " + EventDroppedCallbackScriptGenerator.NO_CONTEXTMENU_INDICATOR); event.setId("" + id); event.setColor(activeTemplateEntry.getColorCode(eventDO.getCalendarId())); if (eventRight.hasUpdateAccess(PFUserContext.getUser(), eventDO, null)) { event.setEditable(true); } else { event.setEditable(false); } if (teamEvent.isAllDay() == true) { event.setAllDay(true); } event.setStart(startDate); event.setEnd(endDate); event.setTooltip(eventDO.getCalendar().getTitle(), new String[][] { { eventDO.getSubject() }, { eventDO.getLocation(), getString("timesheet.location") }, { eventDO.getNote(), getString("plugins.teamcal.event.note") } }); final String title; String durationString = ""; if (longFormat == true) { // String day = duration.getDays() + ""; final Period period = new Period(startDate, endDate); int hourInt = period.getHours(); if (period.getDays() > 0) { hourInt += period.getDays() * 24; } final String hour = hourInt < 10 ? "0" + hourInt : "" + hourInt; final int minuteInt = period.getMinutes(); final String minute = minuteInt < 10 ? "0" + minuteInt : "" + minuteInt; if (event.isAllDay() == false) { durationString = "\n" + getString("plugins.teamcal.event.duration") + ": " + hour + ":" + minute; } final StringBuffer buf = new StringBuffer(); buf.append(teamEvent.getSubject()); if (StringUtils.isNotBlank(teamEvent.getNote()) == true) { buf.append("\n").append(getString("plugins.teamcal.event.note")).append(": ") .append(teamEvent.getNote()); } buf.append(durationString); title = buf.toString(); } else { title = teamEvent.getSubject(); } if (right.hasMinimalAccess(eventDO.getCalendar(), user.getId()) == true) { // for minimal access event.setTitle(""); event.setEditable(false); } else { event.setTitle(title); } events.put(id + "", event); } } }