private static PeriodFormatter buildNonRegExFormatter(ResourceBundle b, Locale locale) { String[] variants = retrieveVariants(b); return new PeriodFormatterBuilder() .appendYears() .appendSuffix(b.getString("PeriodFormat.year"), b.getString("PeriodFormat.years")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendMonths() .appendSuffix(b.getString("PeriodFormat.month"), b.getString("PeriodFormat.months")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendWeeks() .appendSuffix(b.getString("PeriodFormat.week"), b.getString("PeriodFormat.weeks")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendDays() .appendSuffix(b.getString("PeriodFormat.day"), b.getString("PeriodFormat.days")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendHours() .appendSuffix(b.getString("PeriodFormat.hour"), b.getString("PeriodFormat.hours")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendMinutes() .appendSuffix(b.getString("PeriodFormat.minute"), b.getString("PeriodFormat.minutes")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendSeconds() .appendSuffix(b.getString("PeriodFormat.second"), b.getString("PeriodFormat.seconds")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendMillis() .appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")) .toFormatter().withLocale(locale); }
private static PeriodFormatter buildNonRegExFormatter(ResourceBundle b, Locale locale) { String[] variants = retrieveVariants(b); return new PeriodFormatterBuilder() .appendYears() .appendSuffix(b.getString("PeriodFormat.year"), b.getString("PeriodFormat.years")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendMonths() .appendSuffix(b.getString("PeriodFormat.month"), b.getString("PeriodFormat.months")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendWeeks() .appendSuffix(b.getString("PeriodFormat.week"), b.getString("PeriodFormat.weeks")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendDays() .appendSuffix(b.getString("PeriodFormat.day"), b.getString("PeriodFormat.days")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendHours() .appendSuffix(b.getString("PeriodFormat.hour"), b.getString("PeriodFormat.hours")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendMinutes() .appendSuffix(b.getString("PeriodFormat.minute"), b.getString("PeriodFormat.minutes")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendSeconds() .appendSuffix(b.getString("PeriodFormat.second"), b.getString("PeriodFormat.seconds")) .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) .appendMillis() .appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")) .toFormatter().withLocale(locale); }
builder.appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")); return builder.toFormatter().withLocale(locale);
builder.appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")); return builder.toFormatter().withLocale(locale);
public JacksonJodaPeriodFormat(JacksonJodaPeriodFormat base, Locale locale) { super(base, locale); PeriodFormatter f = base._formatter; if (locale != null) { f = f.withLocale(locale); } _formatter = f; }
public PeriodFormatter createFormatter(SerializerProvider provider) { PeriodFormatter formatter = _formatter; if (!_explicitLocale) { Locale loc = provider.getLocale(); if (loc != null && !loc.equals(_locale)) { formatter = formatter.withLocale(loc); } } return formatter; }
Period period = new Period(new LocalDate(2013, 4, 11), LocalDate.now()); PeriodFormatter formatter = PeriodFormat.wordBased(Locale.GERMANY); System.out.println(formatter.print(period)); // output: 1 Jahr, 2 Monate und 3 Wochen formatter = formatter.withLocale(Locale.ENGLISH); System.out.println(formatter.print(period)); // output: 1 Jahr, 2 Monate und 3 Wochen (bug???) formatter = PeriodFormat.wordBased(Locale.ENGLISH); System.out.println(formatter.print(period)); // output: 1 year, 2 months and 3 weeks
public String getFormattedElapsedRunTime() { return periodFormatter.withLocale(locale).print(new Period(descriptor.getElapsedRunTime())); }
/** * Interprets a ISO8601 duration value relative to a given timestamp. * * @param durationString * The duration, as a string. * @param timestamp * The unix timestamp we should apply the duration to. * * @return the new timestamp, after the duration is applied In Seconds. * * @throws IllegalArgumentException */ public static long parseDuration(String durationString, long timestamp) throws IllegalArgumentException { boolean haveMinus = false; if (durationString.startsWith("-")) { durationString = durationString.substring(1); haveMinus = true; } PeriodFormatter periodFormatter = ISOPeriodFormat.standard().withLocale(new Locale("UTC")); Period period = periodFormatter.parsePeriod(durationString); DateTime dt = new DateTime(timestamp * 1000, DateTimeZone.UTC); DateTime result = null; if (haveMinus) { result = dt.minus(period); } else { result = dt.plus(period); } return result.getMillis() / 1000; }
/** * Constructs a new <code>DurationFormatter</code> instance. * * @param locale * the locale the formatter must be constructed in. */ public DurationFormatter(Locale locale) { super(); ResourceBundle bundle = ResourceBundle.getBundle(getClass().getName(), locale); PeriodFormatterBuilder builder = new PeriodFormatterBuilder(); builder.appendDays(); builder.appendSuffix(" " + bundle.getString("day"), " " + bundle.getString("days")); builder.appendSeparator(" "); builder.appendHours(); builder.appendSuffix(" " + bundle.getString("hour"), " " + bundle.getString("hours")); builder.appendSeparator(" "); builder.appendMinutes(); builder.appendSuffix(" " + bundle.getString("minute"), " " + bundle.getString("minutes")); this.formatter = builder.toFormatter().withLocale(locale); }
builder.appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")); return builder.toFormatter().withLocale(locale);
builder.appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")); return builder.toFormatter().withLocale(locale);