Examples of PeriodFormatter


Examples of org.joda.time.format.PeriodFormatter

    }

    @After
    public void testExit() {
        Duration duration = new Duration(testFunctionStart, new DateTime());
        PeriodFormatter periodFormatter = new PeriodFormatterBuilder()
                .appendLiteral("Finished "
                        .concat(getTestDescription()).concat(" in " ))
                .printZeroAlways()
                .appendMinutes()
                .appendSuffix(" minutes, ")
                .appendSeconds()
                .appendSuffix(" seconds, ")
                .appendMillis()
                .appendSuffix("ms")
                .toFormatter();
        log.info(periodFormatter.print(duration.toPeriod()));
    }
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

        if (endField == null) {
            endField = startField;
        }

        if (startField == IntervalField.YEAR && endField == IntervalField.MONTH) {
            PeriodFormatter periodFormatter = INTERVAL_YEAR_MONTH_FORMATTER;
            return parsePeriodMonths(value, periodFormatter, startField, endField);
        }
        if (startField == IntervalField.YEAR && endField == IntervalField.YEAR) {
            return parsePeriodMonths(value, INTERVAL_YEAR_FORMATTER, startField, endField);
        }
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

                builder.appendSecondsWithOptionalMillis();
                parsers.add(builder.toParser());
        }
        //CHECKSTYLE.ON

        return new PeriodFormatter(builder.toPrinter(), new OrderedPeriodParser(parsers));
    }
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

*
* @author rup
*/
public class JodaTimeFormatter {
    public static String format(Period period) {
        PeriodFormatter output = new PeriodFormatterBuilder()
                .appendDays()
                .appendSuffix(" day", " days")
                .appendSeparator(", ")
                .appendHours()
                .appendSuffix(" hour", " hours")
                .appendSeparator(", ")
                .appendMinutes()
                .appendSuffix(" minute", " minutes")
                .appendSeparator(", ")
                .appendSeconds()
                .appendSuffix(" second", " seconds")
                .toFormatter();
        return output.print(period);
    }
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

        Object source = e.getPath().getLastPathComponent();
        if(source instanceof Appointable) {
          Appointable appointable = (Appointable) source;
          appointmentsTabelModel.setAppointable(appointable);
         
          PeriodFormatter periodFormatter = PeriodFormat.getDefault();
         
          String statusMessage =
            "Wartezeit: " + periodFormatter.print(appointable.getSchedule().getWaitTime().toPeriod());
         
          statusBar.setMessage(statusMessage);
        }
      }     
    };
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

     * @return the millisecond duration
     * @throws ClassCastException if the object is invalid
     */
    public void setInto(ReadWritablePeriod period, Object object, Chronology chrono) {
        String str = (String) object;
        PeriodFormatter parser = ISOPeriodFormat.standard();
        period.clear();
        int pos = parser.parseInto(period, str, 0);
        if (pos < str.length()) {
            if (pos < 0) {
                // Parse again to get a better exception thrown.
                parser.withParseType(period.getPeriodType()).parseMutablePeriod(str);
            }
            throw new IllegalArgumentException("Invalid format: \"" + str + '"');
        }
    }
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

            throw new IllegalArgumentException("Format invalid: " + str);
        }

        DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser();
        dateTimeParser = dateTimeParser.withChronology(chrono);
        PeriodFormatter periodParser = ISOPeriodFormat.standard();
        long startInstant = 0, endInstant = 0;
        Period period = null;
        Chronology parsedChrono = null;
       
        // before slash
        char c = leftStr.charAt(0);
        if (c == 'P' || c == 'p') {
            period = periodParser.withParseType(getPeriodType(leftStr)).parsePeriod(leftStr);
        } else {
            DateTime start = dateTimeParser.parseDateTime(leftStr);
            startInstant = start.getMillis();
            parsedChrono = start.getChronology();
        }
       
        // after slash
        c = rightStr.charAt(0);
        if (c == 'P' || c == 'p') {
            if (period != null) {
                throw new IllegalArgumentException("Interval composed of two durations: " + str);
            }
            period = periodParser.withParseType(getPeriodType(rightStr)).parsePeriod(rightStr);
            chrono = (chrono != null ? chrono : parsedChrono);
            endInstant = chrono.add(period, startInstant, 1);
        } else {
            DateTime end = dateTimeParser.parseDateTime(rightStr);
            endInstant = end.getMillis();
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

      .toFormatter();

  public static String print(DateTime dateTime) {
    Duration duration = new Duration(dateTime, null);

    PeriodFormatter formatter = MONTHS;
    if (duration.isShorterThan(Duration.standardMinutes(1))) {
      formatter = SECONDS;
    }

    else if (duration.isShorterThan(Duration.standardHours(1))) {
      formatter = MINUTES;
    }

    else if (duration.isShorterThan(Duration.standardDays(1))) {
      formatter = HOURS;
    }

    else if (duration.isShorterThan(Duration.standardDays(7))) {
      formatter = DAYS;
    }

    else if (duration.isShorterThan(Duration.standardDays(30))) {
      formatter = WEEKS;
    }

    Period period = new Period(duration, new DateTime());
    return formatter.print(period);
  }
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

     * @return the millisecond duration
     * @throws ClassCastException if the object is invalid
     */
    public void setInto(ReadWritablePeriod period, Object object, Chronology chrono) {
        String str = (String) object;
        PeriodFormatter parser = ISOPeriodFormat.standard();
        period.clear();
        int pos = parser.parseInto(period, str, 0);
        if (pos < str.length()) {
            if (pos < 0) {
                // Parse again to get a better exception thrown.
                parser.withParseType(period.getPeriodType()).parseMutablePeriod(str);
            }
            throw new IllegalArgumentException("Invalid format: \"" + str + '"');
        }
    }
View Full Code Here

Examples of org.joda.time.format.PeriodFormatter

            throw new IllegalArgumentException("Format invalid: " + str);
        }

        DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser();
        dateTimeParser = dateTimeParser.withChronology(chrono);
        PeriodFormatter periodParser = ISOPeriodFormat.standard();
        long startInstant = 0, endInstant = 0;
        Period period = null;
        Chronology parsedChrono = null;
       
        // before slash
        char c = leftStr.charAt(0);
        if (c == 'P' || c == 'p') {
            period = periodParser.withParseType(getPeriodType(leftStr)).parsePeriod(leftStr);
        } else {
            DateTime start = dateTimeParser.parseDateTime(leftStr);
            startInstant = start.getMillis();
            parsedChrono = start.getChronology();
        }
       
        // after slash
        c = rightStr.charAt(0);
        if (c == 'P' || c == 'p') {
            if (period != null) {
                throw new IllegalArgumentException("Interval composed of two durations: " + str);
            }
            period = periodParser.withParseType(getPeriodType(rightStr)).parsePeriod(rightStr);
            chrono = (chrono != null ? chrono : parsedChrono);
            endInstant = chrono.add(period, startInstant, 1);
        } else {
            DateTime end = dateTimeParser.parseDateTime(rightStr);
            endInstant = end.getMillis();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.