List of usage examples for org.joda.time LocalDate dayOfMonth
public Property dayOfMonth()
From source file:com.inkubator.hrm.web.HomeDashboardController.java
@PostConstruct @Override//from w w w . jav a2s . c o m public void initialization() { super.initialization(); distribusiKaryawanPerDepartment = new CartesianChartModel(); barChartDistribusiByDept = new BarChartModel(); pieModel = new PieChartModel(); totalMale = new Long(0); totalFemale = new Long(0); try { /** * find All holiday date based on JadwalKaryawan "DEFAULT" which is * OFF and public holiday */ LocalDate now = new LocalDate(); startCalendarDate = now.dayOfMonth().withMinimumValue().toDate(); endCalendarDate = now.dayOfMonth().withMaximumValue().toDate(); Set<Date> holidays = wtScheduleShiftService.getAllRegulerOffDaysBetween(startCalendarDate, endCalendarDate); for (Date holiday : holidays) { DateTime dtHoliday = new DateTime(holiday); listHolidayDate.add(dtHoliday.getDayOfMonth()); } /** * calculate employee distribution based on GENDER */ Map<String, Long> employeesByGender = empDataService.getTotalByGender(HrmUserInfoUtil.getCompanyId()); totalFemale = employeesByGender.get("male"); totalMale = employeesByGender.get("female"); lastUpdateEmpDistByGender = new Date(employeesByGender.get("lastUpdate")); /** * calculate employee distribution based on DEPARTMENT */ Map<String, Long> employeesByDepartment = empDataService .getTotalByDepartment(HrmUserInfoUtil.getCompanyId()); int i = 0; for (Map.Entry<String, Long> entry : employeesByDepartment.entrySet()) { /** * only 8 department is allowed to show atau jika entry key nya * "lastUpdate" berarti itu akhir dari list */ if (i == 8 || StringUtils.equals(entry.getKey(), "lastUpdate")) { break; } i++; ChartSeries deptSeries = new ChartSeries(); deptSeries.setLabel(entry.getKey()); deptSeries.set("Department", entry.getValue()); barChartDistribusiByDept.addSeries(deptSeries); } barChartDistribusiByDept.setLegendPosition("ne"); barChartDistribusiByDept.setStacked(false); barChartDistribusiByDept.setShowDatatip(true); barChartDistribusiByDept.setLegendCols(4); barChartDistribusiByDept.setLegendRows(2); barChartDistribusiByDept.setSeriesColors("66cc00,629de1,003366,990000,cccc00,6600cc,006666,660066"); lastUpdateEmpDistByDepartment = new Date(employeesByDepartment.get("lastUpdate")); /** * calculate employee distribution based on AGE */ Map<String, Long> employeesByAge = empDataService.getTotalByAge(HrmUserInfoUtil.getCompanyId()); pieModel.set("< 26", employeesByAge.get("lessThan26")); pieModel.set("25-30", employeesByAge.get("between26And30")); pieModel.set("31-35", employeesByAge.get("between31And35")); pieModel.set("36-40", employeesByAge.get("between36And40")); pieModel.set("> 40", employeesByAge.get("moreThan40")); pieModel.setLegendPosition("e"); pieModel.setFill(false); pieModel.setShowDataLabels(true); pieModel.setSliceMargin(4); pieModel.setDiameter(120); pieModel.setSeriesColors("66cc00,629de1,003366,990000,cccc00,6600cc"); lastUpdateEmpDistByAge = new Date(employeesByAge.get("lastUpdate")); /** * calculate employee resume */ employeeResumeModel = empDataService.getEmployeeResumeOnDashboard(HrmUserInfoUtil.getCompanyId()); /** * calculate attendance statistic */ attendanceModel = tempAttendanceRealizationService.getStatisticEmpAttendaceRealization(); double totalPresent = Double.parseDouble(String.valueOf(attendanceModel.getTotaldayPresent())); double totalSchedule = Double.parseDouble(String.valueOf(attendanceModel.getTotaldaySchedule())); totalPersent = (totalPresent / totalSchedule); persentasiKehadiranPerWeek = new CartesianChartModel(); barChartModel = new BarChartModel(); barChartModel.setStacked(false); barChartModel.setLegendPosition("ne"); barChartModel.setLegendCols(6); barChartModel.setSeriesColors("66cc00,629de1,003366,990000,cccc00,6600cc"); barChartModel.setShowDatatip(true); barChartModel.setShadow(true); barChartModel.setShowPointLabels(true); Axis yAxis = barChartModel.getAxis(AxisType.Y); yAxis.setMax(150); yAxis.setMin(0); //Get Attendance Percentation per Department on Active Period Map<String, List<DepAttendanceRealizationViewModel>> mapResult = empDataService .getListDepAttendanceByCompanyId(HrmUserInfoUtil.getCompanyId()); //Looping and render it for (Map.Entry<String, List<DepAttendanceRealizationViewModel>> entry : mapResult.entrySet()) { ChartSeries charDepartmentSeries = new ChartSeries(); charDepartmentSeries.setLabel(entry.getKey()); List<DepAttendanceRealizationViewModel> listDepartmentModel = Lambda.sort(entry.getValue(), Lambda.on(DepAttendanceRealizationViewModel.class).getWeekNumber()); for (DepAttendanceRealizationViewModel depAttendanceModel : listDepartmentModel) { charDepartmentSeries.set( ResourceBundleUtil.getAsString("global.week") + " " + depAttendanceModel.getWeekNumber(), depAttendanceModel.getAttendancePercentage().doubleValue() * 100); } barChartModel.addSeries(charDepartmentSeries); } /** * calculate attendance statistic from 6 days ago until yesterday */ SimpleDateFormat formatter = new SimpleDateFormat("MMMM yyyy", LocaleContextHolder.getLocale()); int week = Calendar.getInstance().get(Calendar.WEEK_OF_MONTH); StringBuffer buff = new StringBuffer(); buff.append(week); if (LocaleContextHolder.getLocale().getLanguage().equals("en")) { buff.append(StringUtils.suffixesDayOfMonth[week]); } Object[] parameters = { buff.toString(), formatter.format(now.toDate()) }; ResourceBundle bundle = ResourceBundle.getBundle("Messages", LocaleContextHolder.getLocale()); presentationAttendancePerDayLabel = MessageFormat.format(bundle.getString("home.week_update_data"), parameters); List<Date> listTanggalWaktuKerja = new ArrayList<>(); IntStream.range(1, 6).forEach(num -> listTanggalWaktuKerja.add(now.minusDays(num).toDate())); List<ChartSeries> listPresentasiAttendance = empDataService .getEmployeePresentationAttendanceOnDashboard(HrmUserInfoUtil.getCompanyId(), listTanggalWaktuKerja, "dd MMM yyyy"); presentationAttendancePerDayBarChartModel = new HorizontalBarChartModel(); listPresentasiAttendance.forEach(series -> presentationAttendancePerDayBarChartModel.addSeries(series)); presentationAttendancePerDayBarChartModel.setStacked(true); presentationAttendancePerDayBarChartModel.setShowDatatip(true); presentationAttendancePerDayBarChartModel.setLegendPosition("se"); presentationAttendancePerDayBarChartModel .setSeriesColors("66cc00,629de1,003366,990000,cccc00,6600cc,d500d5,ff2a55"); Axis xAxis = presentationAttendancePerDayBarChartModel.getAxis(AxisType.X); xAxis.setMax(300); xAxis.setTickInterval("20"); xAxis.setMin(0); } catch (Exception e) { LOGGER.error("Error ", e); } }
From source file:com.jjlharrison.jollyday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
/** * Parses the {@link FixedWeekdayInMonth}. * * @param year//from ww w . ja v a 2s . c om * the year * @param fwm * the fwm * @return the local date */ protected LocalDate parse(int year, FixedWeekdayInMonth fwm) { LocalDate date = calendarUtil.create(year, xmlUtil.getMonth(fwm.getMonth()), 1); int direction = 1; if (Which.LAST.equals(fwm.getWhich())) { date = date.withDayOfMonth(date.dayOfMonth().getMaximumValue()); direction = -1; } date = moveToNextRequestedWeekdayByDirection(fwm, date, direction); date = moveNumberOfRequestedWeeks(fwm, date); return date; }
From source file:com.mars.test.jodatime.Mars_App.java
public static void main(String[] args) { // LocalDate , TimeZone LocalDate dt = new LocalDate(); // 1.?1~31/*w ww . j a v a 2 s . co m*/ log.info("1.?" + dt.withDayOfMonth(1).toString(pattern) + " ~ " + dt.dayOfMonth().withMaximumValue().toString(pattern)); // 2.?26~25(????) log.info("2.?" + dt.minusMonths(1).withDayOfMonth(26).toString(pattern) + " ~ " + dt.withDayOfMonth(25).toString(pattern)); // 3.??? LocalDate date2 = dt.withDayOfMonth(5); if (date2.getDayOfWeek() == DateTimeConstants.SATURDAY || date2.getDayOfWeek() == DateTimeConstants.SUNDAY) { date2 = date2.plusWeeks(1).withDayOfWeek(1); } log.info("3." + date2.toString(pattern)); LocalDate date3 = dt.plusMonths(1).withDayOfMonth(5); if (date3.getDayOfWeek() >= 6) { date3 = date3.plusWeeks(1).withDayOfWeek(1); } log.info("4.2014/7" + date3.toString(pattern)); }
From source file:com.ning.billing.invoice.generator.InvoiceDateUtils.java
License:Apache License
public static LocalDate calculateLastBillingCycleDateBefore(final LocalDate date, final LocalDate previousBillCycleDate, final int billingCycleDay, final BillingPeriod billingPeriod) { LocalDate proposedDate = previousBillCycleDate; int numberOfPeriods = 0; while (!proposedDate.isAfter(date)) { proposedDate = previousBillCycleDate.plusMonths(numberOfPeriods * billingPeriod.getNumberOfMonths()); numberOfPeriods += 1;/*from www. j av a 2s.c o m*/ } proposedDate = proposedDate.plusMonths(-billingPeriod.getNumberOfMonths()); if (proposedDate.dayOfMonth().get() < billingCycleDay) { final int lastDayOfTheMonth = proposedDate.dayOfMonth().getMaximumValue(); if (lastDayOfTheMonth < billingCycleDay) { proposedDate = new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), lastDayOfTheMonth); } else { proposedDate = new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), billingCycleDay); } } if (proposedDate.isBefore(previousBillCycleDate)) { // Make sure not to go too far in the past return previousBillCycleDate; } else { return proposedDate; } }
From source file:com.ning.billing.invoice.generator.InvoiceDateUtils.java
License:Apache License
public static LocalDate calculateBillingCycleDateOnOrAfter(final LocalDate date, final int billingCycleDayLocal) { final int lastDayOfMonth = date.dayOfMonth().getMaximumValue(); final LocalDate fixedDate; if (billingCycleDayLocal > lastDayOfMonth) { fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), lastDayOfMonth, date.getChronology()); } else {// ww w.j a v a 2s.co m fixedDate = new LocalDate(date.getYear(), date.getMonthOfYear(), billingCycleDayLocal, date.getChronology()); } LocalDate proposedDate = fixedDate; while (proposedDate.isBefore(date)) { proposedDate = proposedDate.plusMonths(1); } return proposedDate; }
From source file:com.stagecents.pay.domain.PayCycle.java
License:Open Source License
public LocalDate getCycleEnd(LocalDate cycleStart) { LocalDate result = null;//from ww w . j a v a 2 s.c om if (frequency.equals(Frequency.W)) { result = cycleStart.plusDays(6); } else if (frequency.equals(Frequency.F)) { result = cycleStart.plusDays(13); } else if (frequency.equals(Frequency.SM)) { result = (cycleStart.getDayOfMonth() == 1) ? cycleStart.withDayOfMonth(15) : cycleStart.dayOfMonth().withMaximumValue(); } else if (frequency.equals(Frequency.CM)) { result = cycleStart.dayOfMonth().withMaximumValue(); } else if (frequency.equals(Frequency.Q)) { result = cycleStart.plusMonths(2).dayOfMonth().withMaximumValue(); } return result; }
From source file:dao.RegistroDao.java
public List<Registro> getListBetween(Date dt1, Date dt2) { List<Registro> result = new ArrayList<Registro>(); try {/*w ww .j a va 2s . c o m*/ LocalDate dtTmp = LocalDate.fromDateFields(dt1); while (dt2.compareTo(dtTmp.dayOfMonth().withMinimumValue().toDate()) >= 0) { List<Registro> listTmp = getListByMonth(dtTmp.toDate()); if (listTmp != null) { result.addAll(listTmp); //ordena a lista Collections.sort(result, regComparator); } dtTmp = dtTmp.plusMonths(1); } } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:de.appsolve.padelcampus.utils.BookingUtil.java
public void addWeekView(HttpServletRequest request, LocalDate selectedDate, List<Facility> selectedFacilities, ModelAndView mav, Boolean onlyFutureTimeSlots, Boolean preventOverlapping) throws JsonProcessingException { //calculate date configuration for datepicker LocalDate today = new LocalDate(DEFAULT_TIMEZONE); LocalDate firstDay = today.dayOfMonth().withMinimumValue(); LocalDate lastDay = getLastBookableDay(request).plusDays(1); List<CalendarConfig> calendarConfigs = calendarConfigDAO.findBetween(firstDay, lastDay); Collections.sort(calendarConfigs); Map<String, DatePickerDayConfig> dayConfigs = getDayConfigMap(firstDay, lastDay, calendarConfigs); List<Booking> confirmedBookings = bookingDAO.findBlockedBookingsBetween(firstDay, lastDay); //calculate available time slots List<TimeSlot> timeSlots = new ArrayList<>(); List<LocalDate> weekDays = new ArrayList<>(); for (int i = 1; i <= CalendarWeekDay.values().length; i++) { LocalDate date = selectedDate.withDayOfWeek(i); weekDays.add(date);/*from w w w. j a v a 2s. c om*/ if ((!onlyFutureTimeSlots || !date.isBefore(today)) && lastDay.isAfter(date)) { try { //generate list of bookable time slots timeSlots.addAll(getTimeSlotsForDate(date, calendarConfigs, confirmedBookings, onlyFutureTimeSlots, preventOverlapping)); } catch (CalendarConfigException e) { //safe to ignore } } } SortedSet<Offer> offers = new TreeSet<>(); List<TimeRange> rangeList = new ArrayList<>(); //Map<TimeRange, List<TimeSlot>> rangeList = new TreeMap<>(); for (TimeSlot slot : timeSlots) { Set<Offer> slotOffers = slot.getConfig().getOffers(); offers.addAll(slotOffers); TimeRange range = new TimeRange(); range.setStartTime(slot.getStartTime()); range.setEndTime(slot.getEndTime()); if (rangeList.contains(range)) { range = rangeList.get(rangeList.indexOf(range)); } else { rangeList.add(range); } List<TimeSlot> slotis = range.getTimeSlots(); slotis.add(slot); range.setTimeSlots(slotis); } Collections.sort(rangeList); List<Offer> selectedOffers = new ArrayList<>(); if (selectedFacilities.isEmpty()) { selectedOffers = offerDAO.findAll(); } else { for (Facility facility : selectedFacilities) { selectedOffers.addAll(facility.getOffers()); } } Collections.sort(selectedOffers); mav.addObject("dayConfigs", objectMapper.writeValueAsString(dayConfigs)); mav.addObject("maxDate", lastDay.toString()); mav.addObject("Day", selectedDate); mav.addObject("NextMonday", selectedDate.plusDays(8 - selectedDate.getDayOfWeek())); mav.addObject("PrevSunday", selectedDate.minusDays(selectedDate.getDayOfWeek())); mav.addObject("WeekDays", weekDays); mav.addObject("RangeMap", rangeList); mav.addObject("Offers", offers); mav.addObject("SelectedOffers", selectedOffers); mav.addObject("SelectedFacilities", selectedFacilities); mav.addObject("Facilities", facilityDAO.findAll()); }
From source file:de.jollyday.parser.impl.FixedWeekdayInMonthParser.java
License:Apache License
/** * Parses the {@link FixedWeekdayInMonth}. * /*from w ww . j a va2s. c o m*/ * @param year * the year * @param fwm * the fwm * @return the local date */ protected LocalDate parse(int year, FixedWeekdayInMonth fwm) { LocalDate date = calendarUtil.create(year, xmlUtil.getMonth(fwm.getMonth()), 1); int direction = 1; if (fwm.getWhich() == Which.LAST) { date = date.withDayOfMonth(date.dayOfMonth().getMaximumValue()); direction = -1; } date = moveToNextRequestedWeekdayByDirection(fwm, date, direction); date = moveNumberOfRequestedWeeks(fwm, date); return date; }
From source file:energy.usef.brp.workflow.settlement.initiate.BrpInitiateSettlementCoordinator.java
License:Apache License
/** * Preparation of the Initiate Settlement process for the first day of the previous month until the last day of the previous * month. The initiating of settlements will stop if there are no flex orders in the selected period. * * @param event The {@link CollectSmartMeterDataEvent} triggering the process. *//*from w w w. jav a 2s .co m*/ @Asynchronous @Lock(LockType.WRITE) public void handleCollectSmartMeterDataEvent( @Observes(during = TransactionPhase.AFTER_COMPLETION) CollectSmartMeterDataEvent event) { LOGGER.debug(USEFConstants.LOG_COORDINATOR_START_HANDLING_EVENT, event); LocalDate dayOneMonthBefore = event.getPeriodInMonth(); if (dayOneMonthBefore == null) { dayOneMonthBefore = DateTimeUtil.getCurrentDate().minusMonths(1); } LocalDate startDate = dayOneMonthBefore.withDayOfMonth(1); LocalDate endDate = dayOneMonthBefore.dayOfMonth().withMaximumValue(); // retrieve a distinct list of all connections valid in given time frame and map them to a string list. Map<LocalDate, Map<ConnectionGroup, List<Connection>>> connectionGroupsWithConnections = corePlanboardBusinessService .findConnectionGroupWithConnectionsWithOverlappingValidity(startDate, endDate); List<LocalDate> daysWithOrders = corePlanboardBusinessService .findPlanboardMessages(DocumentType.FLEX_ORDER, startDate, endDate, DocumentStatus.ACCEPTED) .stream().map(PlanboardMessage::getPeriod).distinct().collect(Collectors.toList()); if (daysWithOrders.isEmpty()) { checkInitiateSettlementDoneEvent .fire(new CheckInitiateSettlementDoneEvent(startDate.getYear(), startDate.getMonthOfYear())); LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event); return; } // loop through all the MDCs for (MeterDataCompany meterDataCompany : brpBusinessService.findAllMDCs()) { // query meter data company (MDC) for all connections LOGGER.info("Preparing sending MeterDataQuery to Meter Data Company {}", meterDataCompany.getDomain()); for (LocalDate period : connectionGroupsWithConnections.keySet()) { if (!daysWithOrders.contains(period)) { continue; } LocalDateTime expirationDateTime = DateTimeUtil.getCurrentDateTime().plusHours( configBrp.getIntegerProperty(ConfigBrpParam.BRP_METER_DATA_QUERY_EXPIRATION_IN_HOURS)); MessageMetadata messageMetadata = MessageMetadataBuilder .build(meterDataCompany.getDomain(), USEFRole.MDC, config.getProperty(ConfigParam.HOST_DOMAIN), USEFRole.BRP, TRANSACTIONAL) .validUntil(expirationDateTime).build(); // fill the MeterDataQuery message MeterDataQuery meterDataQuery = new MeterDataQuery(); meterDataQuery.setMessageMetadata(messageMetadata); meterDataQuery.setDateRangeStart(period); meterDataQuery.setDateRangeEnd(period); meterDataQuery.getConnections() .addAll(buildConnectionGroups(connectionGroupsWithConnections.get(period))); MeterDataQueryMessageUtil.populateConnectionsInConnectionGroups(meterDataQuery, connectionGroupsWithConnections.get(period)); // Store in PlanboardMessage, no connectionGroup available because query is for the whole grid. // the period should be the startDate of the month. PlanboardMessage meterDataQueryPlanboardMessage = new PlanboardMessage( DocumentType.METER_DATA_QUERY_USAGE, sequenceGeneratorService.next(), DocumentStatus.SENT, meterDataCompany.getDomain(), period, null, null, expirationDateTime); corePlanboardBusinessService.updatePlanboardMessage(meterDataQueryPlanboardMessage); // send the message jmsHelperService.sendMessageToOutQueue(XMLUtil.messageObjectToXml(meterDataQuery)); } } LOGGER.debug(USEFConstants.LOG_COORDINATOR_FINISHED_HANDLING_EVENT, event); }