List of usage examples for org.joda.time Period getMonths
public int getMonths()
From source file:beans.utilidades.MetodosGenerales.java
public String calcularEdad(Date fechaNacimiento) {//calcular la edad a partir de la fecha de nacimiento Period periodo = new Period(new DateTime(fechaNacimiento), new DateTime(new Date())); return String.valueOf(periodo.getYears()) + "A " + String.valueOf(periodo.getMonths()) + "M "; }
From source file:br.edu.utfpr.cm.JGitMinerWeb.services.matrix.AgeRepositoryServices.java
@Override public void run() { System.out.println(params);//from ww w . j a v a 2s . c o m if (getRepositorys().get(0) == null) { throw new IllegalArgumentException("Parmetro Repository no pode ser nulo."); } String jpql = "SELECT r " + "FROM " + "EntityRepository r " + "WHERE " + "r = :repo"; String[] bdParams = new String[] { "repo" }; Object[] bdObjects = new Object[] { getRepositorys().get(0) }; List<EntityRepository> repository = dao.selectWithParams(jpql, bdParams, bdObjects); System.out.println(repository.size()); System.out.println(repository); EntityMatrix matrix = new EntityMatrix(); for (EntityRepository r : repository) { DateTime dateRepository = new DateTime(r.getCreatedAt()); Period period = new Period(dateRepository, new DateTime(), PeriodType.months().withDaysRemoved()); matrix.getNodes().add(new EntityMatrixNode(period.getMonths())); } matricesToSave.add(matrix); }
From source file:br.edu.utfpr.cm.JGitMinerWeb.services.matrix.FiltersServices.java
private int findAgeRepository(EntityRepository repository) { DateTime dateRepository = new DateTime(repository.getCreatedAt()); Period period = new Period(dateRepository, new DateTime(), PeriodType.months().withDaysRemoved()); return period.getMonths(); }
From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java
License:Open Source License
/** * copy participant info/* w ww. ja v a 2s .co m*/ */ private ParticipantType copyParticipant(ObjectFactory factory, Participant part) { final ParticipantType retVal = factory.createParticipantType(); if (part.getId() != null) retVal.setId(part.getId()); retVal.setName(part.getName()); final DateTime bday = part.getBirthDate(); if (bday != null) { try { final DatatypeFactory df = DatatypeFactory.newInstance(); final XMLGregorianCalendar cal = df.newXMLGregorianCalendar(bday.toGregorianCalendar()); cal.setTimezone(DatatypeConstants.FIELD_UNDEFINED); retVal.setBirthday(cal); } catch (DatatypeConfigurationException e) { LOGGER.log(Level.WARNING, e.toString(), e); } } final Period age = part.getAge(null); if (age != null) { try { final DatatypeFactory df = DatatypeFactory.newInstance(); final Duration ageDuration = df.newDuration(true, age.getYears(), age.getMonths(), age.getDays(), 0, 0, 0); retVal.setAge(ageDuration); } catch (DatatypeConfigurationException e) { LOGGER.log(Level.WARNING, e.toString(), e); } } retVal.setEducation(part.getEducation()); retVal.setGroup(part.getGroup()); final String lang = part.getLanguage(); final String langs[] = (lang != null ? lang.split(",") : new String[0]); for (String l : langs) { retVal.getLanguage().add(StringUtils.strip(l)); } if (part.getSex() == Sex.MALE) retVal.setSex(SexType.MALE); else if (part.getSex() == Sex.FEMALE) retVal.setSex(SexType.FEMALE); ParticipantRole prole = part.getRole(); if (prole == null) prole = ParticipantRole.TARGET_CHILD; retVal.setRole(prole.toString()); // create ID based on role if possible if (retVal.getId() == null && prole != null) { if (prole == ParticipantRole.TARGET_CHILD) { retVal.setId("CHI"); } else if (prole == ParticipantRole.MOTHER) { retVal.setId("MOT"); } else if (prole == ParticipantRole.FATHER) { retVal.setId("FAT"); } else if (prole == ParticipantRole.INTERVIEWER) { retVal.setId("INT"); } else { retVal.setId("p" + (++pIdx)); } } retVal.setSES(part.getSES()); return retVal; }
From source file:co.edu.uelbosque.sistemas.swiii.c3.historiaclinica.entities.Medico.java
private void setNacimiento(Calendar nacimiento) { Calendar ahora = Calendar.getInstance(); long hoy = ahora.getTimeInMillis(); long dias = hoy - nacimiento.getTimeInMillis(); Duration d = new Duration(dias); this.dias = (int) d.getStandardDays(); Period period = new Period(nacimiento.getTimeInMillis(), hoy, PeriodType.months()); this.meses = period.getMonths(); this.nacimiento = nacimiento; }
From source file:com.alta189.cyborg.commandkit.twitter.TwitterCommands.java
License:Open Source License
@Command(name = "twitter", desc = "displays the last tweet of a twitter user", aliases = { "twit" }) @Usage(".twitter <user>") public CommandResult twitter(CommandSource source, CommandContext context) { if (source.getSource() == CommandSource.Source.USER && (context.getPrefix() == null || !context.getPrefix().equals("."))) { return null; }/* w w w .j a v a 2 s . c o m*/ if (context.getArgs() == null || context.getArgs().length < 1) { return get(ReturnType.NOTICE, "Correct usage is .twitter <user>", source, context); } try { List<Status> statusList = twitter.getUserTimeline(context.getArgs()[0]); if (statusList == null || statusList.size() < 1) { return get(ReturnType.MESSAGE, "User has no tweets!", source, context); } Status status = statusList.get(0); status.getUser(); StringBuilder builder = new StringBuilder(); builder.append(status.getUser().getScreenName()).append(Colors.BLUE).append(": ").append(Colors.NORMAL) .append(status.getText()).append(" ("); Period period = new Period(new DateTime(status.getCreatedAt()), new DateTime()); if (period.getWeeks() > 2 || period.getMonths() > 1 || period.getYears() > 1) { builder.append(longTimeFormatter.print(period)); } else { builder.append(timeFormatter.print(period)); } builder.append(" ago)"); return get(ReturnType.MESSAGE, builder.toString().replace(lineBreak, " "), source, context); } catch (TwitterException e) { if (e.getStatusCode() == 404) { return get(ReturnType.MESSAGE, "User not found!", source, context); } else if (e.getStatusCode() == 401) { return get(ReturnType.MESSAGE, "Access denied by Twitter!", source, context); } else { e.printStackTrace(); return get(ReturnType.MESSAGE, "There was an internal error!", source, context); } } }
From source file:com.github.jobs.utils.RelativeDate.java
License:Apache License
/** * This method returns a String representing the relative * date by comparing the Calendar being passed in to the * date / time that it is right now./*from w w w .j a va2 s .c o m*/ * * @param context used to build the string response * @param time time to compare with current time * @return a string representing the time ago */ public static String getTimeAgo(Context context, long time) { DateTime baseDate = new DateTime(time); DateTime now = new DateTime(); Period period = new Period(baseDate, now); if (period.getSeconds() < 0 || period.getMinutes() < 0) { return context.getString(R.string.just_now); } if (period.getYears() > 0) { int resId = period.getYears() == 1 ? R.string.one_year_ago : R.string.years_ago; return buildString(context, resId, period.getYears()); } if (period.getMonths() > 0) { int resId = period.getMonths() == 1 ? R.string.one_month_ago : R.string.months_ago; return buildString(context, resId, period.getMonths()); } if (period.getWeeks() > 0) { int resId = period.getWeeks() == 1 ? R.string.one_week_ago : R.string.weeks_ago; return buildString(context, resId, period.getWeeks()); } if (period.getDays() > 0) { int resId = period.getDays() == 1 ? R.string.one_day_ago : R.string.days_ago; return buildString(context, resId, period.getDays()); } if (period.getHours() > 0) { int resId = period.getHours() == 1 ? R.string.one_hour_ago : R.string.hours_ago; return buildString(context, resId, period.getHours()); } if (period.getMinutes() > 0) { int resId = period.getMinutes() == 1 ? R.string.one_minute_ago : R.string.minutes_ago; return buildString(context, resId, period.getMinutes()); } int resId = period.getSeconds() == 1 ? R.string.one_second_ago : R.string.seconds_ago; return buildString(context, resId, period.getSeconds()); }
From source file:com.google.livingstories.server.util.TimeUtil.java
License:Apache License
/** * Return a String representation of the time that has passed from the given time to * right now./*from ww w .j a v a 2 s.c o m*/ * This method returns an approximate user-friendly duration. Eg. If 2 months, 12 days and 4 hours * have passed, the method will return "2 months ago". * TODO: the results of this method need to be internationalized */ public static String getElapsedTimeString(Date updateCreationTime) { Period period = new Period(updateCreationTime.getTime(), new Date().getTime(), PeriodType.yearMonthDayTime()); int years = period.getYears(); int months = period.getMonths(); int days = period.getDays(); int hours = period.getHours(); int minutes = period.getMinutes(); int seconds = period.getSeconds(); String timeLabel = ""; if (years > 0) { timeLabel = years == 1 ? " year " : " years "; return "" + years + timeLabel + "ago"; } else if (months > 0) { timeLabel = months == 1 ? " month " : " months "; return "" + months + timeLabel + "ago"; } else if (days > 0) { timeLabel = days == 1 ? " day " : " days "; return "" + days + timeLabel + "ago"; } else if (hours > 0) { timeLabel = hours == 1 ? " hour " : " hours "; return "" + hours + timeLabel + "ago"; } else if (minutes > 0) { timeLabel = minutes == 1 ? " minute " : " minutes "; return "" + minutes + timeLabel + "ago"; } else if (seconds > 0) { timeLabel = seconds == 1 ? " second " : " seconds "; return "" + seconds + timeLabel + "ago"; } else { return "1 second ago"; } }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java
License:Apache License
private Integer getPeriodsBetween(LocalDate fromDate, LocalDate toDate) { Integer numberOfPeriods = 0;//from w w w. j ava 2s . 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();// w w w . j a v a2s .c o m }