List of usage examples for org.joda.time LocalDate getDayOfWeek
public int getDayOfWeek()
From source file:org.smartdeveloperhub.harvesters.it.testing.generator.Utils.java
License:Apache License
static boolean isWorkingDay(final LocalDate today) { final int dayOfWeek = today.getDayOfWeek(); return DateTimeConstants.SUNDAY != dayOfWeek && DateTimeConstants.SATURDAY != dayOfWeek; }
From source file:org.springframework.samples.petclinic.web.ResultController.java
License:Apache License
/** * * Complex algorith to find the winners /*from w w w . jav a2 s . co m*/ * */ private ArrayList<SumVotes> checkVoteResults() { //get votes Collection<Chooser> oCollection = this.clinicService.findChoices(); Iterator<Chooser> i = oCollection.iterator(); LocalDate dCurrentDate = new LocalDate();//DIA D HJ int nDiaSemana = dCurrentDate.getDayOfWeek(); LocalDate dFirstDayWeek = dCurrentDate.minusDays(nDiaSemana); LocalDate dFinalWeekDay = dFirstDayWeek.plusDays(6); //the week is starting on monday = 1 //sunday is 7 = friday is 5 ArrayList<VoteByDay> oKeepWeekDaysList = new ArrayList<VoteByDay>(); ArrayList<Vote> oInnerKeepWeekDaysList = new ArrayList<Vote>(); //run the list to keep the week day on one collection Chooser oneOptionChoosed = new Chooser(); while (i.hasNext()) { oneOptionChoosed = i.next(); //remove days outside of the week if (dFinalWeekDay.getDayOfYear() >= oneOptionChoosed.getPickedDate().getDayOfYear() && oneOptionChoosed.getPickedDate().getDayOfYear() >= dFirstDayWeek.getDayOfYear()) { Vote oVote = new Vote(); oVote.setRestaurantName(oneOptionChoosed.getRestaurant().getMainName()); oVote.setWeekDay(oneOptionChoosed.getPickedDate().getDayOfWeek()); oInnerKeepWeekDaysList.add(oVote); //print which data is in the week System.out.println("restaurant " + oneOptionChoosed.getRestaurant().getMainName() + " Data: " + oneOptionChoosed.getPickedDate().toString() + " user : " + oneOptionChoosed.getOwner().getLastName()); } //After today is not going to show //print database // System.out.println("restaurant " + oneOptionChoosed.getRestaurant().getMainName() + " Data: " + oneOptionChoosed.getPickedDate().toString() + // " user : " + oneOptionChoosed.getOwner().getLastName()); } boolean bSHouldInclude = false; //for to weekdays for (int ind = 1; ind <= 7; ind++) { VoteByDay oVoteByDay = new VoteByDay(); //runs over the total votes for (Vote oCurrentVote : oInnerKeepWeekDaysList) { if (ind == oCurrentVote.getWeekDay()) { bSHouldInclude = true; if (oVoteByDay.getComplexVote().containsKey(oCurrentVote.getRestaurantName())) { int nCurrentValue = oVoteByDay.getComplexVote().get(oCurrentVote.getRestaurantName()); nCurrentValue++; oVoteByDay.getComplexVote().put(oCurrentVote.getRestaurantName(), nCurrentValue); oVoteByDay.setWeekDay(ind); } else { oVoteByDay.getComplexVote().put(oCurrentVote.getRestaurantName(), 1); oVoteByDay.setWeekDay(ind); } } //dont need here, it will pass again for other day } if (bSHouldInclude) { oKeepWeekDaysList.add(oVoteByDay); bSHouldInclude = false; } } ArrayList<SumVotes> oKeepWinnersList = new ArrayList<SumVotes>(); boolean isDraw = false; //now prepare to show result //for (int indWeek = 1; indWeek < 8; indWeek++) for (VoteByDay oCheckWinnerVote : oKeepWeekDaysList) { Integer nCountVotes = 0; String sPossibleWinner = ""; String secondOptionRestaurant = ""; for (String key : oCheckWinnerVote.getComplexVote().keySet()) { //compare values int nTempValue = oCheckWinnerVote.getComplexVote().get(key); if (nTempValue > nCountVotes) { secondOptionRestaurant = sPossibleWinner; //used on repeated cases sPossibleWinner = key.toString(); nCountVotes = nTempValue; } else if (nTempValue == nCountVotes) { isDraw = true; sPossibleWinner += " & " + key.toString(); } else { secondOptionRestaurant = key.toString(); //used on repeated cases } } SumVotes oWinner = new SumVotes(); if (isDraw) { oWinner.setRestaurantName("Empate entre - " + sPossibleWinner); isDraw = false; } else { //test to not repeat restaurant for (SumVotes oCheckDuplicateWinnerVote : oKeepWinnersList) { if (sPossibleWinner.equals(oCheckDuplicateWinnerVote.getRestaurantName())) { System.out.println("Not allowed repeated restaurant on the week"); sPossibleWinner = secondOptionRestaurant; if (sPossibleWinner.length() < 1) { sPossibleWinner = "Restaurante repetido - dados insuficientes para indicar outro"; } } } oWinner.setRestaurantName(sPossibleWinner); } oWinner.setRestaurantName(sPossibleWinner); oWinner.setWeekDay(oCheckWinnerVote.getWeekDay()); oWinner.setTotalVotes(nCountVotes); oKeepWinnersList.add(oWinner); // if(isDraw) // System.out.println("possible empate"); // System.out.println("The winner is: " + sPossibleWinner + " With the following votes: " + nCountVotes.toString() + // " on the day " + oCheckWinnerVote.getWeekDay()); } //remove today data before 11am for (SumVotes oneWinnerVoteToDelete : oKeepWinnersList) { if (nDiaSemana == oneWinnerVoteToDelete.getWeekDay() && new DateTime().getHourOfDay() < 11) { oKeepWinnersList.remove(oneWinnerVoteToDelete); break; } } Integer nStartingWeekDay = dFirstDayWeek.getDayOfWeek(); //adjust week day to display for (SumVotes oneWinnerVote : oKeepWinnersList) { int nAdjustDay = 0; if (nStartingWeekDay > oneWinnerVote.getWeekDay()) { nAdjustDay = nStartingWeekDay - oneWinnerVote.getWeekDay() - 1; oneWinnerVote.setLunchTime(dFinalWeekDay.minusDays(nAdjustDay)); } else if (nStartingWeekDay == oneWinnerVote.getWeekDay()) { oneWinnerVote.setLunchTime(dFirstDayWeek); } else { nAdjustDay = nStartingWeekDay + oneWinnerVote.getWeekDay(); oneWinnerVote.setLunchTime(dFirstDayWeek.plusDays(nAdjustDay)); } } return oKeepWinnersList; }
From source file:org.squashtest.tm.domain.planning.StandardWorkloadCalendar.java
License:Open Source License
public float getWorkload(LocalDate start, LocalDate end) { if (end.isBefore(start)) { throw new IllegalArgumentException("dashboard.error.date"); }//from w ww . j a v a 2s . c o m LocalDate lstart = skipWeekendToMonday(start); LocalDate lend = truncateWeekendToLastFriday(end); // the following arises iif both days where in the weekend of the same week if (lend.isBefore(lstart)) { return Days.daysBetween(start, end).getDays() * WEEKEND_DAY_WORKLOAD; } int daysbetween = Days.daysBetween(lstart, lend).getDays() + 1; int adjustedDaysbetween = daysbetween + lstart.getDayOfWeek() - 1; int nbWeekend = adjustedDaysbetween / 7; int nbweekdays = daysbetween - nbWeekend * 2; return nbweekdays * BUSINESS_DAY_WORKLOAD; }
From source file:org.squashtest.tm.domain.planning.StandardWorkloadCalendar.java
License:Open Source License
private boolean isWeekend(LocalDate date) { return date.getDayOfWeek() == DateTimeConstants.SATURDAY || date.getDayOfWeek() == DateTimeConstants.SUNDAY; }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
/** * <code>true</code> if date is a week-end, else returns <code>false</code>. <br> * Override this method for custom week-ends days. * /* ww w. j av a2 s.c om*/ * @param date * the date * @return <code>true</code> if date is a week-end, else returns <code>false</code> */ protected boolean isWeekend(LocalDate date) { return date.getDayOfWeek() >= DateTimeConstants.SATURDAY; }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
/** * @return the first day of the calendar. As there are 7 columns displayed, if the first day of month is not in the * first column, we fill previous column items with days of previous month. *///from w w w .jav a2 s.c om private LocalDate getCalendarFirstDay() { LocalDate firstDayOfMonth = yearMonthDisplayed.toLocalDate(1); int calendarFirstDayOfWeek = firstDayOfWeek; int numberOfDaysSinceFirstDayOfWeek = (firstDayOfMonth.getDayOfWeek() - calendarFirstDayOfWeek + 7) % 7; return firstDayOfMonth.minusDays(numberOfDaysSinceFirstDayOfWeek); }
From source file:org.vaadin.addons.tuningdatefield.TuningDateField.java
License:Apache License
/** * @return the last day of the calendar. As there are 7 columns displayed, if the last day of month is not in the * last column, we fill next column items with days of next month. */// w w w. j a v a 2 s .co m private LocalDate getCalendarLastDay() { LocalDate lastDayOfMonth = yearMonthDisplayed.toLocalDate(1).dayOfMonth().withMaximumValue(); int calendarLastDayOfWeek = lastDayOfWeek; int numberOfDaysUntilLastDayOfWeek = (calendarLastDayOfWeek - lastDayOfMonth.getDayOfWeek() + 7) % 7; LocalDate lastDay = lastDayOfMonth.plusDays(numberOfDaysUntilLastDayOfWeek); if (isDisplayFixedNumberOfDayRows()) { // Always display 6 day rows int numberOfDays = Days.daysBetween(getCalendarFirstDay(), lastDay).getDays() + 1; if (numberOfDays / 7 < 5) { lastDay = lastDay.plusDays(14); } else if (numberOfDays / 7 < 6) { lastDay = lastDay.plusDays(7); } } return lastDay; }
From source file:org.zkoss.ganttz.timetracker.zoom.DetailFiveTimeTrackerState.java
License:Open Source License
@Override protected LocalDate round(LocalDate date, boolean down) { int dayOfWeek = date.getDayOfWeek(); if (dayOfWeek == 1) { return date; }/*from w ww .jav a2 s . co m*/ return down ? date.withDayOfWeek(1) : date.withDayOfWeek(1).plusWeeks(1); }
From source file:org.zkoss.ganttz.timetracker.zoom.DetailFourTimeTrackerState.java
License:Open Source License
@Override protected Iterator<LocalDate> getPeriodsSecondLevelGenerator(LocalDate start) { return new LazyGenerator<LocalDate>(start) { @Override// w w w. j a v a2 s. com protected LocalDate next(LocalDate last) { return last.getDayOfWeek() != 1 ? last.plusDays(getDaysUntilFirstDayNextWeek(last)) : last.plusWeeks(1); } }; }
From source file:org.zkoss.ganttz.timetracker.zoom.DetailFourTimeTrackerState.java
License:Open Source License
private int getDaysUntilFirstDayNextWeek(LocalDate date) { return 8 - date.getDayOfWeek(); }