/** * Metoda s³u¿y do obliczania iloœci dni, w których pracowa³ ankieter od pewnej ustalonej daty * * @param interviewer * @param from * @return */ private float numberOfDaysInWork(Interviewer interviewer, GregorianCalendar from) { float days = 0; List<Pair<GregorianCalendar, GregorianCalendar>> outOfWork = interviewer.getOutOfWorkTime(); if (interviewer.isActive()) { Date now = new Date(); days += daysBetween(from.getTime(), now); for (Pair<GregorianCalendar, GregorianCalendar> entr : outOfWork) { if (from.compareTo(entr.getFirst()) <= 0) { days -= daysBetween(entr.getFirst().getTime(), entr.getSecond().getTime()); } if (from.compareTo(entr.getFirst()) >= 0 && from.compareTo(entr.getSecond()) <= 0) { days -= daysBetween(from.getTime(), entr.getSecond().getTime()); } } } else { days += daysBetween(interviewer.getHiredDay().getTime(), interviewer.getRelieveDay().getTime()); for (Pair<GregorianCalendar, GregorianCalendar> entr : outOfWork) { if (from.compareTo(entr.getFirst()) <= 0) { days -= daysBetween(entr.getFirst().getTime(), entr.getSecond().getTime()); } if (from.compareTo(entr.getFirst()) >= 0 && from.compareTo(entr.getSecond()) <= 0) { days -= daysBetween(from.getTime(), entr.getSecond().getTime()); } } } return days; }
/** * Metoda s³u¿y do obliczenia liczby dni przepracowanych przez ankietera w podanym okresie. * Rozwa¿amy cztery przypadki nak³adania siê dat. * * @param interviewer * @param from * @param to * @return */ private float numberOfDaysInWork( Interviewer interviewer, GregorianCalendar from, GregorianCalendar to) { float days = 0; List<Pair<GregorianCalendar, GregorianCalendar>> outOfWork = interviewer.getOutOfWorkTime(); days += daysBetween(from.getTime(), to.getTime()); for (Pair<GregorianCalendar, GregorianCalendar> entr : outOfWork) { if (from.compareTo(entr.getFirst()) <= 0 && to.compareTo(entr.getSecond()) >= 0) { // nie nak³adaja siê days -= daysBetween(entr.getFirst().getTime(), entr.getSecond().getTime()); } if (from.compareTo(entr.getFirst()) >= 0 && to.compareTo(entr.getSecond()) >= 0 && from.compareTo(entr.getSecond()) <= 0) { // from jest w srodku okresu niepracuj¹cego days -= daysBetween(from.getTime(), entr.getSecond().getTime()); } if (from.compareTo(entr.getFirst()) <= 0 && to.compareTo(entr.getSecond()) <= 0 && entr.getFirst().compareTo(to) <= 0) { // to jest w œrodku okresu niepracuj¹cego days -= daysBetween(entr.getFirst().getTime(), to.getTime()); } if (from.compareTo(entr.getFirst()) >= 0 && to.compareTo(entr.getSecond()) <= 0) { // obie daty sa w srodku okresu niepracuj¹cego days -= daysBetween(from.getTime(), to.getTime()); } } return days; }
public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == anul) { dispose(); } if (source == save) { Date now; GregorianCalendar cal = new GregorianCalendar(); now = (Date) jdate.getValue(); cal.setTime(now); if (cal.compareTo(interviewer.getRelieveDay()) >= 0) { interviewer.setOutOfWorkTime(interviewer.getRelieveDay(), cal); int y1 = interviewer.getRelieveDay().get(Calendar.YEAR); // .toString(); int m1 = interviewer.getRelieveDay().get(Calendar.MONTH); int d1 = interviewer.getRelieveDay().get(Calendar.DAY_OF_MONTH); int y2 = cal.get(Calendar.YEAR); int m2 = cal.get(Calendar.MONTH); int d2 = cal.get(Calendar.DAY_OF_MONTH); String s = Integer.toString(d1) + "." + Integer.toString(m1 + 1) + "." + Integer.toString(y1) + " - " + Integer.toString(d2) + "." + Integer.toString(m2 + 1) + "." + Integer.toString(y2); interviewer.setRelieveDay(null); JOptionPane.showMessageDialog(this, "Przywrócono ankietera"); active.setText("Ankieter jest aktywny"); listModel.addElement(s); // JList newJlist = new JList(getTimeOutWork(interviewer)); // workOutTime = newJlist; // SwingUtilities.updateComponentTreeUI(this); // System.out.println("dzien zwolnienia ankietera "+ interviewer.getRelieveDay().getTime()); dispose(); } else { JOptionPane.showMessageDialog(this, "Data nieprawid³owa"); } } }