List of usage examples for org.joda.time PeriodType weeks
public static PeriodType weeks()
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java
License:Apache License
private Integer getPeriodsBetween(LocalDate fromDate, LocalDate toDate) { Integer numberOfPeriods = 0;/* w ww . j av a 2s .co m*/ PeriodType periodType = PeriodType.yearMonthDay(); Period difference = new Period(fromDate, toDate, periodType); switch (this.repaymentPeriodFrequencyType) { case DAYS: numberOfPeriods = difference.getDays(); break; case WEEKS: periodType = PeriodType.weeks(); difference = new Period(fromDate, toDate, periodType); numberOfPeriods = difference.getWeeks(); break; case MONTHS: numberOfPeriods = difference.getMonths(); break; case YEARS: numberOfPeriods = difference.getYears(); break; default: break; } return numberOfPeriods; }
From source file:com.netflix.ice.basic.BasicDataManager.java
License:Apache License
private double[] getData(Interval interval, TagLists tagLists) throws ExecutionException { DateTime start = config.startDate;// w ww. j a v a 2 s . c om DateTime end = config.startDate; if (consolidateType == ConsolidateType.hourly) { start = interval.getStart().withDayOfMonth(1).withMillisOfDay(0); end = interval.getEnd(); } else if (consolidateType == ConsolidateType.daily) { start = interval.getStart().withDayOfYear(1).withMillisOfDay(0); end = interval.getEnd(); } int num = 0; if (consolidateType == ConsolidateType.hourly) { num = interval.toPeriod(PeriodType.hours()).getHours(); if (interval.getStart().plusHours(num).isBefore(interval.getEnd())) num++; } else if (consolidateType == ConsolidateType.daily) { num = interval.toPeriod(PeriodType.days()).getDays(); if (interval.getStart().plusDays(num).isBefore(interval.getEnd())) num++; } else if (consolidateType == ConsolidateType.weekly) { num = interval.toPeriod(PeriodType.weeks()).getWeeks(); if (interval.getStart().plusWeeks(num).isBefore(interval.getEnd())) num++; } else if (consolidateType == ConsolidateType.monthly) { num = interval.toPeriod(PeriodType.months()).getMonths(); if (interval.getStart().plusMonths(num).isBefore(interval.getEnd())) num++; } double[] result = new double[num]; do { ReadOnlyData data = getReadOnlyData(start); int resultIndex = 0; int fromIndex = 0; if (interval.getStart().isBefore(start)) { if (consolidateType == ConsolidateType.hourly) { resultIndex = Hours.hoursBetween(interval.getStart(), start).getHours(); } else if (consolidateType == ConsolidateType.daily) { resultIndex = Days.daysBetween(interval.getStart(), start).getDays(); } else if (consolidateType == ConsolidateType.weekly) { resultIndex = Weeks.weeksBetween(interval.getStart(), start).getWeeks(); } else if (consolidateType == ConsolidateType.monthly) { resultIndex = Months.monthsBetween(interval.getStart(), start).getMonths(); } } else { if (consolidateType == ConsolidateType.hourly) { fromIndex = Hours.hoursBetween(start, interval.getStart()).getHours(); } else if (consolidateType == ConsolidateType.daily) { fromIndex = Days.daysBetween(start, interval.getStart()).getDays(); } else if (consolidateType == ConsolidateType.weekly) { fromIndex = Weeks.weeksBetween(start, interval.getStart()).getWeeks(); if (start.getDayOfWeek() != interval.getStart().getDayOfWeek()) fromIndex++; } else if (consolidateType == ConsolidateType.monthly) { fromIndex = Months.monthsBetween(start, interval.getStart()).getMonths(); } } List<Integer> columeIndexs = Lists.newArrayList(); int columeIndex = 0; for (TagGroup tagGroup : data.getTagGroups()) { if (tagLists.contains(tagGroup)) columeIndexs.add(columeIndex); columeIndex++; } while (resultIndex < num && fromIndex < data.getNum()) { double[] fromData = data.getData(fromIndex++); for (Integer cIndex : columeIndexs) result[resultIndex] += fromData[cIndex]; resultIndex++; } if (consolidateType == ConsolidateType.hourly) start = start.plusMonths(1); else if (consolidateType == ConsolidateType.daily) start = start.plusYears(1); else break; } while (start.isBefore(end)); return result; }
From source file:com.squid.kraken.v4.core.analysis.engine.processor.AnalysisCompute.java
License:Open Source License
private PeriodType computePeriodType(IDomain image) { if (image.isInstanceOf(IDomain.YEARLY)) { return PeriodType.years(); } else if (image.isInstanceOf(IDomain.QUATERLY)) { return PeriodType.months(); } else if (image.isInstanceOf(IDomain.MONTHLY)) { return PeriodType.months(); } else if (image.isInstanceOf(IDomain.WEEKLY)) { return PeriodType.weeks(); } else {/*from w w w . ja va2 s .c o m*/ return PeriodType.days(); } }
From source file:net.sourceforge.fenixedu.domain.Attends.java
License:Open Source License
public int calculateCurrentWeekOffset() { final DateMidnight beginningOfLessonPeriod = new DateMidnight(getBegginingOfLessonPeriod()); final DateMidnight firstMonday = beginningOfLessonPeriod.withField(DateTimeFieldType.dayOfWeek(), 1); final DateMidnight thisMonday = new DateMidnight().withField(DateTimeFieldType.dayOfWeek(), 1); final Interval interval = new Interval(firstMonday, thisMonday); return interval.toPeriod(PeriodType.weeks()).getWeeks(); }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnPeriodMapper.java
License:Apache License
private PeriodType determinePeriodType(String s) { PeriodType periodType = PeriodType.standard(); String current = s;/*from www. j a va 2s. c o m*/ if (current.startsWith(PeriodType.standard().getName())) { periodType = PeriodType.standard(); current = s.substring(PeriodType.standard().getName().length()); } else if (current.startsWith(PeriodType.yearMonthDayTime().getName())) { periodType = PeriodType.yearMonthDayTime(); current = s.substring(PeriodType.yearMonthDayTime().getName().length()); } else if (current.startsWith(PeriodType.yearMonthDay().getName())) { periodType = PeriodType.yearMonthDay(); current = s.substring(PeriodType.yearMonthDay().getName().length()); } else if (current.startsWith(PeriodType.yearWeekDayTime().getName())) { periodType = PeriodType.yearWeekDayTime(); current = s.substring(PeriodType.yearWeekDayTime().getName().length()); } else if (current.startsWith(PeriodType.yearWeekDay().getName())) { periodType = PeriodType.yearWeekDay(); current = s.substring(PeriodType.yearWeekDay().getName().length()); } else if (current.startsWith(PeriodType.yearDayTime().getName())) { periodType = PeriodType.yearDayTime(); current = s.substring(PeriodType.yearDayTime().getName().length()); } else if (current.startsWith(PeriodType.yearDay().getName())) { periodType = PeriodType.yearDay(); current = s.substring(PeriodType.yearDay().getName().length()); } else if (current.startsWith(PeriodType.dayTime().getName())) { periodType = PeriodType.dayTime(); current = s.substring(PeriodType.dayTime().getName().length()); } else if (current.startsWith(PeriodType.time().getName())) { periodType = PeriodType.time(); current = s.substring(PeriodType.time().getName().length()); } else if (current.startsWith(PeriodType.years().getName())) { periodType = PeriodType.years(); current = s.substring(PeriodType.years().getName().length()); } else if (current.startsWith(PeriodType.months().getName())) { periodType = PeriodType.months(); current = s.substring(PeriodType.months().getName().length()); } else if (current.startsWith(PeriodType.weeks().getName())) { periodType = PeriodType.weeks(); current = s.substring(PeriodType.weeks().getName().length()); } else if (current.startsWith(PeriodType.days().getName())) { periodType = PeriodType.days(); current = s.substring(PeriodType.days().getName().length()); } else if (current.startsWith(PeriodType.hours().getName())) { periodType = PeriodType.hours(); current = s.substring(PeriodType.hours().getName().length()); } else if (current.startsWith(PeriodType.minutes().getName())) { periodType = PeriodType.minutes(); current = s.substring(PeriodType.minutes().getName().length()); } else if (current.startsWith(PeriodType.seconds().getName())) { periodType = PeriodType.seconds(); current = s.substring(PeriodType.seconds().getName().length()); } else if (current.startsWith(PeriodType.millis().getName())) { periodType = PeriodType.millis(); current = s.substring(PeriodType.millis().getName().length()); } while (current.length() > 0) { if (current.startsWith("NoYears")) { periodType = periodType.withYearsRemoved(); current = s.substring("NoYears".length()); } else if (current.startsWith("NoMonths")) { periodType = periodType.withMonthsRemoved(); current = s.substring("NoMonths".length()); } else if (current.startsWith("NoWeeks")) { periodType = periodType.withWeeksRemoved(); current = s.substring("NoWeeks".length()); } else if (current.startsWith("NoDays")) { periodType = periodType.withDaysRemoved(); current = s.substring("NoDays".length()); } else if (current.startsWith("NoHours")) { periodType = periodType.withHoursRemoved(); current = s.substring("NoHours".length()); } else if (current.startsWith("NoMinutes")) { periodType = periodType.withMinutesRemoved(); current = s.substring("NoMinutes".length()); } else if (current.startsWith("NoSeconds")) { periodType = periodType.withSecondsRemoved(); current = s.substring("NoSeconds".length()); } else if (current.startsWith("NoMillis")) { periodType = periodType.withMillisRemoved(); current = s.substring("NoMillis".length()); } else { throw new IllegalArgumentException("Unrecognised PeriodType: " + s + "{" + current + "}"); } } return periodType; }