List of usage examples for org.joda.time PeriodType forFields
public static synchronized PeriodType forFields(DurationFieldType[] types)
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.ddialliance.ddiftp.util.Translator.java
License:Open Source License
/** * Creates a ISO8601 duration of the form PyYmMwWdDThHmMsS * //from w ww. j a v a 2s . c om * @param start * @param end * @return ISO8601 duration * @throws DDIFtpException */ public static String formatIso8601Duration(long start, long end) throws DDIFtpException { DateTime startTime = new DateTime(start); DateTime endTime = new DateTime(end); DurationFieldType[] types = { DurationFieldType.years(), DurationFieldType.months(), DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes(), DurationFieldType.seconds() }; PeriodType periodType = PeriodType.forFields(types); try { Period period = new Interval(startTime, endTime).toPeriod(periodType); PeriodFormatter isoPeriodFormat = ISOPeriodFormat.standard(); isoPeriodFormat.withLocale(getLocale()); return period.toString(isoPeriodFormat); } catch (Exception e) { throw new DDIFtpException("translate.period.intevalerror", new Object[] { start, end }, e); } }
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()); ;//w w w .j a v a 2s. c o m 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 }); }