List of usage examples for org.joda.time Period toString
public String toString(PeriodFormatter formatter)
From source file:org.datanucleus.store.types.jodatime.converters.JodaPeriodStringConverter.java
License:Open Source License
public String toDatastoreType(Period per) { return per != null ? per.toString(ISOPeriodFormat.standard()) : null; }
From source file:org.ddialliance.ddiftp.util.Translator.java
License:Open Source License
/** * Creates a ISO8601 duration of the form PyYmMwWdDThHmMsS * /*w ww. j a va2s .c o m*/ * @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.supercsv.cellprocessor.joda.FmtPeriod.java
License:Apache License
/** * {@inheritDoc}// w w w . j a va 2 s . c o m * * @throws SuperCsvCellProcessorException * if value is null or not a Period */ public Object execute(final Object value, final CsvContext context) { validateInputNotNull(value, context); if (!(value instanceof Period)) { throw new SuperCsvCellProcessorException(Period.class, value, context, this); } final Period period = (Period) value; final String result; if (formatter != null) { result = period.toString(formatter); } else { result = period.toString(); } return next.execute(result, context); }