code: public static TimeUnit findBestUnit(long time) {
          for (int i = 1; i < unitOrder.length; i++) {
              if (unitBounds[unitOrder[i].ordinal()] > time) {
                  return unitOrder[i - 1];
              }
          }
          return unitOrder[unitOrder.length - 1];
      }
docs: Identify a TimeUnit that is convenient for the display of the supplied
  nanosecond value.
  <p>
  The best unit is the one which has no zeros after the decimal, and at
  most two digits before.
  <p>
  The following are examples of "best" displays:
  <ul>
  <li>1.2345 seconds
  <li>0.7247 microseconds
  <li>82.443 milliseconds
  </ul>
  
  in contrast, the following would not be suggested as "best" units:
  
  <ul>
  <li>623.2345 milliseconds
  <li>0.0000007247 seconds
  <li>825543.000 nanoseconds
  </ul>
  
  It is suggested that you should find the best unit for the shortest time
  value you will have in your data, and then use that same unit to display
  all times.
  <p>
  For example, if you have the following nanosecond times
  <code>[5432, 8954228, 665390, 492009]</code> you should find the unit for
  the shortest (5432) which will be TimeUnit.MICROSECONDS, and end up with
  the display of:
  
  <pre>
  5.432
  8954.228
  665.390
  492.009
  </pre>
  
  @param time
  the time to display (in nanoseconds)
  @return A Time Unit that will display the nanosecond time well.