List of usage examples for org.joda.time Period Period
public Period(Object period, PeriodType type, Chronology chrono)
From source file:info.culebrasgis.calculadoradefechas.IntervaloActivity.java
License:Open Source License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_intervalo); fechaUsuario = (Button) findViewById(R.id.buttonFechaUsuario); fechaUsuario.setOnClickListener(new View.OnClickListener() { @Override/* w w w .j a va 2s . c o m*/ public void onClick(View v) { DialogFragment newFragment = new DatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); fechaUsuario2 = (Button) findViewById(R.id.buttonFechaUsuario2); fechaUsuario2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new DatePickerFragment2(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); resultado = (TextView) findViewById(R.id.textViewResultado); volver = (Button) findViewById(R.id.buttonVolver); volver.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); reiniciar = (Button) findViewById(R.id.buttonReiniciar); reiniciar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { resultado.setText(R.string.resultado); fechaUsuario.setText(R.string.fecha); fechaUsuario2.setText(R.string.fecha); } }); calcular = (Button) findViewById(R.id.buttonCalcular); calcular.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { int dia, mes, anno, dia2, mes2, anno2; dia = Integer.parseInt(String.valueOf(fechaUsuario.getText()).substring(0, 2)); mes = Integer.parseInt(String.valueOf(fechaUsuario.getText()).substring(3, 5)); anno = Integer.parseInt(String.valueOf(fechaUsuario.getText()).substring(6, 10)); dia2 = Integer.parseInt(String.valueOf(fechaUsuario2.getText()).substring(0, 2)); mes2 = Integer.parseInt(String.valueOf(fechaUsuario2.getText()).substring(3, 5)); anno2 = Integer.parseInt(String.valueOf(fechaUsuario2.getText()).substring(6, 10)); DateTime fecha = new DateTime(anno, mes, dia, 0, 0); DateTime fecha2 = new DateTime(anno2, mes2, dia2, 0, 0); Period periodo; if (fecha.isBefore(fecha2)) { // si la primera fecha es anterior periodo = new Period(fecha, fecha2, PeriodType.yearMonthDay()); } else { // si la que es anterior es la segunda fecha periodo = new Period(fecha2, fecha, PeriodType.yearMonthDay()); } resultado.setText(String.format(getString(R.string.resultado_intervalo), periodo.getYears(), periodo.getMonths(), periodo.getDays())); } catch (Exception e) { resultado.setText(R.string.fechas_incorrectas); } } }); }
From source file:models.utils.DateUtils.java
License:Apache License
/** * Returns time difference/*from w ww . j a va2 s . c om*/ * * @param d1 * @param d2 * @return */ public static String getDateDifference(Date d1, Date d2) { Period period = new Period(new DateTime(d1), new DateTime(d2), PeriodType.yearMonthDayTime()); return PERIOD_FORMATTER.print(period); }
From source file:net.bashtech.geobot.MessageReplaceParser.java
License:Open Source License
public static String handleUntil(String message, String prefix, String suffix, PeriodFormatter formatter) { int commandStart = message.indexOf(prefix); int commandEnd = message.indexOf(suffix); if (commandStart + prefix.length() < commandEnd) { String replaced = message.substring(commandStart, commandEnd + suffix.length()); String dateStr = message.substring(commandStart + prefix.length(), commandEnd); DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm"); String until;// ww w. j a va 2 s. c om try { DateTime future = fmt.parseDateTime(dateStr); PeriodType pType = PeriodType.dayTime().withMillisRemoved().withSecondsRemoved(); Period period = new Period(new DateTime(), future, pType); until = period.toString(formatter); } catch (IllegalArgumentException e) { until = "Unknown date"; System.out.println(dateStr); e.printStackTrace(); } message = message.replace(replaced, until); } return message; }
From source file:net.bither.viewsystem.froms.VanitygenPanel.java
License:Apache License
private String secondsToString(long seconds) { long now = System.currentTimeMillis(); return remainingTimeFormatter.print(new Period(now, now + seconds * 1000, PeriodType.yearMonthDayTime())); }
From source file:net.objectlab.kit.datecalc.joda.LocalDatePeriodCountCalculator.java
License:Apache License
public int dayDiff(final LocalDate start, final LocalDate end, final PeriodCountBasis basis) { int diff = 0; switch (basis) { case CONV_30_360: diff = diffConv30v360(start, end); break;/*from www.jav a 2 s .c o m*/ case CONV_360E_ISDA: diff = diff360EIsda(start, end); break; case CONV_360E_ISMA: diff = diff360EIsma(start, end); break; default: final Period p = new Period(start, end, PeriodType.days()); diff = p.getDays(); } return diff; }
From source file:net.objectlab.kit.datecalc.joda.LocalDatePeriodCountCalculator.java
License:Apache License
public double yearDiff(final LocalDate start, final LocalDate end, final PeriodCountBasis basis) { double diff = 0.0; switch (basis) { case ACT_ACT: final int startYear = start.getYear(); final int endYear = end.getYear(); if (startYear != endYear) { final LocalDate endOfStartYear = start.dayOfYear().withMaximumValue(); final LocalDate startOfEndYear = end.withDayOfYear(1); final int diff1 = new Period(start, endOfStartYear, PeriodType.days()).getDays(); final int diff2 = new Period(startOfEndYear, end, PeriodType.days()).getDays(); diff = (diff1 + 1.0) / start.dayOfYear().getMaximumValue() + (endYear - startYear - 1.0) + (double) diff2 / (double) end.dayOfYear().getMaximumValue(); }/*from w w w . j ava 2s. com*/ break; case CONV_30_360: case CONV_360E_ISDA: case CONV_360E_ISMA: case ACT_360: diff = dayDiff(start, end, basis) / YEAR_360_0; break; case ACT_365: diff = dayDiff(start, end, basis) / YEAR_365_0; break; default: throw new UnsupportedOperationException("Sorry ACT_UST is not supported"); } return diff; }
From source file:net.tourbook.device.garmin.fit.PrefPageImportFit.java
License:Open Source License
private void updateUI_SplitTour() { final long duration = _spinnerExceededDuration.getSelection(); final Period tourPeriod = new Period(0, duration * 1000, _tourPeriodTemplate); _lblSplitTour_DurationUnit.setText(tourPeriod.toString(UI.DEFAULT_DURATION_FORMATTER_SHORT)); }
From source file:net.tourbook.importdata.DialogEasyImportConfig.java
License:Open Source License
private void updateUI_TemperatureAdjustmentDuration() { final long duration = _spinnerIL_TemperatureAdjustmentDuration.getSelection(); final Period durationPeriod = new Period(0, duration * 1000, _durationTemplate); _lblIL_TemperatureAdjustmentDuration_Unit.setText(durationPeriod.toString(UI.DEFAULT_DURATION_FORMATTER)); }
From source file:net.tourbook.tour.DialogAdjustTemperature_Wizard.java
License:Open Source License
private IRunnableWithProgress performFinish_getRunnable() { _wizardPage.saveState();//from w w w. j a va 2 s.co m final float avgTemperature = _prefStore.getFloat(ITourbookPreferences.ADJUST_TEMPERATURE_AVG_TEMPERATURE); final int durationTime = _prefStore.getInt(ITourbookPreferences.ADJUST_TEMPERATURE_DURATION_TIME); final float temperature = UI.convertTemperatureFromMetric(avgTemperature); final Period durationPeriod = new Period(0, durationTime * 1000, _durationTemplate); final String logText = NLS.bind(TourManager.LOG_TEMP_ADJUST_001_START, new Object[] { durationPeriod.toString(UI.DEFAULT_DURATION_FORMATTER), _nf1.format(temperature), UI.UNIT_LABEL_TEMPERATURE }); TourLogManager.addLog(TourLogState.DEFAULT, logText); final IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(Messages.Dialog_AdjustTemperature_Label_Progress_Task, _selectedTours.size()); // sort tours by date Collections.sort(_selectedTours); int workedTours = 0; final ArrayList<TourData> savedTours = new ArrayList<TourData>(); for (final TourData tourData : _selectedTours) { if (monitor.isCanceled()) { break; } monitor.worked(1); monitor.subTask(NLS.bind(Messages.Dialog_AdjustTemperature_Label_Progress_SubTask, ++workedTours, _selectedTours.size())); final float oldTourAvgTemperature = tourData.getAvgTemperature(); // skip tours which avg temperature is above the minimum avg temperature if (oldTourAvgTemperature > avgTemperature) { TourLogManager.logSubInfo(String.format( TourManager.LOG_TEMP_ADJUST_006_IS_ABOVE_TEMPERATURE, TourManager.getTourDateTimeShort(tourData), oldTourAvgTemperature, avgTemperature)); continue; } if (TourManager.adjustTemperature(tourData, durationTime)) { // tour is modified, save it final TourData savedTourData = TourManager.saveModifiedTour(tourData, false); if (savedTourData != null) { savedTours.add(savedTourData); } } } // update the UI if (savedTours.size() > 0) { Display.getDefault().asyncExec(new Runnable() { @Override public void run() { Util.clearSelection(); /* * Ensure the tour data editor contains the correct tour data */ TourData tourDataInEditor = null; final TourDataEditorView tourDataEditor = TourManager.getTourDataEditor(); if (tourDataEditor != null) { tourDataInEditor = tourDataEditor.getTourData(); } final TourEvent tourEvent = new TourEvent(savedTours); tourEvent.tourDataEditorSavedTour = tourDataInEditor; TourManager.fireEvent(TourEventId.TOUR_CHANGED, tourEvent); // do a reselection of the selected tours to fire the multi tour data selection _tourProvider.toursAreModified(savedTours); } }); } } }; return runnable; }
From source file:net.tourbook.tour.DialogAdjustTemperature_WizardPage.java
License:Open Source License
private void updateUI_TemperatureAdjustmentDuration() { final long duration = _spinnerTemperatureAdjustmentDuration.getSelection(); final Period tourPeriod = new Period(0, duration * 1000, _durationTemplate); _lblDurationUnit.setText(tourPeriod.toString(UI.DEFAULT_DURATION_FORMATTER)); }