List of usage examples for org.joda.time Period normalizedStandard
public Period normalizedStandard()
From source file:com.alta189.cyborg.commandkit.seen.SeenEntry.java
License:Open Source License
public String getDifference(long time) { DateTime begin = new DateTime(time); DateTime end = new DateTime(timestamp); Period period = new Period(end, begin); return timeFormatter.print(period.normalizedStandard()) + " ago"; }
From source file:com.eviware.loadui.ui.fx.views.analysis.linechart.MillisToTickMark.java
License:EUPL
private Period trimPeriod(Period period) { period = period.normalizedStandard(); switch (zoomLevelProperty.get()) { case WEEKS://w w w .j a va 2 s .c o m period = period.withWeeks(0); case DAYS: period = period.withDays(0); case HOURS: period = period.withHours(0); case MINUTES: period = period.withMinutes(0); default: break; } return period; }
From source file:com.nubits.nubot.utils.Utils.java
License:Open Source License
public static String getDurationDate(DateTime from, DateTime to) { Duration duration = new Duration(from, to); Period period = duration.toPeriod(); Period normalizedPeriod = period.normalizedStandard(); PeriodFormatter minutesAndSeconds = new PeriodFormatterBuilder().appendDays().appendSuffix(" day", " days") .appendSeparator(" ").printZeroIfSupported() //.minimumPrintedDigits(2) .appendHours().appendSuffix(" hour", " hours").appendSeparator(" ").appendMinutes() .appendSuffix(" minute", " minutes").printZeroIfSupported() //.minimumPrintedDigits(2) .appendSeparator(" ").appendSeconds().appendSuffix(" second", " seconds") //.minimumPrintedDigits(2) .toFormatter();/*w w w . ja v a 2s . c o m*/ /* .printZeroAlways() .appendMinutes() .appendSeparator(":") .appendSeconds() .toFormatter();*/ String result = minutesAndSeconds.print(normalizedPeriod); return result; }
From source file:com.planyourexchange.utils.DateUtils.java
License:Open Source License
public static String toTimeDelta(Period timeTotal) { return timeTotal.normalizedStandard().toString(FORMATTER); }
From source file:de.azapps.mirakel.model.recurring.RecurringBase.java
License:Open Source License
public void setInterval(final @NonNull Period interval) { recurringInterval = interval.normalizedStandard(); }
From source file:de.tshw.worktracker.view.TimeEntriesTableModel.java
License:MIT License
@Override public Object getValueAt(int rowIndex, int columnIndex) { Object value = null;//www.j av a 2 s .c o m Set<Project> projects = workTracker.getProjects(); if (columnIndex == 0) { value = projects.toArray(new Project[projects.size()])[rowIndex]; } else if (columnIndex == 1) { Project project = projects.toArray(new Project[projects.size()])[rowIndex]; Period period = elapsedTimes.get(project); if (period == null) { value = "0:00:00"; } else { value = periodFormatter.print(period.normalizedStandard()); } } return value; }
From source file:ee.ut.soras.test_ajavt.KiiruseTestiTulemus.java
License:Open Source License
private String convertToOtherFields(double timeInMills) { Period p = new Period((long) timeInMills, PeriodType.millis()); p = p.normalizedStandard(); DurationFieldType[] fieldTypes = p.getFieldTypes(); int[] values = p.getValues(); if (values.length == fieldTypes.length) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < values.length; i++) { if (values[i] != 0) { sb.append(values[i] + " " + fieldTypes[i].getName() + " "); }/*from w w w. j a v a2 s . c om*/ } return sb.toString(); } return p.toString(); }
From source file:graphene.util.stats.TimeReporter.java
License:Apache License
public void logEstimation(long estimatedTotal, long numberProcessed) { if (estimatedTotal <= numberProcessed) { log.info("Should be Completed"); } else if (numberProcessed == 0) { log.info("inf"); } else {//from w w w .j a va 2 s. com double rate = getElapsed() / numberProcessed; double guess = ((estimatedTotal - numberProcessed) * rate) / 1000; int d = guess > 86400 ? (int) guess / 86400 : 0; guess %= 86400; int h = guess > 3600 ? (int) guess / 3600 : 0; guess %= 3600; int m = guess > 60 ? (int) guess / 60 : 0; guess %= 60; int s = (int) (guess > 0 ? guess : 0); Period period = new Period(d, h, m, s); log.info("Time remaining: " + daysHoursMinutes.print(period.normalizedStandard())); } }
From source file:org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategy.java
License:Open Source License
/** * Determines the starting point ("anchor") for a period. * * To produce repeatable rotation points in time, the period is "snapped" to a "grid" of time. * For example, an hourly index rotation would be anchored to the last full hour, instead of happening at whatever minute * the first rotation was started.//from w ww . ja va 2s .c om * * This "snapping" is done accordingly with the other parts of a period. * * For highly irregular periods (those that do not have a small zero component) * * @param period the rotation period * @return the anchor DateTime to calculate rotation periods from */ protected static DateTime determineRotationPeriodAnchor(@Nullable DateTime lastAnchor, Period period) { final Period normalized = period.normalizedStandard(); int years = normalized.getYears(); int months = normalized.getMonths(); int weeks = normalized.getWeeks(); int days = normalized.getDays(); int hours = normalized.getHours(); int minutes = normalized.getMinutes(); int seconds = normalized.getSeconds(); if (years == 0 && months == 0 && weeks == 0 && days == 0 && hours == 0 && minutes == 0 && seconds == 0) { throw new IllegalArgumentException("Invalid rotation period specified"); } // find the largest non-zero stride in the period. that's our anchor type. statement order matters here! DateTimeFieldType largestStrideType = null; if (seconds > 0) largestStrideType = secondOfMinute(); if (minutes > 0) largestStrideType = minuteOfHour(); if (hours > 0) largestStrideType = hourOfDay(); if (days > 0) largestStrideType = dayOfMonth(); if (weeks > 0) largestStrideType = weekOfWeekyear(); if (months > 0) largestStrideType = monthOfYear(); if (years > 0) largestStrideType = year(); if (largestStrideType == null) { throw new IllegalArgumentException("Could not determine rotation stride length."); } final DateTime anchorTime = MoreObjects.firstNonNull(lastAnchor, Tools.nowUTC()); final DateTimeField field = largestStrideType.getField(anchorTime.getChronology()); // use normalized here to make sure we actually have the largestStride type available! see https://github.com/Graylog2/graylog2-server/issues/836 int periodValue = normalized.get(largestStrideType.getDurationType()); final long fieldValue = field.roundFloor(anchorTime.getMillis()); final int fieldValueInUnit = field.get(fieldValue); if (periodValue == 0) { // https://github.com/Graylog2/graylog2-server/issues/836 log.warn( "Determining stride length failed because of a 0 period. Defaulting back to 1 period to avoid crashing, but this is a bug!"); periodValue = 1; } final long difference = (fieldValueInUnit % periodValue); final long newValue = field.add(fieldValue, -1 * difference); return new DateTime(newValue, DateTimeZone.UTC); }
From source file:org.graylog2.indexer.rotation.TimeBasedRotationStrategy.java
License:Open Source License
public TimeBasedRotationStrategy(Period rotationPeriod) { this.rotationPeriod = rotationPeriod.normalizedStandard(); anchor = determineRotationPeriodAnchor(rotationPeriod); lastRotation = null;//from www . ja v a2 s.c o m }