List of usage examples for org.joda.time Period Period
public Period(Object period, PeriodType type, Chronology chrono)
From source file:net.tourbook.tour.photo.TourPhotoLink.java
License:Open Source License
/** * Constructor for a real tour.//w ww. jav a2 s.c o m * * @param tourEndTime * @param tourStartTime * @param tourId * @param dbPhotoTimeAdjustment * @param dbNumberOfPhotos */ TourPhotoLink(final long tourId, final long tourStartTime, final long tourEndTime, final int numberOfPhotos, final int dbPhotoTimeAdjustment) { this.tourId = tourId; linkId = tourId; setTourStartTime(tourStartTime); setTourEndTime(tourEndTime); numberOfTourPhotos = numberOfPhotos; tourPeriod = new Period(tourStartTime, tourEndTime, _tourPeriodTemplate); photoTimeAdjustment = dbPhotoTimeAdjustment; }
From source file:net.tourbook.tour.photo.TourPhotoLink.java
License:Open Source License
void setTourEndTime(final long endTime) { if (isHistoryTour) { final int photosSize = linkPhotos.size(); if (photosSize == 0) { // there are no photos in this history tour, THIS SHOULD NOT HAPPEN FOR A HISTORY TOUR tourEndTime = tourStartTime; } else {/*w w w.java 2 s . c o m*/ // get time from last photo tourEndTime = linkPhotos.get(photosSize - 1).adjustedTimeLink; } finalizeHistoryTour(); } else { tourEndTime = endTime; } // set tour period AFTER history tour is finalized tourPeriod = new Period(tourStartTime, tourEndTime, _tourPeriodTemplate); }
From source file:net.tourbook.tour.TourInfoUI.java
License:Open Source License
private void updateUI() { /*//from www . j a v a2 s. co m * upper/lower part */ if (_lblTourType != null && _lblTourType.isDisposed() == false) { _lblTourType.setToolTipText(_uiTourTypeName); net.tourbook.ui.UI.updateUI_TourType(_tourData, _lblTourType, false); } String tourTitle = _tourData.getTourTitle(); if (tourTitle == null || tourTitle.trim().length() == 0) { tourTitle = Messages.Tour_Tooltip_Label_DefaultTitle; } _lblTitle.setText(tourTitle); if (_hasWeather) { _txtWeather.setText(_tourData.getWeather()); } if (_hasTourType) { _lblTourTypeText.setText(_tourData.getTourType().getName()); } if (_hasTags) { net.tourbook.ui.UI.updateUI_Tags(_tourData, _lblTourTags); } if (_hasDescription) { _txtDescription.setText(_tourData.getTourDescription()); } /* * column: left */ final long recordingTime = _tourData.getTourRecordingTime(); final long movingTime = _tourData.getTourDrivingTime(); final long breakTime = recordingTime - movingTime; final ZonedDateTime zdtTourStart = _tourData.getTourStartTime(); final ZonedDateTime zdtTourEnd = zdtTourStart.plusSeconds(recordingTime); if (isSimpleTour()) { // < 1 day _lblDate.setText(String.format(// Messages.Tour_Tooltip_Format_DateWeekTime, zdtTourStart.format(TimeTools.Formatter_Date_F), zdtTourStart.format(TimeTools.Formatter_Time_M), zdtTourEnd.format(TimeTools.Formatter_Time_M), zdtTourStart.get(TimeTools.calendarWeek.weekOfWeekBasedYear()) )); _lblRecordingTimeHour.setVisible(true); _lblMovingTimeHour.setVisible(true); _lblBreakTimeHour.setVisible(true); _lblRecordingTime.setText(FormatManager.formatRecordingTime(recordingTime)); _lblMovingTime.setText(FormatManager.formatDrivingTime(movingTime)); _lblBreakTime.setText(FormatManager.formatPausedTime(breakTime)); /* * Time zone */ final String tourTimeZoneId = _tourData.getTimeZoneId(); final TourDateTime tourDateTime = _tourData.getTourDateTime(); _lblTimeZone_Value.setText(tourTimeZoneId == null ? UI.EMPTY_STRING : tourTimeZoneId); _lblTimeZoneDifference_Value.setText(tourDateTime.timeZoneOffsetLabel); // set tooltip text final String defaultTimeZoneId = _prefStoreCommon.getString(ICommonPreferences.TIME_ZONE_LOCAL_ID); final String timeZoneTooltip = NLS.bind(Messages.ColumnFactory_TimeZoneDifference_Tooltip, defaultTimeZoneId); _lblTimeZoneDifference.setToolTipText(timeZoneTooltip); _lblTimeZoneDifference_Value.setToolTipText(timeZoneTooltip); _decoTimeZone.setDescriptionText(timeZoneTooltip); } else { // > 1 day _lblDate.setText(String.format(// Messages.Tour_Tooltip_Format_HistoryDateTime, zdtTourStart.format(_dtHistoryFormatter), zdtTourEnd.format(_dtHistoryFormatter)// )); // hide labels, they are displayed with the period values _lblRecordingTimeHour.setVisible(false); _lblMovingTimeHour.setVisible(false); _lblBreakTimeHour.setVisible(false); final Period recordingPeriod = new Period(_tourData.getTourStartTimeMS(), _tourData.getTourEndTimeMS(), _tourPeriodTemplate); final Period movingPeriod = new Period(0, movingTime * 1000, _tourPeriodTemplate); final Period breakPeriod = new Period(0, breakTime * 1000, _tourPeriodTemplate); _lblRecordingTime.setText(recordingPeriod.toString(UI.DEFAULT_DURATION_FORMATTER_SHORT)); _lblMovingTime.setText(movingPeriod.toString(UI.DEFAULT_DURATION_FORMATTER_SHORT)); _lblBreakTime.setText(breakPeriod.toString(UI.DEFAULT_DURATION_FORMATTER_SHORT)); } int windSpeed = _tourData.getWeatherWindSpeed(); windSpeed = (int) (windSpeed / net.tourbook.ui.UI.UNIT_VALUE_DISTANCE); _lblWindSpeed.setText(Integer.toString(windSpeed)); _lblWindSpeedUnit.setText(String.format(Messages.Tour_Tooltip_Format_WindSpeedUnit, UI.UNIT_LABEL_SPEED, IWeather.windSpeedTextShort[getWindSpeedTextIndex(windSpeed)])); // wind direction final int weatherWindDirDegree = _tourData.getWeatherWindDir(); _lblWindDirection.setText(Integer.toString(weatherWindDirDegree)); _lblWindDirectionUnit.setText(String.format(Messages.Tour_Tooltip_Format_WindDirectionUnit, IWeather.windDirectionText[getWindDirectionTextIndex(weatherWindDirDegree)])); // temperature float temperature = _tourData.getAvgTemperature(); if (net.tourbook.ui.UI.UNIT_VALUE_TEMPERATURE != 1) { temperature = temperature * net.tourbook.ui.UI.UNIT_FAHRENHEIT_MULTI + net.tourbook.ui.UI.UNIT_FAHRENHEIT_ADD; } _lblTemperature.setText(_nf1.format(temperature)); // weather clouds final int weatherIndex = _tourData.getWeatherIndex(); final String cloudText = IWeather.cloudText[weatherIndex]; final String cloudImageName = IWeather.cloudIcon[weatherIndex]; _lblClouds.setImage(UI.IMAGE_REGISTRY.get(cloudImageName)); _lblCloudsUnit.setText(cloudText.equals(IWeather.cloudIsNotDefined) ? UI.EMPTY_STRING : cloudText); /* * column: right */ final float distance = _tourData.getTourDistance() / net.tourbook.ui.UI.UNIT_VALUE_DISTANCE; _lblDistance.setText(FormatManager.formatDistance(distance / 1000.0)); _lblDistanceUnit.setText(UI.UNIT_LABEL_DISTANCE); _lblAltitudeUp.setText(Integer.toString(// (int) (_tourData.getTourAltUp() / net.tourbook.ui.UI.UNIT_VALUE_ALTITUDE))); _lblAltitudeUpUnit.setText(UI.UNIT_LABEL_ALTITUDE); _lblAltitudeDown.setText(Integer.toString(// (int) (_tourData.getTourAltDown() / net.tourbook.ui.UI.UNIT_VALUE_ALTITUDE))); _lblAltitudeDownUnit.setText(UI.UNIT_LABEL_ALTITUDE); final float avgSpeed = movingTime == 0 ? 0 : distance / (movingTime / 3.6f); _lblAvgSpeed.setText(FormatManager.formatSpeed(avgSpeed)); _lblAvgSpeedUnit.setText(UI.UNIT_LABEL_SPEED); final int pace = (int) (distance == 0 ? 0 : (movingTime * 1000 / distance)); _lblAvgPace.setText(String.format(// Messages.Tour_Tooltip_Format_Pace, pace / 60, pace % 60)// ); _lblAvgPaceUnit.setText(UI.UNIT_LABEL_PACE); // avg pulse final double avgPulse = _tourData.getAvgPulse(); _lblAvgPulse.setText(FormatManager.formatPulse(avgPulse)); _lblAvgPulseUnit.setText(Messages.Value_Unit_Pulse); // avg cadence final double avgCadence = _tourData.getAvgCadence() * _tourData.getCadenceMultiplier(); _lblAvgCadence.setText(FormatManager.formatCadence(avgCadence)); _lblAvgCadenceUnit .setText(_tourData.isCadenceSpm() ? Messages.Value_Unit_Cadence_Spm : Messages.Value_Unit_Cadence); // avg power final double avgPower = _tourData.getPower_Avg(); _lblAvg_Power.setText(FormatManager.formatPower(avgPower)); _lblAvg_PowerUnit.setText(UI.UNIT_POWER); // calories final double calories = _tourData.getCalories(); _lblCalories.setText(FormatManager.formatNumber_0(calories)); // body _lblRestPulse.setText(Integer.toString(_tourData.getRestPulse())); _lblBodyWeight.setText(_nf1.format(_tourData.getBodyWeight())); /* * Max values */ _lblMaxAltitude.setText(Integer.toString(// (int) (_tourData.getMaxAltitude() / net.tourbook.ui.UI.UNIT_VALUE_ALTITUDE))); _lblMaxAltitudeUnit.setText(UI.UNIT_LABEL_ALTITUDE); _lblMaxPulse.setText(FormatManager.formatPulse(_tourData.getMaxPulse())); _lblMaxPulseUnit.setText(Messages.Value_Unit_Pulse); _lblMaxSpeed.setText(FormatManager.formatSpeed(_tourData.getMaxSpeed())); _lblMaxSpeedUnit.setText(UI.UNIT_LABEL_SPEED); // gears if (_hasGears) { _lblGearFrontShifts.setText(Integer.toString(_tourData.getFrontShiftCount())); _lblGearRearShifts.setText(REAR_SHIFT_FORMAT + Integer.toString(_tourData.getRearShiftCount())); } /* * date/time */ // date/time created if (_uiDtCreated != null) { _lblDateTimeCreatedValue.setText(_uiDtCreated == null ? // UI.EMPTY_STRING : _uiDtCreated.format(TimeTools.Formatter_DateTime_M)); } // date/time modified if (_uiDtModified != null) { _lblDateTimeModifiedValue.setText(_uiDtModified == null ? // UI.EMPTY_STRING : _uiDtModified.format(TimeTools.Formatter_DateTime_M)); } }
From source file:net.tourbook.ui.views.rawData.RawDataView.java
License:Open Source License
private String getDurationText(final ImportLauncher importLauncher) { final int duration = importLauncher.temperatureAdjustmentDuration; final Period durationPeriod = new Period(0, duration * 1000, _durationTemplate); return durationPeriod.toString(UI.DEFAULT_DURATION_FORMATTER); }
From source file:org.apache.beam.sdk.extensions.sql.impl.interpreter.operator.date.BeamSqlTimestampMinusTimestampExpression.java
License:Apache License
private long numberOfIntervalsBetweenDates(DateTime timestampStart, DateTime timestampEnd) { Period period = new Period(timestampStart, timestampEnd, PeriodType.forFields(new DurationFieldType[] { durationFieldType(intervalType) })); return period.get(durationFieldType(intervalType)); }
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/*w w w.ja va 2s . 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(); }
From source file:org.gephi.desktop.timeline.DateTick.java
License:Open Source License
public static DateTick create(double min, double max, int width) { DateTime minDate = new DateTime((long) min); DateTime maxDate = new DateTime((long) max); Period period = new Period(minDate, maxDate, PeriodType.yearMonthDayTime()); ;// www . j a v a2 s. c om int years = period.getYears(); int months = period.getMonths(); int days = period.getDays(); int hours = period.getHours(); int minutes = period.getMinutes(); int seconds = period.getSeconds(); //Top type DateTimeFieldType topType; if (years > 0) { topType = DateTimeFieldType.year(); } else if (months > 0) { topType = DateTimeFieldType.monthOfYear(); } else if (days > 0) { topType = DateTimeFieldType.dayOfMonth(); } else if (hours > 0) { topType = DateTimeFieldType.hourOfDay(); } else if (minutes > 0) { topType = DateTimeFieldType.minuteOfHour(); } else if (seconds > 0) { topType = DateTimeFieldType.secondOfMinute(); } else { topType = DateTimeFieldType.millisOfSecond(); } //Bottom type if (topType != DateTimeFieldType.millisOfSecond()) { DateTimeFieldType bottomType; if (topType.equals(DateTimeFieldType.year())) { bottomType = DateTimeFieldType.monthOfYear(); } else if (topType.equals(DateTimeFieldType.monthOfYear())) { bottomType = DateTimeFieldType.dayOfMonth(); } else if (topType.equals(DateTimeFieldType.dayOfMonth())) { bottomType = DateTimeFieldType.hourOfDay(); } else if (topType.equals(DateTimeFieldType.hourOfDay())) { bottomType = DateTimeFieldType.minuteOfHour(); } else if (topType.equals(DateTimeFieldType.minuteOfHour())) { bottomType = DateTimeFieldType.secondOfMinute(); } else { bottomType = DateTimeFieldType.millisOfSecond(); } //Number of ticks Period p = new Period(minDate, maxDate, PeriodType.forFields(new DurationFieldType[] { bottomType.getDurationType() })); int intervals = p.get(bottomType.getDurationType()); if (intervals > 0) { int intervalSize = width / intervals; if (intervalSize >= MIN_PIXELS) { return new DateTick(minDate, maxDate, new DateTimeFieldType[] { topType, bottomType }); } } } return new DateTick(minDate, maxDate, new DateTimeFieldType[] { topType }); }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionImpl.java
License:Apache License
@Override public String getTimeFancyText(DateTime from, DateTime to) { final String prefix = "Join in "; if (to != null) { Duration d = new Duration(to, from); Period timeUntil = new Period(to.toInstant(), from.toInstant(), PeriodType.dayTime()); long standardDays = d.getStandardDays(); if (standardDays > 0) { PeriodFormatter daysHours = new PeriodFormatterBuilder().appendDays().appendSuffix(" day", " days") .appendSeparator(", and ").appendHours().appendSuffix(" hour", " hours").toFormatter(); return prefix + daysHours.print(timeUntil.normalizedStandard(PeriodType.dayTime())); } else {/*from w ww.ja va 2 s .co m*/ PeriodFormatter dafaultFormatter = new PeriodFormatterBuilder().appendHours() .appendSuffix(" hour", " hours").appendSeparator(", and ").appendMinutes() .appendSuffix(" minute", " minutes").toFormatter(); return prefix + dafaultFormatter.print(timeUntil.normalizedStandard(PeriodType.dayTime())); } } else { return null; } }
From source file:org.jw.service.entity.Contact.java
@Transient public String getAge() { if (this.birthdate == null) return "<No Birthdate>"; LocalDate dob = LocalDate.fromDateFields(birthdate); LocalDate now = LocalDate.now(); Period period = new Period(dob, now, PeriodType.yearMonthDay()); return String.format("%d years & %d months", period.getYears(), period.getMonths()); }
From source file:org.openmrs.module.chaiui.ChaiUiUtils.java
License:Open Source License
/** * Formats a person's age/*from ww w .j av a2s . c o m*/ * @param person the person * @return the string value */ public String formatPersonAge(Person person) { String prefix = BooleanUtils.isTrue(person.isBirthdateEstimated()) ? "~" : ""; int ageYears = person.getAge(); if (ageYears < 1) { Period p = new Period(person.getBirthdate().getTime(), System.currentTimeMillis(), PeriodType.yearMonthDay()); return prefix + p.getMonths() + " month(s), " + p.getDays() + " day(s)"; } else { return prefix + ageYears + " year(s)"; } }