List of usage examples for org.joda.time DateTime plusDays
public DateTime plusDays(int days)
From source file:org.kuali.kpme.tklm.time.timeblock.service.TimeBlockServiceImpl.java
License:Educational Community License
public List<TimeBlock> buildTimeBlocksSpanDates(Assignment assignment, String earnCode, TimesheetDocument timesheetDocument, DateTime beginDateTime, DateTime endDateTime, BigDecimal hours, BigDecimal amount, Boolean getClockLogCreated, Boolean getLunchDeleted, String spanningWeeks, String userPrincipalId) { DateTimeZone zone = HrServiceLocator.getTimezoneService().getUserTimezoneWithFallback(); DateTime beginDt = beginDateTime.withZone(zone); DateTime endDt = beginDt.toLocalDate().toDateTime(endDateTime.withZone(zone).toLocalTime(), zone); if (endDt.isBefore(beginDt)) endDt = endDt.plusDays(1); List<Interval> dayInt = TKUtils.getDaySpanForCalendarEntry(timesheetDocument.getCalendarEntry()); TimeBlock firstTimeBlock = new TimeBlock(); List<TimeBlock> lstTimeBlocks = new ArrayList<TimeBlock>(); DateTime endOfFirstDay = null; // KPME-2568 long diffInMillis = 0; // KPME-2568 for (Interval dayIn : dayInt) { if (dayIn.contains(beginDt)) { if (dayIn.contains(endDt) || dayIn.getEnd().equals(endDt)) { // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list if (StringUtils.isEmpty(spanningWeeks) && (dayIn.getStart().getDayOfWeek() == DateTimeConstants.SATURDAY || dayIn.getStart().getDayOfWeek() == DateTimeConstants.SUNDAY)) { // Get difference in millis for the next time block - KPME-2568 endOfFirstDay = endDt.withZone(zone); diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis(); } else { firstTimeBlock = createTimeBlock(timesheetDocument, beginDateTime, endDt, assignment, earnCode, hours, amount, false, getLunchDeleted, userPrincipalId); lstTimeBlocks.add(firstTimeBlock); }//from ww w .j a va 2 s.com } else { //TODO move this to prerule validation //throw validation error if this case met error } } } DateTime endTime = endDateTime.withZone(zone); if (firstTimeBlock.getEndDateTime() != null) { // KPME-2568 endOfFirstDay = firstTimeBlock.getEndDateTime().withZone(zone); diffInMillis = endOfFirstDay.minus(beginDt.getMillis()).getMillis(); } DateTime currTime = beginDt.plusDays(1); while (currTime.isBefore(endTime) || currTime.isEqual(endTime)) { // KPME-1446 if "Include weekends" check box is checked, don't add Sat and Sun to the timeblock list if (StringUtils.isEmpty(spanningWeeks) && (currTime.getDayOfWeek() == DateTimeConstants.SATURDAY || currTime.getDayOfWeek() == DateTimeConstants.SUNDAY)) { // do nothing } else { TimeBlock tb = createTimeBlock(timesheetDocument, currTime, currTime.plus(diffInMillis), assignment, earnCode, hours, amount, false, getLunchDeleted, userPrincipalId); lstTimeBlocks.add(tb); } currTime = currTime.plusDays(1); } return lstTimeBlocks; }
From source file:org.kuali.kpme.tklm.time.timesummary.service.TimeSummaryServiceImpl.java
License:Educational Community License
/** * Generate a list of string describing this pay calendar entry for the summary * @param payCalEntry/*from w w w. java 2s . co m*/ * @return */ protected List<String> getSummaryHeader(CalendarEntry payCalEntry) { List<String> summaryHeader = new ArrayList<String>(); int dayCount = 0; DateTime beginDateTime = payCalEntry.getBeginPeriodFullDateTime(); DateTime endDateTime = payCalEntry.getEndPeriodFullDateTime(); boolean virtualDays = false; LocalDateTime endDate = payCalEntry.getEndPeriodLocalDateTime(); if (endDate.get(DateTimeFieldType.hourOfDay()) != 0 || endDate.get(DateTimeFieldType.minuteOfHour()) != 0 || endDate.get(DateTimeFieldType.secondOfMinute()) != 0) { virtualDays = true; } DateTime currentDateTime = beginDateTime; while (currentDateTime.isBefore(endDateTime)) { LocalDateTime currDate = currentDateTime.toLocalDateTime(); summaryHeader.add(makeHeaderDiplayString(currDate, virtualDays)); dayCount++; if ((dayCount % 7) == 0) { summaryHeader.add("Week " + ((dayCount / 7))); } currentDateTime = currentDateTime.plusDays(1); } summaryHeader.add("Period Total"); return summaryHeader; }
From source file:org.kuali.kpme.tklm.utils.TkTestUtils.java
License:Educational Community License
public static List<TimeBlock> createUniformTimeBlocks(DateTime start, int days, BigDecimal hours, String earnCode, Long jobNumber, Long workArea, Long task) { List<TimeBlock> blocks = new ArrayList<TimeBlock>(); for (int i = 0; i < days; i++) { DateTime ci = start.plusDays(i); DateTime co = ci.plusHours(hours.intValue()); TimeBlock block = TkTestUtils.createDummyTimeBlock(ci, co, hours, earnCode, jobNumber, workArea); block.setTask(task);//www. j a va2s. co m blocks.add(block); } return blocks; }
From source file:org.kuali.kpme.tklm.utils.TkTestUtils.java
License:Educational Community License
public static TimeBlock createTimeBlock(TimesheetDocument timesheetDocument, int dayInPeriod, int numHours, String earnCode) {//from w w w.j ava 2 s . c o m TimeBlock timeBlock = new TimeBlock(); DateTime beginPeriodDateTime = timesheetDocument.getCalendarEntry().getBeginPeriodFullDateTime(); DateTime beginDateTime = beginPeriodDateTime.plusDays(dayInPeriod).withHourOfDay(8).withMinuteOfHour(0); DateTime endDateTime = beginDateTime.plusHours(numHours); timeBlock.setDocumentId(timesheetDocument.getDocumentId()); timeBlock.setBeginDateTime(beginDateTime); timeBlock.setBeginTimeDisplay(beginDateTime); timeBlock.setEndDateTime(endDateTime); timeBlock.setEndTimeDisplay(endDateTime); timeBlock.setEarnCode(earnCode); timeBlock.setJobNumber(1L); timeBlock.setWorkArea(1234L); timeBlock.setTask(1L); timeBlock.setHours((new BigDecimal(numHours)).setScale(HrConstants.BIG_DECIMAL_SCALE, HrConstants.BIG_DECIMAL_SCALE_ROUNDING)); return timeBlock; }
From source file:org.kuali.kpme.tklm.utils.TkTestUtils.java
License:Educational Community License
/** * Helper method to generate time blocks suitable for db persistence in * unit tests./*from ww w. j a v a 2 s .co m*/ */ public static List<TimeBlock> createUniformActualTimeBlocks(TimesheetDocument timesheetDocument, Assignment assignment, String earnCode, DateTime start, int days, BigDecimal hours, BigDecimal amount, String principalId) { TimeBlockService service = TkServiceLocator.getTimeBlockService(); List<TimeBlock> blocks = new ArrayList<TimeBlock>(); for (int i = 0; i < days; i++) { DateTime ci = start.plusDays(i); DateTime co = ci.plusHours(hours.intValue()); blocks.addAll(service.buildTimeBlocks(assignment, earnCode, timesheetDocument, ci, co, hours, amount, false, false, principalId)); } return blocks; }
From source file:org.kuali.kpme.tklm.utils.TkTestUtils.java
License:Educational Community License
public static Map<DateTime, BigDecimal> getDateToHoursMap(TimeBlock timeBlock, TimeHourDetail timeHourDetail) { Map<DateTime, BigDecimal> dateToHoursMap = new HashMap<DateTime, BigDecimal>(); DateTime beginTime = timeBlock.getBeginDateTime(); DateTime endTime = timeBlock.getEndDateTime(); Days d = Days.daysBetween(beginTime, endTime); int numberOfDays = d.getDays(); if (numberOfDays < 1) { dateToHoursMap.put(timeBlock.getBeginDateTime(), timeHourDetail.getHours()); return dateToHoursMap; }/*ww w . ja va 2 s . c om*/ DateTime currentTime = beginTime; for (int i = 0; i < numberOfDays; i++) { DateTime nextDayAtMidnight = currentTime.plusDays(1); nextDayAtMidnight = nextDayAtMidnight.hourOfDay().setCopy(12); nextDayAtMidnight = nextDayAtMidnight.minuteOfDay().setCopy(0); nextDayAtMidnight = nextDayAtMidnight.secondOfDay().setCopy(0); nextDayAtMidnight = nextDayAtMidnight.millisOfSecond().setCopy(0); Duration dur = new Duration(currentTime, nextDayAtMidnight); long duration = dur.getStandardSeconds(); BigDecimal hrs = new BigDecimal(duration / 3600, HrConstants.MATH_CONTEXT); dateToHoursMap.put(currentTime, hrs); currentTime = nextDayAtMidnight; } Duration dur = new Duration(currentTime, endTime); long duration = dur.getStandardSeconds(); BigDecimal hrs = new BigDecimal(duration / 3600, HrConstants.MATH_CONTEXT); dateToHoursMap.put(currentTime, hrs); return dateToHoursMap; }
From source file:org.mifos.accounts.business.AccountBO.java
License:Open Source License
/** * @deprecated - used to create installment dates based on 'loan meeting' and working das, holidays, moratoria etc * * better to pull capability of creating 'installments' out of loan into something more reuseable and isolated *//* w w w .j a v a2 s .c o m*/ @Deprecated public final List<InstallmentDate> getInstallmentDates(final MeetingBO meeting, final Short noOfInstallments, final Short installmentToSkip, final boolean isRepaymentIndepOfMeetingEnabled, final boolean adjustForHolidays) { logger.debug("Generating intallment dates"); List<InstallmentDate> dueInstallmentDates = new ArrayList<InstallmentDate>(); if (noOfInstallments > 0) { List<Days> workingDays = new FiscalCalendarRules().getWorkingDaysAsJodaTimeDays(); List<Holiday> holidays = new ArrayList<Holiday>(); DateTime startFromMeetingDate = new DateTime(meeting.getMeetingStartDate()); if (adjustForHolidays) { HolidayDao holidayDao = ApplicationContextProvider.getBean(HolidayDao.class); holidays = holidayDao.findAllHolidaysFromDateAndNext(getOffice().getOfficeId(), startFromMeetingDate.toLocalDate().toString()); } final int occurrences = noOfInstallments + installmentToSkip; ScheduledEvent scheduledEvent = ScheduledEventFactory.createScheduledEventFrom(meeting); ScheduledDateGeneration dateGeneration = new HolidayAndWorkingDaysAndMoratoriaScheduledDateGeneration( workingDays, holidays); List<Date> dueDates = new ArrayList<Date>(); // FIXME - keithw - this whole area of installment creation should be pulled out of domain DateTime startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate; if (this.isLoanAccount()) { // ensure loans that are created or disbursed on a meeting date start on next valid meeting date and not todays meeting // ensure loans that are created or disbursed before a meeting date start on next valid meeting date startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments = startFromMeetingDate .plusDays(1); } List<DateTime> installmentDates = dateGeneration.generateScheduledDates(occurrences, startFromDayAfterAssignedMeetingDateRatherThanSkippingInstallments, scheduledEvent, false); for (DateTime installmentDate : installmentDates) { dueDates.add(installmentDate.toDate()); } dueInstallmentDates = createInstallmentDates(installmentToSkip, dueDates); } return dueInstallmentDates; }
From source file:org.mifos.accounts.loan.struts.action.LoanAccountAction.java
License:Open Source License
private MeetingBO createNewMeetingForRepaymentDay(DateTime disbursementDate, final LoanAccountActionForm loanAccountActionForm, final CustomerBO customer) throws NumberFormatException, MeetingException { MeetingBO newMeetingForRepaymentDay = null; Short recurrenceId = Short.valueOf(loanAccountActionForm.getRecurrenceId()); final int minDaysInterval = new ConfigurationPersistence() .getConfigurationKeyValueInteger(MIN_DAYS_BETWEEN_DISBURSAL_AND_FIRST_REPAYMENT_DAY).getValue(); final Date repaymentStartDate = disbursementDate.plusDays(minDaysInterval).toDate(); if (RecurrenceType.WEEKLY.getValue().equals(recurrenceId)) { newMeetingForRepaymentDay = new MeetingBO( WeekDay.getWeekDay(Short.valueOf(loanAccountActionForm.getWeekDay())), Short.valueOf(loanAccountActionForm.getRecurWeek()), repaymentStartDate, MeetingType.LOAN_INSTALLMENT, customer.getCustomerMeeting().getMeeting().getMeetingPlace()); } else if (RecurrenceType.MONTHLY.getValue().equals(recurrenceId)) { if (loanAccountActionForm.getMonthType().equals("1")) { newMeetingForRepaymentDay = new MeetingBO(Short.valueOf(loanAccountActionForm.getMonthDay()), Short.valueOf(loanAccountActionForm.getDayRecurMonth()), repaymentStartDate, MeetingType.LOAN_INSTALLMENT, customer.getCustomerMeeting().getMeeting().getMeetingPlace()); } else {/* ww w . j a v a 2 s .co m*/ newMeetingForRepaymentDay = new MeetingBO(Short.valueOf(loanAccountActionForm.getMonthWeek()), Short.valueOf(loanAccountActionForm.getRecurMonth()), repaymentStartDate, MeetingType.LOAN_INSTALLMENT, customer.getCustomerMeeting().getMeeting().getMeetingPlace(), Short.valueOf(loanAccountActionForm.getMonthRank())); } } return newMeetingForRepaymentDay; }
From source file:org.mifos.calendar.CalendarUtils.java
License:Open Source License
public static DateTime nearestWorkingDay(DateTime day) { if (isWorkingDay(day)) { return day; }/*from w w w . ja v a2 s . c om*/ DateTime nearestWorkingDay = day; do { nearestWorkingDay = nearestWorkingDay.plusDays(1); } while (!isWorkingDay(nearestWorkingDay)); return nearestWorkingDay; }
From source file:org.mifos.calendar.WorkingDay.java
License:Open Source License
public static DateTime nextWorkingDay(final DateTime day, final List<Days> workingDays) { if (workingDays == null || workingDays.isEmpty()) { throw new IllegalStateException("workingDays cannot be null or empty"); }/*from w w w.j av a 2 s . c o m*/ DateTime nextWorkingDay = day; do { nextWorkingDay = nextWorkingDay.plusDays(1); } while (isNotWorkingDay(nextWorkingDay, workingDays)); return nextWorkingDay; }