List of usage examples for org.joda.time LocalDateTime toString
public String toString(String pattern)
From source file:com.axelor.apps.production.web.OperationOrderController.java
License:Open Source License
public void chargeByMachineHours(ActionRequest request, ActionResponse response) throws AxelorException { List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>(); DateTimeFormatter parser = ISODateTimeFormat.dateTime(); LocalDateTime fromDateTime = LocalDateTime.parse(request.getContext().get("fromDateTime").toString(), parser);//from w ww.j a v a 2 s .c o m LocalDateTime toDateTime = LocalDateTime.parse(request.getContext().get("toDateTime").toString(), parser); LocalDateTime itDateTime = new LocalDateTime(fromDateTime); if (Days.daysBetween( new LocalDate(fromDateTime.getYear(), fromDateTime.getMonthOfYear(), fromDateTime.getDayOfMonth()), new LocalDate(toDateTime.getYear(), toDateTime.getMonthOfYear(), toDateTime.getDayOfMonth())) .getDays() > 20) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS)), IException.CONFIGURATION_ERROR); } List<OperationOrder> operationOrderListTemp = operationOrderRepo.all() .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime) .fetch(); Set<String> machineNameList = new HashSet<String>(); for (OperationOrder operationOrder : operationOrderListTemp) { if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) { if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) { machineNameList.add(operationOrder.getWorkCenter().getMachine().getName()); } } } while (!itDateTime.isAfter(toDateTime)) { List<OperationOrder> operationOrderList = operationOrderRepo.all() .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)) .fetch(); Map<String, BigDecimal> map = new HashMap<String, BigDecimal>(); for (OperationOrder operationOrder : operationOrderList) { if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) { String machine = operationOrder.getWorkCenter().getMachine().getName(); int numberOfMinutes = 0; if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) { numberOfMinutes = Minutes.minutesBetween(itDateTime, operationOrder.getPlannedEndDateT()) .getMinutes(); } else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) { numberOfMinutes = Minutes .minutesBetween(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1)) .getMinutes(); } else { numberOfMinutes = Minutes.minutesBetween(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()).getMinutes(); } if (numberOfMinutes > 60) { numberOfMinutes = 60; } BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)) .divide(new BigDecimal(60), 2, RoundingMode.HALF_UP); if (map.containsKey(machine)) { map.put(machine, map.get(machine).add(percentage)); } else { map.put(machine, percentage); } } } Set<String> keyList = map.keySet(); for (String key : machineNameList) { if (keyList.contains(key)) { Map<String, Object> dataMap = new HashMap<String, Object>(); if (Hours.hoursBetween(fromDateTime, toDateTime).getHours() > 24) { dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy HH:mm")); } else { dataMap.put("dateTime", (Object) itDateTime.toString("HH:mm")); } dataMap.put("charge", (Object) map.get(key)); dataMap.put("machine", (Object) key); dataList.add(dataMap); } else { Map<String, Object> dataMap = new HashMap<String, Object>(); if (Hours.hoursBetween(fromDateTime, toDateTime).getHours() > 24) { dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy HH:mm")); } else { dataMap.put("dateTime", (Object) itDateTime.toString("HH:mm")); } dataMap.put("charge", (Object) BigDecimal.ZERO); dataMap.put("machine", (Object) key); dataList.add(dataMap); } } itDateTime = itDateTime.plusHours(1); } response.setData(dataList); }
From source file:com.axelor.apps.production.web.OperationOrderController.java
License:Open Source License
public void chargeByMachineDays(ActionRequest request, ActionResponse response) throws AxelorException { List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>(); DateTimeFormatter parser = ISODateTimeFormat.dateTime(); LocalDateTime fromDateTime = LocalDateTime.parse(request.getContext().get("fromDateTime").toString(), parser);/*from w ww .j a v a 2s. c o m*/ fromDateTime = fromDateTime.withHourOfDay(0).withMinuteOfHour(0); LocalDateTime toDateTime = LocalDateTime.parse(request.getContext().get("toDateTime").toString(), parser); toDateTime = toDateTime.withHourOfDay(23).withMinuteOfHour(59); LocalDateTime itDateTime = new LocalDateTime(fromDateTime); if (Days.daysBetween( new LocalDate(fromDateTime.getYear(), fromDateTime.getMonthOfYear(), fromDateTime.getDayOfMonth()), new LocalDate(toDateTime.getYear(), toDateTime.getMonthOfYear(), toDateTime.getDayOfMonth())) .getDays() > 500) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS)), IException.CONFIGURATION_ERROR); } List<OperationOrder> operationOrderListTemp = operationOrderRepo.all() .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime) .fetch(); Set<String> machineNameList = new HashSet<String>(); for (OperationOrder operationOrder : operationOrderListTemp) { if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) { if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) { machineNameList.add(operationOrder.getWorkCenter().getMachine().getName()); } } } while (!itDateTime.isAfter(toDateTime)) { List<OperationOrder> operationOrderList = operationOrderRepo.all() .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime, itDateTime.plusHours(1)) .fetch(); Map<String, BigDecimal> map = new HashMap<String, BigDecimal>(); for (OperationOrder operationOrder : operationOrderList) { if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) { String machine = operationOrder.getWorkCenter().getMachine().getName(); int numberOfMinutes = 0; if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) { numberOfMinutes = Minutes.minutesBetween(itDateTime, operationOrder.getPlannedEndDateT()) .getMinutes(); } else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) { numberOfMinutes = Minutes .minutesBetween(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1)) .getMinutes(); } else { numberOfMinutes = Minutes.minutesBetween(operationOrder.getPlannedStartDateT(), operationOrder.getPlannedEndDateT()).getMinutes(); } if (numberOfMinutes > 60) { numberOfMinutes = 60; } int numberOfMinutesPerDay = 0; if (operationOrder.getWorkCenter().getMachine().getWeeklyPlanning() != null) { DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning( operationOrder.getWorkCenter().getMachine().getWeeklyPlanning(), new LocalDate(itDateTime)); numberOfMinutesPerDay = Minutes .minutesBetween(dayPlanning.getMorningFrom(), dayPlanning.getMorningTo()) .getMinutes(); numberOfMinutesPerDay += Minutes .minutesBetween(dayPlanning.getAfternoonFrom(), dayPlanning.getAfternoonTo()) .getMinutes(); } else { numberOfMinutesPerDay = 60 * 8; } BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100)) .divide(new BigDecimal(numberOfMinutesPerDay), 2, RoundingMode.HALF_UP); if (map.containsKey(machine)) { map.put(machine, map.get(machine).add(percentage)); } else { map.put(machine, percentage); } } } Set<String> keyList = map.keySet(); for (String key : machineNameList) { if (keyList.contains(key)) { int found = 0; for (Map<String, Object> mapIt : dataList) { if (mapIt.get("dateTime").equals((Object) itDateTime.toString("dd/MM/yyyy")) && mapIt.get("machine").equals((Object) key)) { mapIt.put("charge", new BigDecimal(mapIt.get("charge").toString()).add(map.get(key))); found = 1; break; } } if (found == 0) { Map<String, Object> dataMap = new HashMap<String, Object>(); dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy")); dataMap.put("charge", (Object) map.get(key)); dataMap.put("machine", (Object) key); dataList.add(dataMap); } } } itDateTime = itDateTime.plusHours(1); } response.setData(dataList); }
From source file:com.constellio.model.packaging.custom.CustomPluginsPackagingService.java
private String format(LocalDateTime localDateTime) { // return new SimpleDateFormat("yyyy-MM-dd").format(localDateTime); return localDateTime.toString("yyyy-MM-dd"); }
From source file:com.kccomy.orgar.adapter.SimpleTreeAdapter.java
License:Apache License
@Override public View getConvertView(final TreeNode treeNode, int position, View convertView, ViewGroup parent) { TreeViewHolder treeViewHolder;/*from ww w .j a v a2s.c o m*/ if (convertView == null) { convertView = inflater.inflate(R.layout.item_tree, parent, false); treeViewHolder = new TreeViewHolder(convertView); convertView.setTag(treeViewHolder); } else { treeViewHolder = (TreeViewHolder) convertView.getTag(); } //Hide root node if (position == 0) { convertView.setVisibility(View.GONE); } else { convertView.setVisibility(View.VISIBLE); } if (treeNode.getIcon() == -1) { treeViewHolder.nodeIcon.setVisibility(View.INVISIBLE); } else { treeViewHolder.nodeIcon.setVisibility(View.VISIBLE); treeViewHolder.nodeIcon.setImageResource(treeNode.getIcon()); } String todo = treeNode.getTodo(); if (todo != null) { treeViewHolder.todoText.setText(todo); TextPaint paint = treeViewHolder.todoText.getPaint(); paint.setFakeBoldText(true); } else { treeViewHolder.todoText.setVisibility(View.GONE); } treeViewHolder.priorityText.setVisibility(View.GONE); treeViewHolder.headerText.setText(treeNode.getHeader()); String body = treeNode.getBody(); if (body != null) { treeViewHolder.bodyText.setText(body); } else { treeViewHolder.bodyText.setVisibility(View.GONE); } String deadline = null; LocalDateTime deadlineDate = treeNode.getTimestamp(OrgTimestamp.Type.DEADLINE); if (deadlineDate != null) { deadline = deadlineDate.toString("HH:mm"); } if (deadline != null) { treeViewHolder.deadlineIcon.setImageResource(R.drawable.ic_deadline_black); treeViewHolder.deadlineText.setText(deadline); } else { treeViewHolder.deadlineIcon.setVisibility(View.GONE); treeViewHolder.deadlineText.setVisibility(View.GONE); } String scheduled = null; LocalDateTime scheduledDate = treeNode.getTimestamp(OrgTimestamp.Type.SCHEDULED); if (scheduledDate != null) { scheduled = scheduledDate.toString("yyyy-MM-dd HH:mm"); } if (scheduled != null) { treeViewHolder.scheduledIcon.setImageResource(R.drawable.ic_deadline_black); treeViewHolder.scheduledText.setText(scheduled); } else { treeViewHolder.scheduledIcon.setVisibility(View.GONE); treeViewHolder.scheduledText.setVisibility(View.GONE); } treeViewHolder.closedIcon.setVisibility(View.GONE); treeViewHolder.closedText.setVisibility(View.GONE); return convertView; }
From source file:com.kccomy.orgar.module.TreeNode.java
License:Apache License
public void setTimestamp(LocalDateTime dateTime, OrgTimestamp.Type type) { if (dateTime == null || type == null) return;// ww w .ja v a 2 s . co m OrgTimestamp timestamp = null; for (OrgTimestamp t : orgNode.getTimestamps()) { if (type.equals(t.getType())) { timestamp = t; } } if (timestamp == null) { OrgTimestamp ts = new OrgTimestamp("[", OrgTimestamp.Type.SCHEDULED.toString(), dateTime.toString("yyyy-MM-dd"), dateTime.toString("HH:mm"), null, null, null); orgNode.addTimestamp(ts); } else { timestamp.setDate(dateTime, true); } }
From source file:com.kccomy.orgar.ui.editor.NodeEditorFragment.java
License:Apache License
@Override public void onDateSet(com.wdullaer.materialdatetimepicker.date.DatePickerDialog view, int year, int month, int day) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day);/*from w w w . j ava 2 s.co m*/ LocalDateTime date = LocalDateTime.fromCalendarFields(calendar); String tag = view.getTag(); if (OrgTimestamp.Type.SCHEDULED.toString().equals(tag)) { scheduledDateBtn.setText(date.toString(DATE_FORMAT)); scheduledDate = date; if (scheduledTime != null) { scheduledDate.withTime(scheduledTime.getHourOfDay(), scheduledTime.getMinuteOfHour(), 0, 0); } } else if (OrgTimestamp.Type.DEADLINE.toString().equals(tag)) { deadlineDateBtn.setText(date.toString(DATE_FORMAT)); deadlineDate = date; if (deadlineTime != null) { deadlineDate.withTime(deadlineTime.getHourOfDay(), deadlineTime.getMinuteOfHour(), 0, 0); } } }
From source file:com.kccomy.orgar.util.DateFormatUtil.java
License:Apache License
public static String getFormattedDate(Date date) { LocalDateTime modified = LocalDateTime.fromDateFields(date); LocalDateTime now = LocalDateTime.now(); if (modified.getWeekOfWeekyear() == now.getWeekOfWeekyear() && modified.getYear() == now.getYear()) { if (modified.getDayOfWeek() == now.getDayOfWeek()) { return modified.toString(TIME); } else {/*from w ww . jav a 2 s.c o m*/ return modified.toString(WEEK); } } else { return modified.toString(DATE); } }
From source file:com.makotogo.mobile.datetimepickerexample.MainActivity.java
License:Apache License
private String formatDateString(LocalDateTime localDateTime) { return localDateTime.toString("MM/dd/yyyy hh:mm a"); }
From source file:com.makotogo.mobile.hoursdroid.FilterDialogFragment.java
License:Apache License
/** * Formats the specified date according to the format string from the * ApplicationOptions object.//from w ww .j ava 2 s . c om * <p/> * TODO: Move to generic class? * * @param date * @return */ private String formatDate(Date date) { ApplicationOptions applicationOptions = ApplicationOptions.instance(getActivity()); String dateFormatString = applicationOptions.getDateFormatString(); // Sanity check if (dateFormatString == null || dateFormatString.equals("")) { throw new RuntimeException("Date Format String cannot be null or empty string."); } LocalDateTime localDateTime = new LocalDateTime(date.getTime()); return localDateTime.toString(dateFormatString); }
From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java
License:Apache License
private void updateBegin() { if (mHours.getBegin() != null) { LocalDateTime beginDateTime = new LocalDateTime(mHours.getBegin().getTime()); ((TextView) getView().findViewById(R.id.textview_hours_detail_begin_date)) .setText(beginDateTime.toString(DATE_FORMAT_PATTERN)); }// w w w . j ava 2 s . com }