@Test
 public void testLANG984() { // Long durations
   assertEquals("0", DurationFormatUtils.formatDuration(0, "S"));
   assertEquals(
       Integer.toString(Integer.MAX_VALUE),
       DurationFormatUtils.formatDuration(Integer.MAX_VALUE, "S"));
   long maxIntPlus = Integer.MAX_VALUE;
   maxIntPlus++;
   assertEquals(Long.toString(maxIntPlus), DurationFormatUtils.formatDuration(maxIntPlus, "S"));
   assertEquals(
       Long.toString(Long.MAX_VALUE), DurationFormatUtils.formatDuration(Long.MAX_VALUE, "S"));
 }
 @Test
 public void testLANG982() { // More than 3 millisecond digits following a second
   assertEquals("61.999", DurationFormatUtils.formatDuration(61999, "s.S"));
   assertEquals("1 1999", DurationFormatUtils.formatDuration(61999, "m S"));
   assertEquals("61.999", DurationFormatUtils.formatDuration(61999, "s.SSS"));
   assertEquals("1 1999", DurationFormatUtils.formatDuration(61999, "m SSS"));
   assertEquals("61.0999", DurationFormatUtils.formatDuration(61999, "s.SSSS"));
   assertEquals("1 1999", DurationFormatUtils.formatDuration(61999, "m SSSS"));
   assertEquals("61.00999", DurationFormatUtils.formatDuration(61999, "s.SSSSS"));
   assertEquals("1 01999", DurationFormatUtils.formatDuration(61999, "m SSSSS"));
 }
  public static void main(String[] args) throws Exception {
    IndexArgs indexArgs = new IndexArgs();

    CmdLineParser parser =
        new CmdLineParser(indexArgs, ParserProperties.defaults().withUsageWidth(90));

    try {
      parser.parseArgument(args);
    } catch (CmdLineException e) {
      System.err.println(e.getMessage());
      parser.printUsage(System.err);
      System.err.println(
          "Example: "
              + IndexCollection.class.getSimpleName()
              + parser.printExample(OptionHandlerFilter.REQUIRED));
      return;
    }

    if (indexArgs.docvectors && !indexArgs.positions) {
      LOG.warn(
          "to store docVectors you must store positions too. With this configuration, both positions and docVectors will not be stored!");
    }

    final long start = System.nanoTime();
    MultithreadedIndexer indexer = new MultithreadedIndexer(indexArgs);

    LOG.info("Index path: " + indexArgs.index);
    LOG.info("Threads: " + indexArgs.threads);
    LOG.info("Keep Stopwords: " + indexArgs.keepstop);
    LOG.info("Positions: " + indexArgs.positions);
    LOG.info("Store docVectors: " + indexArgs.docvectors);
    LOG.info("Optimize (merge segments): " + indexArgs.optimize);

    LOG.info("Starting indexer...");

    int numIndexed = indexer.run();
    final long durationMillis =
        TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
    LOG.info(
        "Total "
            + numIndexed
            + " documents indexed in "
            + DurationFormatUtils.formatDuration(durationMillis, "HH:mm:ss"));
  }
 public String toString() {
   return DurationFormatUtils.formatDuration(duration.toMillis(), "HH:mm:ss");
 }
  @Test
  public void testFormatDuration() {
    long duration = 0;
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "y"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "M"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "d"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "H"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "m"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "s"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "S"));
    assertEquals("0000", DurationFormatUtils.formatDuration(duration, "SSSS"));
    assertEquals("0000", DurationFormatUtils.formatDuration(duration, "yyyy"));
    assertEquals("0000", DurationFormatUtils.formatDuration(duration, "yyMM"));

    duration = 60 * 1000;
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "y"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "M"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "d"));
    assertEquals("0", DurationFormatUtils.formatDuration(duration, "H"));
    assertEquals("1", DurationFormatUtils.formatDuration(duration, "m"));
    assertEquals("60", DurationFormatUtils.formatDuration(duration, "s"));
    assertEquals("60000", DurationFormatUtils.formatDuration(duration, "S"));
    assertEquals("01:00", DurationFormatUtils.formatDuration(duration, "mm:ss"));

    final Calendar base = Calendar.getInstance();
    base.set(2000, 0, 1, 0, 0, 0);
    base.set(Calendar.MILLISECOND, 0);

    final Calendar cal = Calendar.getInstance();
    cal.set(2003, 1, 1, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    duration =
        cal.getTime().getTime() - base.getTime().getTime(); // duration from 2000-01-01 to cal
    // don't use 1970 in test as time zones were less reliable in 1970 than now
    // remember that duration formatting ignores time zones, working on strict hour lengths
    final int days = 366 + 365 + 365 + 31;
    assertEquals("0 0 " + days, DurationFormatUtils.formatDuration(duration, "y M d"));
  }