List of usage examples for org.joda.time Days ONE
Days ONE
To view the source code for org.joda.time Days ONE.
Click Source Link
From source file:com.mbc.jfin.daycount.impl.calculator.AFBActualActualDaycountCalculator.java
License:Open Source License
public double calculateDaycountFraction(SchedulePeriod period) { int daysBetween = DateUtils.daysBetween(period.getStart(), period.getEnd()); if (daysBetween == 0) return 0; LocalDate newD2 = period.getEnd(); LocalDate temp = period.getEnd(); double sum = 0.0; while (temp.isAfter(period.getStart())) { temp = newD2;//www.j a va 2 s . c o m temp = temp.minus(Years.ONE); if (temp.getDayOfMonth() == 28 && temp.getMonthOfYear() == 2 && DateUtils.isLeapYear(temp)) { temp = temp.plus(Days.ONE); } if (temp.isAfter(period.getStart()) || temp.equals(period.getStart())) { sum += 1.0; newD2 = temp; } } double den = 365.0; if (DateUtils.isLeapYear(newD2)) { temp = newD2; temp = new LocalDate(temp.getYear(), 2, 29); if (newD2.isAfter(temp) && (period.getStart().isBefore(temp) || period.getStart().equals(temp))) den += 1.0; } else if (DateUtils.isLeapYear(period.getStart())) { temp = new LocalDate(period.getStart().getYear(), 2, 29); if (newD2.isAfter(temp) && (period.getStart().isBefore(temp) || period.getStart().equals(temp))) den += 1.0; } return sum + DateUtils.daysBetween(period.getStart(), newD2) / den; }
From source file:com.mbc.jfin.holiday.impl.DefaultDateAdjustmentServiceImpl.java
License:Open Source License
public LocalDate following(LocalDate calendar, HolidayCalendar holidayCalendar) { LocalDate d1 = calendar;/*w w w . j a v a 2s . c o m*/ while (holidayCalendar.isHoliday(d1) || holidayCalendar.isWeekend(d1)) { d1 = d1.plus(Days.ONE); } return d1; }
From source file:com.mbc.jfin.holiday.impl.DefaultDateAdjustmentServiceImpl.java
License:Open Source License
public LocalDate modFollowing(LocalDate calendar, HolidayCalendar holidayCalendar) { LocalDate d1 = calendar;/*from w w w. j av a 2 s . c o m*/ while (holidayCalendar.isHoliday(d1) || holidayCalendar.isWeekend(d1)) { d1 = d1.plus(Days.ONE); } if (d1.getMonthOfYear() != calendar.getMonthOfYear()) { return preceding(calendar, holidayCalendar); } return d1; }
From source file:com.mbc.jfin.holiday.impl.DefaultDateAdjustmentServiceImpl.java
License:Open Source License
public LocalDate preceding(LocalDate calendar, HolidayCalendar holidayCalendar) { LocalDate d1 = calendar;/* w w w .j ava 2 s . c om*/ while (holidayCalendar.isHoliday(d1) || holidayCalendar.isWeekend(d1)) { d1 = d1.minus(Days.ONE); } return d1; }
From source file:com.mbc.jfin.holiday.impl.DefaultDateAdjustmentServiceImpl.java
License:Open Source License
public LocalDate modPreceding(LocalDate calendar, HolidayCalendar holidayCalendar) { LocalDate d1 = calendar;/*from w w w .j ava 2 s. c o m*/ while (holidayCalendar.isHoliday(d1) || holidayCalendar.isWeekend(d1)) { d1 = d1.minus(Days.ONE); } if (d1.getMonthOfYear() != calendar.getMonthOfYear()) { return following(calendar, holidayCalendar); } return d1; }
From source file:com.ning.metrics.serialization.util.DateTimeUtil.java
License:Apache License
public DateTime truncateToWeek(ReadableDateTime time) { MutableDateTime result = new MutableDateTime(time); result.setMillisOfSecond(0);/*from w w w. java 2 s . c o m*/ result.setSecondOfMinute(0); result.setMinuteOfHour(0); result.setHourOfDay(0); result.setHourOfDay(0); if (time.getDayOfWeek() != 7) { result.setDayOfWeek(1); result.add(Days.ONE.multipliedBy(-1)); } return new DateTime(result); }
From source file:controllers.api.DashboardsApiController.java
License:Open Source License
private Duration estimateIntervalStep(String interval) { Duration step;//from w ww .j a va2 s.c o m switch (interval) { case "minute": step = Minutes.ONE.toStandardDuration(); break; case "hour": step = Hours.ONE.toStandardDuration(); break; case "day": step = Days.ONE.toStandardDuration(); break; case "week": step = Weeks.ONE.toStandardDuration(); break; case "month": step = Days.days(31).toStandardDuration(); break; case "quarter": step = Days.days(31 * 3).toStandardDuration(); break; case "year": step = Days.days(365).toStandardDuration(); break; default: throw new IllegalArgumentException("Invalid duration specified: " + interval); } return step; }
From source file:economy.EconomicCycle.java
License:Open Source License
public void init(boolean testing) { addEvent(new Recordable.PollRecordables(), getStart(), Days.ONE); addEvent(new TransientNumber.RefreshTransients(), getStart(), Days.ONE); addEvent(new PayBankDividend(economy), getStart(), Days.ONE); addEvent(new PayFirmDividends(economy), getStart(), Days.ONE); addEvent(new RunMarket(economy.getLaborMarket()), getStart(), Days.ONE); addEvent(new RunProduction(economy), getStart(), Days.ONE);// TODO: not // clear// ww w . j a v a2 s . c o m // if this goes here addEvent(new RunMarket(economy.getGoodsMarket()), getStart(), Days.ONE); addEvent(new UpdateHouseholds(economy), getStart(), Days.ONE); addEvent(new RunDebtRecovery(economy), getStart(), Days.ONE); addEvent(new UpdateProductiveSector(economy), getStart(), Days.ONE); addEvent(new UpdateBank(economy), getStart(), Days.ONE); addEvent(new CreditCheques(economy), getStart(), Days.ONE);// TODO: // dunno // where this // goes exactly }
From source file:energy.usef.agr.workflow.altstep.AgrFlexOfferDetermineFlexibilityStubOffer.java
License:Apache License
@SuppressWarnings("unchecked") @Override// ww w.j a v a2 s . com public WorkflowContext invoke(WorkflowContext context) { LOGGER.debug("Received context parameters: {}", context); LocalDate period = context.get(FlexOfferDetermineFlexibilityStepParameter.IN.PERIOD.name(), LocalDate.class); Integer ptuDuration = context.get(FlexOfferDetermineFlexibilityStepParameter.IN.PTU_DURATION.name(), Integer.class); List<FlexRequestDto> inputFlexRequests = context .get(FlexOfferDetermineFlexibilityStepParameter.IN.FLEX_REQUEST_DTO_LIST.name(), List.class); List<FlexOfferDto> existingFlexOffers = context .get(FlexOfferDetermineFlexibilityStepParameter.IN.FLEX_OFFER_DTO_LIST.name(), List.class); // build maps of: ConnectionGroup > List<ConnectionDto> Map<String, List<ConnectionPortfolioDto>> connectionPortfolioDtoMap = buildConnectionDtoPerConnectionGroup( context); // retrieve map of flexible potential per congestion point Map<String, Map<Integer, Map<ConsumptionProductionTypeDto, BigInteger>>> potentialFlexPerConnectionGroupPerPtu = fetchPotentialFlex( connectionPortfolioDtoMap, period, ptuDuration); Map<String, Map<Integer, Map<ConsumptionProductionTypeDto, BigInteger>>> offeredFlexPerConnectionGroupPerPtu = fetchAlreadyOfferedFlex( existingFlexOffers); LocalDateTime now = DateTimeUtil.getCurrentDateTime(); // retrieve APX prices from the pbc feeder final int ptusPerDay = Days.ONE.toStandardMinutes().getMinutes() / context.get(FlexOfferDetermineFlexibilityStepParameter.IN.PTU_DURATION.name(), Integer.class); Map<Integer, BigDecimal> apxPrices = pbcFeederService.retrieveApxPrices(period, 1, ptusPerDay); List<FlexOfferDto> outputFlexOffers = new ArrayList<>(); for (FlexRequestDto flexRequestDto : inputFlexRequests) { boolean congestionPointContext = isFlexRequestForCongestionPoint(flexRequestDto); String connectionGroup = flexRequestDto.getConnectionGroupEntityAddress(); // possibleFlex = potentialFlex - offered_flex Map<Integer, Map<ConsumptionProductionTypeDto, BigInteger>> possibleFlexPerPtu = fetchPossibleFlex( potentialFlexPerConnectionGroupPerPtu.get(connectionGroup), offeredFlexPerConnectionGroupPerPtu.getOrDefault(connectionGroup, new HashMap<>())); // create new flex offer FlexOfferDto flexOfferDto = new FlexOfferDto(); flexOfferDto.setFlexRequestSequenceNumber(flexRequestDto.getSequenceNumber()); flexOfferDto.setPeriod(flexRequestDto.getPeriod()); flexOfferDto.setConnectionGroupEntityAddress(flexRequestDto.getConnectionGroupEntityAddress()); flexOfferDto.setParticipantDomain(flexRequestDto.getParticipantDomain()); flexOfferDto.setExpirationDateTime(now.plusDays(FLEX_OFFER_EXPIRATION_DAYS).withTime(0, 0, 0, 0)); // for each ptu of the flex request for (PtuFlexRequestDto ptu : flexRequestDto.getPtus()) { BigInteger maxPotentialFlex; BigDecimal price; if (ptu.getDisposition() == DispositionTypeDto.AVAILABLE) { maxPotentialFlex = ZERO; price = BigDecimal.ZERO; } else { maxPotentialFlex = determineMaxPotentialFlex(possibleFlexPerPtu, ptu); price = determinePrice(possibleFlexPerPtu, apxPrices, ptu, congestionPointContext, ptuDuration); } PtuFlexOfferDto ptuFlexOfferDto = new PtuFlexOfferDto(); ptuFlexOfferDto.setPower(maxPotentialFlex); ptuFlexOfferDto.setPrice(price.setScale(PRECISION_OF_PRICE, RoundingMode.HALF_UP)); ptuFlexOfferDto.setPtuIndex(ptu.getPtuIndex()); LOGGER.trace("{} added to {}.", ptuFlexOfferDto, flexOfferDto); flexOfferDto.getPtus().add(ptuFlexOfferDto); } outputFlexOffers.add(flexOfferDto); } context.setValue(FlexOfferDetermineFlexibilityStepParameter.OUT.FLEX_OFFER_DTO_LIST.name(), outputFlexOffers); return context; }
From source file:energy.usef.core.event.DayAheadClosureEvent.java
License:Apache License
/** * Default constructor. Set the period of closure to <code>TODAY+1</code>. *///from w ww. j a v a2 s . c om public DayAheadClosureEvent() { this.period = DateTimeUtil.getCurrentDate().plus(Days.ONE); }