Пример #1
0
 /**
  * Creates a new <code>Weeks</code> by parsing a string in the ISO8601 format 'PnW'.
  *
  * <p>The parse will accept the full ISO syntax of PnYnMnWnDTnHnMnS however only the weeks
  * component may be non-zero. If any other component is non-zero, an exception will be thrown.
  *
  * @param periodStr the period string, null returns zero
  * @return the period in weeks
  * @throws IllegalArgumentException if the string format is invalid
  */
 @FromString
 public static Weeks parseWeeks(String periodStr) {
   if (periodStr == null) {
     return Weeks.ZERO;
   }
   Period p = PARSER.parsePeriod(periodStr);
   return Weeks.weeks(p.getWeeks());
 }
Пример #2
0
 /** {@inheritDoc} */
 @Override
 public Number parse(String source) throws ParseException {
   if (source == null || source.length() == 0) {
     return null;
   }
   try {
     return formatter.parsePeriod(source).toDurationFrom(new Instant(0)).getMillis();
   } catch (Throwable t) {
     throw new ParseException(t.getMessage(), 0);
   }
 }
Пример #3
0
 protected void actionAdjustment() {
   String result =
       (String) JOptionPane.showInputDialog(this, "Enter an adjustment", "0 00:00:00.000");
   if (result != null && !result.isEmpty()) {
     try {
       Period adjustment = format_short.parsePeriod(result);
       DateTime start = new DateTime();
       DateTime end = start.plus(adjustment);
       TimeSpan ts = new TimeSpan(start, end);
       times.add(ts);
       period = period.plus(adjustment);
       updateTimes();
     } catch (IllegalArgumentException ex) {
       JOptionPane.showMessageDialog(this, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE);
     }
   }
 }