List of usage examples for org.joda.time Period getMonths
public int getMonths()
From source file:it.f2informatica.webapp.utils.PeriodParser.java
License:Apache License
private String appendMonths(Period period) { int months = period.getMonths(); if (months <= 0) { return appendDays(period); }/*www.j a v a 2 s .com*/ return String.valueOf(months) + " " + ((months == 1) ? getMessage("global.month") : getMessage("global.months")); }
From source file:net.longfalcon.view.DateView.java
License:Open Source License
public Period roundPeriod(Period period) { int fieldCount = 0; int years = period.getYears(); int months = period.getMonths(); int weeks = period.getWeeks(); int days = period.getDays(); int hours = period.getHours(); int minutes = period.getMinutes(); int seconds = period.getSeconds(); if (years > 0) { fieldCount++;/*from www . j ava2 s . c o m*/ } if (months > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(years, months, 0, 0, 0, 0, 0, 0); } if (weeks > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(0, months, weeks, 0, 0, 0, 0, 0); } if (days > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(0, 0, weeks, days, 0, 0, 0, 0); } if (hours > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(0, 0, 0, days, hours, 0, 0, 0); } if (minutes > 0) { fieldCount++; } if (fieldCount > 1) { return new Period(0, 0, 0, 0, hours, minutes, 0, 0); } return new Period(0, 0, 0, 0, 0, minutes, seconds, 0); }
From source file:net.sourceforge.fenixedu.domain.GratuitySituation.java
License:Open Source License
private int calculateMonthsToChargePenalty(final YearMonthDay when) { final YearMonthDay endPaymentDate = getEndPaymentDate(); final YearMonthDay endOfMonth = endPaymentDate.plusMonths(1).withDayOfMonth(1).minusDays(1); final int numberOfDaysLeftInMonth = new Period(endPaymentDate, endOfMonth).getDays(); int monthsToChargePenalty = 0; if (numberOfDaysLeftInMonth > 0) { monthsToChargePenalty += 1;//from w ww . ja va2 s . co m } final Period period = new Period(endPaymentDate.plusMonths(1).withDayOfMonth(1), when); monthsToChargePenalty += period.getMonths() + 1; return monthsToChargePenalty; }
From source file:nz.co.gregs.dbvolution.databases.definitions.DBDefinition.java
License:Apache License
/** * Creates a string representation of a DateRepeat from the Period * * @param interval the interval to be transformed into a DateRepeat. * @return a DateRpeat as an SQL string//www . j a v a 2 s .c o m */ public String transformPeriodIntoDateRepeat(Period interval) { StringBuilder str = new StringBuilder(); str.append("'").append(DateRepeatExpression.INTERVAL_PREFIX); str.append(interval.getYears()).append(DateRepeatExpression.YEAR_SUFFIX); str.append(interval.getMonths()).append(DateRepeatExpression.MONTH_SUFFIX); str.append(interval.getDays() + (interval.getWeeks() * 7)).append(DateRepeatExpression.DAY_SUFFIX); str.append(interval.getHours()).append(DateRepeatExpression.HOUR_SUFFIX); str.append(interval.getMinutes()).append(DateRepeatExpression.MINUTE_SUFFIX); str.append(interval.getSeconds()).append(DateRepeatExpression.SECOND_SUFFIX); str.append("'"); return str.toString(); }
From source file:nz.co.gregs.dbvolution.internal.datatypes.DateRepeatImpl.java
License:Apache License
/** * * @param interval/*from www . j a va 2s .c o m*/ * @return the DateRepeat equivalent of the Period value */ public static String getDateRepeatString(Period interval) { if (interval == null) { return null; } int years = interval.getYears(); int months = interval.getMonths(); int days = interval.getDays() + interval.getWeeks() * 7; int hours = interval.getHours(); int minutes = interval.getMinutes(); int millis = interval.getMillis(); double seconds = interval.getSeconds() + (millis / 1000.0); String intervalString = "P" + years + "Y" + months + "M" + days + "D" + hours + "h" + minutes + "n" + seconds + "s"; return intervalString; }
From source file:org.apache.arrow.vector.util.DateUtility.java
License:Apache License
public static int monthsFromPeriod(Period period) { return (period.getYears() * yearsToMonths) + period.getMonths(); }
From source file:org.apache.drill.exec.vector.DateUtilities.java
License:Apache License
public static int periodToMonths(Period value) { return value.getYears() * yearsToMonths + value.getMonths(); }
From source file:org.apache.drill.exec.vector.DateUtilities.java
License:Apache License
public static StringBuilder intervalYearStringBuilder(Period value) { return intervalYearStringBuilder(value.getYears() * 12 + value.getMonths()); }
From source file:org.apache.drill.exec.vector.DateUtilities.java
License:Apache License
public static StringBuilder intervalStringBuilder(Period value) { return intervalStringBuilder(value.getYears() * 12 + value.getMonths(), value.getDays(), periodToMillis(value));/*from ww w.ja v a 2 s . c om*/ }
From source file:org.apigw.authserver.svc.impl.TokenServicesImpl.java
License:Open Source License
/** * @param residentIdentificationNumber in format yyyyMMddnnnn- for example 199212319876 * @param validitySeconds - for example 43200 (60 * 60 * 12) - 12 hours in the future * @return//from w w w . ja v a 2 s . c o m */ protected Date generateExpirationTime(String residentIdentificationNumber, long validitySeconds) { if (residentIdentificationNumber == null || residentIdentificationNumber.length() < 8) { throw new IllegalArgumentException( "Invalid residentIdentificationNumber " + residentIdentificationNumber); } long validityMilliseconds = validitySeconds * 1000L; final String birthdayString = residentIdentificationNumber.substring(0, 8); final DateTime birthDate = DateTime.parse(birthdayString, ISODateTimeFormat.basicDate()); Period period = new Period(birthDate, new DateTime(), PeriodType.yearMonthDay()); DateTime birthDatePlusLegalGuardianAgeLimit = birthDate.plusYears(legalGuardianAgeLimit); DateTime residentAdultDate = birthDate.plusYears(adultAge); DateTime expiration = new DateTime().withTimeAtStartOfDay(); //defaulting to midnight of today (token will be immediately invalid) if (validitySeconds > 0) { // Standard expiration final DateTime standardExpiration = new DateTime().plus(validityMilliseconds); if (birthDatePlusLegalGuardianAgeLimit.isAfter(now().plus(validityMilliseconds))) { // resident will hit the legal guardian age after max token validity expiration = standardExpiration; } else if (residentAdultDate.isBeforeNow()) { // resident is considered adult expiration = standardExpiration; } else if (birthDatePlusLegalGuardianAgeLimit.isAfterNow()) { //resident will hit the legal guardian age before max token validity expiration = birthDatePlusLegalGuardianAgeLimit; } // if we get here resident has passed legal guardian age but is not considered adult, using default } log.debug("calculated token exp time for resident who is ~ {} years, {} months and {} days old to {}", period.getYears(), period.getMonths(), period.getDays(), expiration); return expiration.toDate(); }