List of usage examples for org.joda.time Period Period
public Period(Object period, PeriodType type, Chronology chrono)
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java
License:Apache License
private Integer getPeriodsBetween(LocalDate fromDate, LocalDate toDate) { Integer numberOfPeriods = 0;/* www . j a v a2 s. c o 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.hendi.cekusia.Joda.java
public static void main(String[] args) { LocalDate birthdate = new LocalDate(1986, 9, 19); //Birth date LocalDate now = new LocalDate(); //Today's date Period period = new Period(birthdate, now, PeriodType.yearMonthDay()); //Now access the values as below System.out.println("Using Joda Time"); System.out.println("Usia : " + period.getYears() + " Tahun " + period.getMonths() + " Bulan " + period.getDays() + " Hari "); System.out.println();//from w w w . j a v a2 s . co m }
From source file:com.hmsinc.epicenter.model.health.Interaction.java
License:Open Source License
private int calculateAgeFromDOB(final DateTime dob) { int years = -1; if (dob != null) { Validate.isTrue(dob.isBefore(interactionDate), "Date of birth was in the future: " + dob.toString()); years = new Period(dob, interactionDate, PeriodType.years()).getYears(); }/*from ww w . ja v a 2 s . c o m*/ return years; }
From source file:com.hmsinc.epicenter.util.DateTimeUtils.java
License:Open Source License
/** * Gets a difference in days, taking into account the timezone and DST. * /* www. j av a2s . com*/ * @param start * @param end * @return */ public static int deltaDays(final ReadableInstant start, final ReadableInstant end) { return new Period(start, end, PeriodType.days()).getDays(); }
From source file:com.huang.rp.common.utils.TimeUtils.java
License:Apache License
/** * ? /*from w w w . j av a 2 s.c om*/ * @param dt1 * @param dt2 * @return */ public static int getDateDiff(DateTime dt1, DateTime dt2) { Period p = new Period(dt1, dt2, PeriodType.days()); return p.getDays(); }
From source file:com.metinkale.prayerapp.vakit.times.Times.java
License:Apache License
public String getLeft(int next, boolean showsecs) { LocalDateTime date = getTimeCal(null, next); Period period = new Period(LocalDateTime.now(), date, PeriodType.dayTime()); if (showsecs) { return Utils.toArabicNrs(PERIOD_FORMATTER_HMS.print(period)); } else if (Prefs.isDefaultWidgetMinuteType()) { return Utils.toArabicNrs(PERIOD_FORMATTER_HM.print(period)); } else {/*w w w . j av a 2 s . c om*/ period = period.withFieldAdded(DurationFieldType.minutes(), 1); return Utils.toArabicNrs(PERIOD_FORMATTER_HM.print(period)); } }
From source file:com.metinkale.prayerapp.vakit.times.Times.java
License:Apache License
public int getLeftMinutes(int which) { LocalDateTime date = getTimeCal(null, which); Period period = new Period(LocalDateTime.now(), date, PeriodType.minutes()); return period.getMinutes(); }
From source file:com.metinkale.prayerapp.vakit.times.Times.java
License:Apache License
public float getPassedPart() { int i = getNext(); LocalDateTime date1 = getTimeCal(null, i - 1); LocalDateTime date2 = getTimeCal(null, i); Period period = new Period(date1, date2, PeriodType.minutes()); float total = period.getMinutes(); float passed = total - getLeftMinutes(i); return passed / total; }
From source file:com.reclabs.recomendar.common.helpers.types.DateHelper.java
License:Open Source License
/** * Dada una fecha de referencia y una fecha a comparar obtenemos la diferencia de la primera con la segunda, el * formato depender del rango de la diferencia, es decir, si hay menos de * un mes de diferencia obtendremos la diferencia en das. * @param referenceDate The date of reference * @param compareDate The date to compare * @return Diferencia entre las fechas//from w w w. j a v a 2 s .c o m */ public static String getDifToCompareDateInUnitTimeLowRound(final Date referenceDate, final Date compareDate) { Period period = new Period(compareDate.getTime(), referenceDate.getTime(), PeriodType.yearMonthDayTime().withSecondsRemoved().withMillisRemoved()); if ((period.getYears() > 0) || (period.getMonths() > 0) || (period.getDays() > 0)) { return REDUCED_DATE_FORMAT.format(compareDate); } else if (period.getHours() > 0) { return period.getHours() + " Hora" + (period.getHours() > 1 ? "s" : ""); } else if (period.getMinutes() > 0) { return period.getMinutes() + " Minuto" + (period.getMinutes() > 1 ? "s" : ""); } else { return "Ahora"; } }
From source file:com.squid.kraken.v4.core.analysis.engine.processor.AnalysisCompute.java
License:Open Source License
private IntervalleObject alignPastInterval(IntervalleObject presentInterval, IntervalleObject pastInterval, Axis joinAxis) throws ScopeException { if (joinAxis != null && presentInterval != null && pastInterval != null) { Object lowerPresent = presentInterval.getLowerBound(); Object lowerPast = pastInterval.getLowerBound(); Object upperPresent = presentInterval.getUpperBound(); Object upperPast = pastInterval.getUpperBound(); ///*from w w w .j a v a2 s. c om*/ IDomain image = joinAxis.getDefinition().getImageDomain(); if (lowerPresent instanceof Date && lowerPast instanceof Date) { DateTime lowerPastDT = new DateTime((Date) lowerPast); DateTime lowerPresentDT = new DateTime((Date) lowerPresent); DateTime upperPresentDT = new DateTime((Date) upperPresent); DateTime upperPastDT = new DateTime((Date) upperPast); // realign if (image.isInstanceOf(IDomain.YEARLY)) { // check if present is an exact number of years if (lowerPresentDT.getDayOfYear() == 1 && upperPresentDT.getDayOfYear() == upperPresentDT.dayOfYear().getMaximumValue()) { // check of both periods have the same number of days Period presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)), PeriodType.days()); Period pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)), PeriodType.days()); if (presentPeriod.getDays() == pastPeriod.getDays()) { presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)).plusDays(1), PeriodType.years()); pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)).plusDays(1), PeriodType.years()); // realign if (presentPeriod.getYears() > pastPeriod.getYears()) { // some days are missing to align the periods if (lowerPastDT.getDayOfYear() != 1) { // previous period Date newLowerPast = new DateTime(upperPastDT.getYear(), 1, 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } if (upperPastDT.getDayOfYear() != upperPastDT.dayOfYear().getMaximumValue()) { // year over year Date newUpperPast = new DateTime(upperPastDT.getYear(), 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } } else { // either already aligned, or some days should // be removed if (upperPastDT.getDayOfYear() != upperPastDT.dayOfYear().getMaximumValue()) { // year over Year Date newUpperPast = new DateTime(upperPastDT.getYear() - 1, 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } if (lowerPastDT.getDayOfYear() != 1) { // previous period Date newLowerPast = new DateTime(lowerPastDT.getYear() + 1, 1, 1, 0, 0) .toDate(); return new IntervalleObject(newLowerPast, upperPast); } } } } } else if (image.isInstanceOf(IDomain.QUATERLY) || image.isInstanceOf(IDomain.MONTHLY)) { // check if present is an exact number of month if (lowerPresentDT.getDayOfMonth() == 1 && upperPresentDT.getDayOfMonth() == upperPresentDT.dayOfMonth().getMaximumValue()) { // check of both periods have the same number of days Period presentPeriod = new Period(new LocalDate(lowerPresent), new LocalDate(upperPresent), PeriodType.days()); Period pastPeriod = new Period(new LocalDate(lowerPast), new LocalDate(upperPast), PeriodType.days()); if (presentPeriod.getDays() == pastPeriod.getDays()) { // realign presentPeriod = new Period(new LocalDate(lowerPresent), (new LocalDate(upperPresent)).plusDays(1), PeriodType.months()); pastPeriod = new Period(new LocalDate(lowerPast), (new LocalDate(upperPast)).plusDays(1), PeriodType.months()); if (presentPeriod.getMonths() > pastPeriod.getMonths()) { // some days are missing if (upperPastDT.getDayOfMonth() != upperPastDT.dayOfMonth().getMaximumValue()) { // month over month Date newUpperPast = new DateTime(upperPastDT.getYear(), upperPastDT.getMonthOfYear(), upperPastDT.dayOfMonth().getMaximumValue(), 23, 59).toDate(); return new IntervalleObject(lowerPast, newUpperPast); } if (lowerPastDT.getDayOfMonth() != 1) { // previous period Date newLowerPast = new DateTime(lowerPastDT.getYear(), lowerPastDT.getMonthOfYear(), 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } } else { // either already aligned, of some days should // be removed if (upperPastDT.getDayOfMonth() != upperPastDT.dayOfMonth().getMaximumValue()) { /// month over month if (upperPastDT.getMonthOfYear() == 1) { Date newUpperPast = new DateTime(upperPastDT.getYear() - 1, 12, 31, 23, 59) .toDate(); return new IntervalleObject(lowerPast, newUpperPast); } else { upperPastDT = upperPastDT.minusMonths(1); Date newUpperPast = new DateTime(upperPastDT.getYear(), upperPastDT.getMonthOfYear(), upperPastDT.dayOfMonth().getMaximumValue(), 23, 59).toDate(); return new IntervalleObject(lowerPast, newUpperPast); } } if (lowerPastDT.getDayOfMonth() != 1) { // previous period if (lowerPastDT.getMonthOfYear() == 12) { Date newLowerPast = new DateTime(lowerPastDT.getYear() + 1, 1, 1, 0, 0) .toDate(); return new IntervalleObject(newLowerPast, upperPast); } else { lowerPastDT = lowerPastDT.plusMonths(1); Date newLowerPast = new DateTime(lowerPastDT.getYear(), lowerPastDT.getMonthOfYear(), 1, 0, 0).toDate(); return new IntervalleObject(newLowerPast, upperPast); } } } } } } } } return pastInterval; }