List of usage examples for org.joda.time Period getDays
public int getDays()
From source file:app.sunstreak.yourpisd.util.DateHelper.java
License:Open Source License
public static String timeSince(DateTime dt) { StringBuilder sb = new StringBuilder(); sb.append("Last updated "); Period pd = new Interval(dt.getMillis(), Instant.now().getMillis()).toPeriod(); if (pd.getDays() > 0) { sb.append(pd.getDays());// w w w . j a v a2 s.co m return sb.append(" days ago").toString(); } if (pd.getHours() > 0) sb.append(pd.getHours() + "hours "); if (pd.getMinutes() > 0) { sb.append(pd.getMinutes() + " minutes"); return sb.append(" ago").toString(); } return sb.append("less than a minute ago").toString(); }
From source file:br.com.bob.dashboard.model.Metric.java
public String getInactiveTime() { final DateTime old = new DateTime(date); final DateTime now = new DateTime(); final Period period = new Period(old, now); int interval; if ((interval = period.getDays()) > 0) return getText(interval, "dia(s)"); else if ((interval = period.getHours()) > 0) return getText(interval, "hora(s)"); else if ((interval = period.getMinutes()) > 0) return getText(interval, "minuto(s)"); else//ww w . ja v a 2 s. c o m return "h pouco"; }
From source file:br.com.registro.view.TelaHoras.java
private void jButtonConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfirmarActionPerformed // TODO add your handling code here: ControleDAO dao = new ControleDAO(); Controle control = new Controle(); HoraUtil util = new HoraUtil(); SimpleDateFormat data = new SimpleDateFormat("dd/MM/yyyy"); Date date = new Date(); String d = data.format(date); int indiceLinha = jTable1.getSelectedRow(); if (jComboBoxFuncionario.getSelectedItem().equals("Selecione um funciorio") || jFormattedTextFieldHoraEntrada.getText().isEmpty() || jFormattedTextFieldHoraSaida.getText().isEmpty() || jFormattedTextFieldData.getText().isEmpty()) { JOptionPane.showMessageDialog(null, "Campos obrigatrios vazios", "Ateno", JOptionPane.INFORMATION_MESSAGE); } else if (jFormattedTextFieldData.getText().equals(d)) { JOptionPane.showMessageDialog(null, "Funcionrio j registrou ponto nesta data", "Ateno", JOptionPane.ERROR_MESSAGE); jButtonAdicionar.setEnabled(true); jButtonConfirmar.setEnabled(false); jButtonCancelar.setEnabled(false); jButtonAtualizar.setEnabled(false); jButtonExcluir.setEnabled(false); jComboBoxFuncionario.setEnabled(false); jFormattedTextFieldHoraEntrada.setEnabled(false); jFormattedTextFieldHoraSaida.setEnabled(false); jFormattedTextFieldHoraExtra.setEnabled(false); jFormattedTextFieldData.setEnabled(false); jTextAreaDescricao.setEnabled(false); jComboBoxFuncionario.setSelectedItem("Selecione um funcionrio"); jFormattedTextFieldHoraEntrada.setText(""); jFormattedTextFieldHoraSaida.setText(""); jFormattedTextFieldHoraExtra.setText(""); jFormattedTextFieldData.setText(""); jTextAreaDescricao.setText(""); } else {//from w ww . j ava 2 s. c o m SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Date dataInicial = null; Date dataFinal = null; try { dataInicial = format .parse(jFormattedTextFieldData.getText() + " " + jFormattedTextFieldHoraEntrada.getText()); dataFinal = format .parse(jFormattedTextFieldData.getText() + " " + jFormattedTextFieldHoraSaida.getText()); Timestamp inicialStamp = new Timestamp(dataInicial.getTime()); Timestamp finalStamp = new Timestamp(dataFinal.getTime()); control.setHoraEntrada(inicialStamp); control.setHoraSaida(finalStamp); DateTime dataHoraEntrada = new DateTime(inicialStamp); DateTime dataHoraSaida = new DateTime(finalStamp); Period tempoTrabalhado = new Period(dataHoraEntrada, dataHoraSaida); int horaLocal = tempoTrabalhado.getMinutes() + tempoTrabalhado.getHours() * 60 + tempoTrabalhado.getDays() * 1440; int hora = horaLocal - 540; control.setHoraExtra(hora); control.setFuncionario((Funcionario) jComboBoxFuncionario.getSelectedItem()); control.setData(jFormattedTextFieldData.getText()); control.setStatus(util.informaAtraso(horaLocal) + ""); control.setDescricao(jTextAreaDescricao.getText()); if (dao.savar(control)) { JOptionPane.showMessageDialog(null, "Ponto registrado com sucesso", "Ateno", JOptionPane.INFORMATION_MESSAGE); jButtonAdicionar.setEnabled(true); jButtonConfirmar.setEnabled(false); jButtonCancelar.setEnabled(false); jButtonAtualizar.setEnabled(false); jButtonExcluir.setEnabled(false); jComboBoxFuncionario.setEnabled(false); jFormattedTextFieldHoraEntrada.setEnabled(false); jFormattedTextFieldHoraSaida.setEnabled(false); jFormattedTextFieldHoraExtra.setEnabled(false); jFormattedTextFieldData.setEnabled(false); jTextAreaDescricao.setEnabled(false); jComboBoxFuncionario.setSelectedItem("Selecione um funcionrio"); jFormattedTextFieldHoraEntrada.setText(""); jFormattedTextFieldHoraSaida.setText(""); jFormattedTextFieldHoraExtra.setText(""); jFormattedTextFieldData.setText(""); jTextAreaDescricao.setText(""); //======================== //--Tabela this.tabelaControle = new TableModelControle(); this.jTable1.setModel(tabelaControle); } else { JOptionPane.showMessageDialog(null, "Erro ao cadastrar.", "Ateno", JOptionPane.ERROR_MESSAGE); jButtonAdicionar.setEnabled(true); jButtonConfirmar.setEnabled(false); jButtonCancelar.setEnabled(false); jButtonAtualizar.setEnabled(false); jButtonExcluir.setEnabled(false); jComboBoxFuncionario.setEnabled(false); jFormattedTextFieldHoraEntrada.setEnabled(false); jFormattedTextFieldHoraSaida.setEnabled(false); jFormattedTextFieldHoraExtra.setEnabled(false); jFormattedTextFieldData.setEnabled(false); jTextAreaDescricao.setEnabled(false); jComboBoxFuncionario.setSelectedItem("Selecione um funcionrio"); jFormattedTextFieldHoraEntrada.setText(""); jFormattedTextFieldHoraSaida.setText(""); jFormattedTextFieldHoraExtra.setText(""); jFormattedTextFieldData.setText(""); jTextAreaDescricao.setText(""); } } catch (Exception e) { } } }
From source file:br.com.registro.view.TelaHoras.java
private void jButtonAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAtualizarActionPerformed // TODO add your handling code here: ControleDAO dao = new ControleDAO(); Controle control = new Controle(); HoraUtil util = new HoraUtil(); if (jComboBoxFuncionario.getSelectedItem().equals("Selecione um funciorio") || jFormattedTextFieldHoraEntrada.getText().isEmpty() || jFormattedTextFieldHoraSaida.getText().isEmpty() || jFormattedTextFieldData.getText().isEmpty()) { JOptionPane.showMessageDialog(null, "Campos obrigatrios vazios", "Ateno", JOptionPane.INFORMATION_MESSAGE); } else {//from w ww.j a v a 2 s . c o m SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Date dataInicial = null; Date dataFinal = null; try { dataInicial = format .parse(jFormattedTextFieldData.getText() + " " + jFormattedTextFieldHoraEntrada.getText()); dataFinal = format .parse(jFormattedTextFieldData.getText() + " " + jFormattedTextFieldHoraSaida.getText()); Timestamp inicialStamp = new Timestamp(dataInicial.getTime()); Timestamp finalStamp = new Timestamp(dataFinal.getTime()); control.setHoraEntrada(inicialStamp); control.setHoraSaida(finalStamp); DateTime dataHoraEntrada = new DateTime(inicialStamp); DateTime dataHoraSaida = new DateTime(finalStamp); Period tempoTrabalhado = new Period(dataHoraEntrada, dataHoraSaida); int horaLocal = tempoTrabalhado.getMinutes() + tempoTrabalhado.getHours() * 60 + tempoTrabalhado.getDays() * 1440; int hora = horaLocal - 540; control.setHoraExtra(hora); control.setStatus(util.informaAtraso(horaLocal) + ""); control.setDescricao(jTextAreaDescricao.getText()); if (dao.update(control)) { JOptionPane.showMessageDialog(null, "Ponto Atualizado com sucesso", "Ateno", JOptionPane.INFORMATION_MESSAGE); jButtonAdicionar.setEnabled(true); jButtonConfirmar.setEnabled(false); jButtonCancelar.setEnabled(false); jButtonAtualizar.setEnabled(false); jButtonExcluir.setEnabled(false); jComboBoxFuncionario.setEnabled(false); jFormattedTextFieldHoraEntrada.setEnabled(false); jFormattedTextFieldHoraSaida.setEnabled(false); jFormattedTextFieldHoraExtra.setEnabled(false); jFormattedTextFieldData.setEnabled(false); jTextAreaDescricao.setEnabled(false); jComboBoxFuncionario.setSelectedItem("Selecione um funcionrio"); jFormattedTextFieldHoraEntrada.setText(""); jFormattedTextFieldHoraSaida.setText(""); jFormattedTextFieldHoraExtra.setText(""); jFormattedTextFieldData.setText(""); jTextAreaDescricao.setText(""); //======================== //--Tabela this.tabelaControle = new TableModelControle(); this.jTable1.setModel(tabelaControle); } else { JOptionPane.showMessageDialog(null, "Em Desenvolvimento.", "Ateno", JOptionPane.ERROR_MESSAGE); jButtonAdicionar.setEnabled(true); jButtonConfirmar.setEnabled(false); jButtonCancelar.setEnabled(false); jButtonAtualizar.setEnabled(false); jButtonExcluir.setEnabled(false); jComboBoxFuncionario.setEnabled(false); jFormattedTextFieldHoraEntrada.setEnabled(false); jFormattedTextFieldHoraSaida.setEnabled(false); jFormattedTextFieldHoraExtra.setEnabled(false); jFormattedTextFieldData.setEnabled(false); jTextAreaDescricao.setEnabled(false); jComboBoxFuncionario.setSelectedItem("Selecione um funcionrio"); jFormattedTextFieldHoraEntrada.setText(""); jFormattedTextFieldHoraSaida.setText(""); jFormattedTextFieldHoraExtra.setText(""); jFormattedTextFieldData.setText(""); jTextAreaDescricao.setText(""); } } catch (Exception e) { } } }
From source file:br.inf.ufes.lar.thtbot.utils.TimeUtil.java
License:Open Source License
/** * Get the number of days elapsed between two Dates. * * @param startDate Start Date./* w ww . j a v a 2 s.co m*/ * @param endDate End Date. * @return Number of days elapsed between two Dates. * @see Date * @since 1.0 */ public static int getDaysElapsed(Date startDate, Date endDate) { Interval interval = new Interval(startDate.getTime(), endDate.getTime()); Period period = interval.toPeriod(); return period.getDays(); }
From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java
License:Open Source License
/** * copy participant info/* ww w . jav a 2s . c o 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:com.cloudhopper.commons.util.demo.UptimeMain.java
License:Apache License
public static void main(String[] args) { //Period period = new Period(uptime, PeriodType.standard().withYearsRemoved().withWeeksRemoved().withMonthsRemoved().withMillisRemoved()); //MutablePeriod period = new Duration(uptime).toPeriod().toMutablePeriod(); long uptime = UPTIME_56_SECS; // ah, ha -- this is super important -- need to normalize the period! PeriodType periodType = PeriodType.standard().withYearsRemoved().withMonthsRemoved().withWeeksRemoved() .withMillisRemoved();/*from w w w. j av a2 s . c o m*/ Period period = new Period(uptime).normalizedStandard(periodType); System.out.println("Uptime: " + uptime + " ms"); System.out.println("Weeks: " + period.getWeeks()); System.out.println("Days: " + period.getDays()); System.out.println("Millis: " + period.getMillis() + " ms"); // print out the uptime String uptimeStyleString = PeriodFormatterUtil.getStandardUptimeStyle().print(period); String linuxStyleString = PeriodFormatterUtil.getLinuxUptimeStyle().print(period); System.out.println(uptimeStyleString); System.out.println(linuxStyleString); PeriodFormatter fmt = new PeriodFormatterBuilder().printZeroNever().appendDays() .appendSuffix(" day ", " days ").appendHours().appendSuffix(" hours ").appendMinutes() .appendSuffix(" mins ").printZeroAlways().appendSeconds().appendSuffix(" secs ").toFormatter(); String str0 = fmt.print(period); System.out.println(str0); String str1 = PeriodFormat.getDefault().print(period); System.out.println(str1); }
From source file:com.github.dbourdette.glass.tools.UtilsTool.java
License:Apache License
public String duration(Date start, Date end) { Period period = new Period(start.getTime(), end.getTime()); StringBuilder builder = new StringBuilder(); appendDuration(builder, period.getDays(), "d"); appendDuration(builder, period.getHours(), "h"); appendDuration(builder, period.getMinutes(), "m"); appendDuration(builder, period.getSeconds(), "s"); return builder.toString().trim(); }
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.// w w w .j a va 2 s . c om * * @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. jav a 2s . 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"; } }