List of usage examples for org.joda.time Period getMillis
public int getMillis()
From source file:org.apache.arrow.vector.util.DateUtility.java
License:Apache License
public static int millisFromPeriod(final Period period) { return (period.getHours() * hoursToMillis) + (period.getMinutes() * minutesToMillis) + (period.getSeconds() * secondsToMillis) + (period.getMillis()); }
From source file:org.apache.drill.exec.vector.DateUtilities.java
License:Apache License
public static int periodToMillis(final Period period) { return (period.getHours() * hoursToMillis) + (period.getMinutes() * minutesToMillis) + (period.getSeconds() * secondsToMillis) + (period.getMillis()); }
From source file:org.apache.streams.jackson.StreamsPeriodSerializer.java
License:Apache License
@Override public void serialize(Period value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(Integer.toString(value.getMillis())); }
From source file:org.eclim.plugin.core.command.history.HistoryListCommand.java
License:Open Source License
private String delta(long time) { // FIXME: a formatter can probably do this. Period period = new Period(time, System.currentTimeMillis()); ArrayList<String> parts = new ArrayList<String>(); int years = period.getYears(); if (years > 0) { parts.add(years + " year" + (years == 1 ? "" : "s")); }//from w ww .j a v a 2s. co m int months = period.getMonths(); if (months > 0) { parts.add(months + " month" + (months == 1 ? "" : "s")); } int weeks = period.getWeeks(); if (weeks > 0) { parts.add(weeks + " week" + (weeks == 1 ? "" : "s")); } int days = period.getDays(); if (days > 0) { parts.add(days + " day" + (days == 1 ? "" : "s")); } int hours = period.getHours(); if (hours > 0) { parts.add(hours + " hour" + (hours == 1 ? "" : "s")); } int minutes = period.getMinutes(); if (minutes > 0) { parts.add(minutes + " minute" + (minutes == 1 ? "" : "s")); } int seconds = period.getSeconds(); if (seconds > 0) { parts.add(seconds + " second" + (seconds == 1 ? "" : "s")); } if (parts.size() == 0) { int millis = period.getMillis(); if (millis > 0) { parts.add(millis + " millis"); } } return StringUtils.join(parts.toArray(), ' ') + " ago"; }
From source file:org.hawkular.metrics.core.impl.DateTimeService.java
License:Apache License
public DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/*from w w w. j a v a 2 s. c o m*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hawkular.metrics.datetime.DateTimeService.java
License:Apache License
public static DateTime getTimeSlice(DateTime dt, Duration duration) { Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/*w w w . jav a2s . co m*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.hawkular.metrics.tasks.api.AbstractTrigger.java
License:Apache License
protected DateTime getExecutionTime(long time, Duration duration) { DateTime dt = new DateTime(time); Period p = duration.toPeriod(); if (p.getYears() != 0) { return dt.yearOfEra().roundFloorCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundFloorCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundFloorCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundFloorCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundFloorCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundFloorCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundFloorCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }/*from w w w.j a va 2s .c o m*/ return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }
From source file:org.jbpm.process.core.timer.BusinessCalendarImpl.java
License:Apache License
protected String adoptISOFormat(String timeExpression) { try {// w w w .j av a 2 s .co m Period p = null; if (DateTimeUtils.isPeriod(timeExpression)) { p = ISOPeriodFormat.standard().parsePeriod(timeExpression); } else { DateTime dt = ISODateTimeFormat.dateTimeParser().parseDateTime(timeExpression); Duration duration = new Duration(System.currentTimeMillis(), dt.getMillis()); p = duration.toPeriod(); } int days = p.getDays(); int hours = p.getHours(); int minutes = p.getMinutes(); int seconds = p.getSeconds(); int milis = p.getMillis(); StringBuffer time = new StringBuffer(); if (days > 0) { time.append(days + "d"); } if (hours > 0) { time.append(hours + "h"); } if (minutes > 0) { time.append(minutes + "m"); } if (seconds > 0) { time.append(seconds + "s"); } if (milis > 0) { time.append(milis + "ms"); } return time.toString(); } catch (Exception e) { return timeExpression; } }
From source file:org.kalypso.commons.time.PeriodUtils.java
License:Open Source License
/** * @return {@link Integer#MAX_VALUE} if the amount could not be determined. *///from www.j av a2 s . co m public static int findCalendarAmount(final Period period) { final int fieldCount = countNonZeroFields(period); if (fieldCount > 1) throw new IllegalArgumentException( "Unable to find calendar amount for periods with more than one field: " + period); //$NON-NLS-1$ if (period.getDays() != 0) return period.getDays(); if (period.getHours() != 0) return period.getHours(); if (period.getMillis() != 0) return period.getMillis(); if (period.getMinutes() != 0) return period.getMinutes(); if (period.getMonths() != 0) return period.getMonths(); if (period.getSeconds() != 0) return period.getSeconds(); if (period.getWeeks() != 0) return period.getWeeks(); if (period.getYears() != 0) return period.getYears(); return Integer.MAX_VALUE; }
From source file:org.kalypso.commons.time.PeriodUtils.java
License:Open Source License
public static FIELD findCalendarField(final Period period) { final int fieldCount = countNonZeroFields(period); if (fieldCount > 1) throw new IllegalArgumentException( "Unable to find calendar field for periods with more than one field: " + period); //$NON-NLS-1$ if (period.getDays() != 0) return FIELD.DAY_OF_MONTH; if (period.getHours() != 0) return FIELD.HOUR_OF_DAY; if (period.getMillis() != 0) return FIELD.MILLISECOND; if (period.getMinutes() != 0) return FIELD.MINUTE; if (period.getMonths() != 0) return FIELD.MONTH; if (period.getSeconds() != 0) return FIELD.SECOND; if (period.getWeeks() != 0) return FIELD.WEEK_OF_YEAR; if (period.getYears() != 0) return FIELD.YEAR; return null;/* w w w. j av a 2 s .com*/ }