List of usage examples for org.joda.time Period getDays
public int getDays()
From source file:trabalho.model.JodaMain.java
public int retornaTempo(RegistroPontoEntity registro) { RegistroPontoEntity registroPonto = registro; DateTime dataHoraEntrada = new DateTime(registroPonto.getDataInicial()); DateTime dataHoraSaida = new DateTime(registroPonto.getDataFinal()); Period tempoTrabalhado = new Period(dataHoraEntrada, dataHoraSaida); int horaLocal = tempoTrabalhado.getMinutes() + tempoTrabalhado.getHours() * 60 + tempoTrabalhado.getDays() * 1440; System.out.println(horaLocal); return horaLocal; }
From source file:TVShowTimelineMaker.timeline.OnceDayEvent.java
@Override public int size() { if (this.isMarkedForComplexEval()) { return this.PossibleDays.size(); } else if (this.latestPossibleDate.isAfter(this.earliestPossibleDate)) { org.joda.time.Interval newInterval = new org.joda.time.Interval(this.earliestPossibleDate, this.latestPossibleDate); Period daysPeriod = newInterval.toPeriod(org.joda.time.PeriodType.days()); return daysPeriod.getDays() + 1; } else {/*from w ww . j a va 2 s. c o m*/ return -1; } }
From source file:TVShowTimelineMaker.timeline.OncePeriodEvent.java
@Override public boolean containsCould(DayOfYear inDateTime) { int monthOfYear = inDateTime.getMonth(); boolean rAccept; org.joda.time.Interval newInterval = this.toLongInterval(); Period daysPeriod = newInterval.toPeriod(org.joda.time.PeriodType.days()); if (daysPeriod.getDays() < 366) { boolean overYearBound = this.earliestPossibleDateForStart.getYear() < this.latestPossibleDateForEnd .getYear();// www . j a v a2s .c o m int startMonth = this.earliestPossibleDateForStart.getMonthOfYear(); int endMonth = this.latestPossibleDateForEnd.getMonthOfYear(); int startDay = this.earliestPossibleDateForStart.getDayOfMonth(); int endDay = this.latestPossibleDateForEnd.getDayOfMonth(); if ((!overYearBound) && (monthOfYear > startMonth) && (monthOfYear < endMonth)) { rAccept = true; } else if ((overYearBound) && ((monthOfYear > startMonth) || (monthOfYear < endMonth))) { rAccept = true; } else if ((monthOfYear == startMonth) && (inDateTime.getDay() >= startDay)) { rAccept = true; } else if ((monthOfYear == endMonth) && (inDateTime.getDay() <= endDay)) { rAccept = true; } else { rAccept = false; } } else { rAccept = true; } return rAccept; }
From source file:TVShowTimelineMaker.timeline.OncePeriodEvent.java
@Override public boolean containsSure(DayOfYear inDateTime) { int monthOfYear = inDateTime.getMonth(); boolean rAccept; org.joda.time.Interval newInterval = this.toShortInterval(); Period daysPeriod = newInterval.toPeriod(org.joda.time.PeriodType.days()); if (daysPeriod.getDays() < 366) { boolean overYearBound = this.earliestPossibleDateForStart.getYear() < this.latestPossibleDateForEnd .getYear();//from www . j a va2s .c o m int startMonth = this.earliestPossibleDateForStart.getMonthOfYear(); int endMonth = this.latestPossibleDateForEnd.getMonthOfYear(); int startDay = this.earliestPossibleDateForStart.getDayOfMonth(); int endDay = this.latestPossibleDateForEnd.getDayOfMonth(); if ((!overYearBound) && (monthOfYear > startMonth) && (monthOfYear < endMonth)) { rAccept = true; } else if ((overYearBound) && ((monthOfYear > startMonth) || (monthOfYear < endMonth))) { rAccept = true; } else if ((monthOfYear == startMonth) && (inDateTime.getDay() >= startDay)) { rAccept = true; } else if ((monthOfYear == endMonth) && (inDateTime.getDay() <= endDay)) { rAccept = true; } else { rAccept = false; } } else { rAccept = true; } return rAccept; }
From source file:TVShowTimelineMaker.timeline.OncePeriodEvent.java
@Override public int size() { //TODO: refine int tSize;/*w ww. j a va 2s.c om*/ if (this.isMarkedForComplexEval()) { tSize = this.endPossibleDays.size() * this.startPossibleDays.size(); } else { org.joda.time.Interval startInterval = new org.joda.time.Interval(this.earliestPossibleDateForStart, this.latestPossibleDateForStart); Period startPeriod = startInterval.toPeriod(org.joda.time.PeriodType.days()); org.joda.time.Interval endInterval = new org.joda.time.Interval(this.earliestPossibleDateForEnd, this.latestPossibleDateForEnd); Period endPeriod = endInterval.toPeriod(org.joda.time.PeriodType.days()); tSize = (startPeriod.getDays() + 1) * (endPeriod.getDays() + 1); } return tSize; }
From source file:uk.ac.susx.tag.method51.core.params.codec.concrete.DurationCodec.java
License:Apache License
@Override public Duration decodeString(String value) throws DecodeException { Duration result = null;//from www. j a va2 s. c om long milliseconds; try { milliseconds = Long.parseLong(value); } catch (NumberFormatException e) { try { if (value.length() == 0) { throw new IllegalArgumentException("zero length interval specification"); } value = value.toUpperCase(); if (!value.matches(".*[DWMHS].*")) { throw new IllegalArgumentException( "no time units specified, see ISO 8601 duration specification (months / years not supported): http://en.wikipedia.org/wiki/ISO_8601#Durations"); } if (!value.startsWith("P")) { value = "P" + value; } Matcher m = Pattern.compile("[HMS]").matcher(value); if (!value.contains("T") && m.find()) { String c = m.group(0); int i = value.indexOf(c); value = value.substring(0, i - 1) + "T" + value.substring(i - 1); } Period period = ISOPeriodFormat.standard().parsePeriod(value); long seconds = 0; seconds += period.getSeconds(); seconds += period.getMinutes() * DateTimeConstants.SECONDS_PER_MINUTE; seconds += period.getHours() * DateTimeConstants.SECONDS_PER_HOUR; seconds += period.getDays() * DateTimeConstants.SECONDS_PER_DAY; seconds += period.getWeeks() * DateTimeConstants.SECONDS_PER_WEEK; milliseconds = seconds * 1000; } catch (IllegalArgumentException e1) { throw new DecodeException("'" + value + "' is not a number, or an ISO 8601 duration", e1); } } result = new Duration(milliseconds); return result; }
From source file:utilities.time.DateAndTimes.java
License:Open Source License
/** * * This will calculate out and return a String the length of a period in easy to read format: Y * * @param duration//from w w w . ja va 2 s . com * @param yearsSeparatorFormat * @param monthsSeparatorFormat * @param weeksSeparatorFormat * @param daysSeparatorFormat * @param hoursSeparatorFormat * @param minutesSeparatorFormat * @param secondsSeparatorFormat * @return */ public static String getPeriodFormattedFromMilliseconds(long duration, String yearsSeparatorFormat, String monthsSeparatorFormat, String weeksSeparatorFormat, String daysSeparatorFormat, String hoursSeparatorFormat, String minutesSeparatorFormat, String secondsSeparatorFormat) { Period period = new Period(duration); if (period.getYears() > 0) { return getPeriodFormat(period, yearsSeparatorFormat, monthsSeparatorFormat, weeksSeparatorFormat, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getMonths() > 0) { return getPeriodFormat(period, monthsSeparatorFormat, weeksSeparatorFormat, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getWeeks() > 0) { return getPeriodFormat(period, weeksSeparatorFormat, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getDays() > 0) { return getPeriodFormat(period, daysSeparatorFormat, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getHours() > 0) { return getPeriodFormat(period, hoursSeparatorFormat, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getMinutes() > 0) { return getPeriodFormat(period, minutesSeparatorFormat, secondsSeparatorFormat); } else if (period.getSeconds() > 0) { return getPeriodFormat(period, secondsSeparatorFormat); } else { return null; } }
From source file:ventanas.parqueadero.ventas.java
private void btnPagoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPagoActionPerformed try {//from www. j a v a 2 s . c o m int indice = dBTable1.getSelectedRow(); Billing b = ventas.get(indice); Object state = controller.getEm().createNativeQuery("Select estado from factura where id=" + b.getId()) .getSingleResult(); if (state.toString().equals("Pagada")) { JOptionPane.showMessageDialog(this, "El ticket ya ha sido PAGADO.\n Actualice la tabla de datos", "ERROR", JOptionPane.ERROR_MESSAGE); verTabla(true); return; } if (state.toString().equals("ANULADA")) { JOptionPane.showMessageDialog(this, "El ticket ha sido ANULADO.\n Actualice la tabla de datos", "ERROR", JOptionPane.ERROR_MESSAGE); verTabla(true); return; } if (state.equals("CONTRATO")) { JOptionPane.showMessageDialog(this, "El ticket es de tipo CONTRATO.\n No se puede pagar.", "ERROR", JOptionPane.ERROR_MESSAGE); verTabla(true); return; } //calcular el tiempo de pago Date timeStart = b.getDetailBillingList().get(0).getTimestart(); DateTime start = new DateTime(timeStart); //obtener la fecha de la base de datos //generar la hora de la bd Date endJava = convertToDate_DatabaseDate(); DateTime end = new DateTime(endJava); Period $period = new Period(start, end, PeriodType.yearMonthDayTime()); int days = $period.getDays(); int hours = $period.getHours(); int minutes = $period.getMinutes(); System.out.println("DIA " + $period.getDays()); System.out.println("HORAS: " + $period.getHours()); System.out.println("MINUTOS: " + $period.getMinutes()); Product product = b.getDetailBillingList().get(0).getProductId(); BigDecimal price = product.getSaleprice(); BigDecimal quantity = BigDecimal.ZERO; String tiempo = days + ":" + hours + ":" + minutes; if (hours >= 1) { quantity = new BigDecimal(hours); } if (minutes > 0) { quantity = quantity.add(BigDecimal.ONE); } if (days >= 1) { int hoursPerDay = days * 24; quantity = quantity.add(new BigDecimal(hoursPerDay)); } BigDecimal totalIva = price.multiply(quantity).multiply(product.getPercentageIva()); BigDecimal total = product.getSaleprice().multiply(quantity).add(totalIva); total = total.setScale(2, RoundingMode.HALF_UP); CobroParkForm dialog = new CobroParkForm(new javax.swing.JFrame(), Boolean.TRUE, b, tiempo, days, hours, minutes, quantity, endJava, total); dialog.setVisible(true); verTabla(true); } catch (ParseException ex) { Logger.getLogger(ventas.class.getName()).log(Level.SEVERE, null, ex); } }