/** * Bereken de prijs die een ad-hoc klant moet betalen. * * @param intijd LocalDateTime * @param uittijd LocalDateTime * @return double */ public double berekenPrijs(LocalDateTime intijd, LocalDateTime uittijd) { // haal de benodigde informatie op ArrayList<TijdTarief> tijdtarief = db.getTijdTarief(); ArrayList<TariefCat> tariefcat = db.getTariefCat(); // maak de variabelen voor het berekenen aan Duration deltatijd = Duration.between(intijd, uittijd); Duration minus = Duration.ofMinutes(30); Duration zeroDuration = Duration.ZERO; LocalTime per30min = LocalTime.from(uittijd); HashMap<TariefCat, HashMap<Integer, Double>> teBetalenPerCatPerDag = new HashMap<>(); TariefCat tmpCat = null; do { DayOfWeek dag = uittijd.getDayOfWeek(); setDagnr(dag.getValue()); for (TijdTarief tijd : tijdtarief) { if (tijd.getDagbegin() <= getDagnr() && getDagnr() <= tijd.getDageind() && per30min.isAfter(tijd.getTijdstart()) && per30min.isBefore(tijd.getTijdeind())) { setCatnr(tijd.getCategorie()); } } for (TariefCat cat : tariefcat) { if (cat.getDatumbegin().getYear() == uittijd.toLocalDate().getYear() && cat.getDatumbegin().getMonthValue() <= uittijd.toLocalDate().getMonthValue() && cat.getCategorie() == getCatnr()) { tmpCat = cat; } } // update te betalen per categorie per dag HashMap<Integer, Double> totaal = teBetalenPerCatPerDag.getOrDefault(tmpCat, new HashMap<Integer, Double>()); double dagTotaal = totaal.getOrDefault(getDagnr(), 0.0); dagTotaal += tmpCat.getTarief(); totaal.put(getDagnr(), dagTotaal); teBetalenPerCatPerDag.put(tmpCat, totaal); uittijd = uittijd.minus(minus); deltatijd = deltatijd.minus(minus); per30min = LocalTime.from(uittijd); } while (deltatijd.compareTo(zeroDuration) == 1); double tebetalen = 0.0; for (Map.Entry<TariefCat, HashMap<Integer, Double>> dagEntry : teBetalenPerCatPerDag.entrySet()) { for (Map.Entry<Integer, Double> entry : dagEntry.getValue().entrySet()) { if (dagEntry.getKey().getMaxtarief() > entry.getValue().doubleValue()) tebetalen += entry.getValue(); else tebetalen += dagEntry.getKey().getMaxtarief(); } } BigDecimal bd = new BigDecimal(tebetalen); bd = bd.setScale(2, RoundingMode.HALF_UP); return bd.doubleValue(); }
@Test public void testVoteSuccess() { Vote correctVote = new Vote(); correctVote.setRestaurantId(Long.MIN_VALUE); Restaurant restaurant = new Restaurant(); restaurant.setRestaurantId(Long.MIN_VALUE); when(restaurantRepository.findOne(Long.MIN_VALUE)).thenReturn(restaurant); when(votingRepository.findByUser("admin")).thenReturn(null); try { MvcResult successVoteRes = mockMvc .perform( post("/vote") .contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(correctVote))) .andExpect(status().isOk()) .andReturn(); String outdatedVoteResString = successVoteRes.getResponse().getContentAsString(); assertTrue(outdatedVoteResString.contains(Status.SUCCESS.getStatusValue())); } catch (Exception e) { fail(); } LocalTime currentTime = LocalTime.now(); if (currentTime.isBefore(RestaurantController.DEADLINE)) { Restaurant votingRestaurant = new Restaurant(); votingRestaurant.setRestaurantId(Long.MAX_VALUE); Voting identicalVoting = new Voting(); identicalVoting.setRestaurant(votingRestaurant); when(votingRepository.findByUser("admin")).thenReturn(identicalVoting); try { MvcResult actualVoteRes = mockMvc .perform( post("/vote") .contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(correctVote))) .andExpect(status().isOk()) .andReturn(); String outdatedVoteResString = actualVoteRes.getResponse().getContentAsString(); assertTrue(outdatedVoteResString.contains(Status.SUCCESS.getStatusValue())); } catch (Exception e) { fail(); } } }
@Test public void test() { ZoneId zone1 = ZoneId.of("Europe/Berlin"); ZoneId zone2 = ZoneId.of("Brazil/East"); ZoneId zone3 = ZoneId.of("Europe/London"); LocalTime now1 = LocalTime.now(zone1); LocalTime now2 = LocalTime.now(zone2); System.out.println(now1.isBefore(now2)); // false long hoursBetween = ChronoUnit.HOURS.between(now1, now2); long minutesBetween = ChronoUnit.MINUTES.between(now1, now2); System.out.println(hoursBetween); // -3 System.out.println(minutesBetween); // -239 }
public boolean isTakeoffBetween(final DayPeriod period) { final LocalTime begin = period.begin; final LocalTime end = period.end; return (takeoffTime.equals(begin) || takeoffTime.isAfter(begin)) && (takeoffTime.isBefore(end) || takeoffTime.equals(end)); }