code: private Duration convertFormat(long totalTime, TimeUnit format)
     {
        double duration = totalTime;
  
        switch (format)
        {
           case MINUTES:
           case ELAPSED_MINUTES:
           {
              duration /= (60 * 1000);
              break;
           }
  
           case HOURS:
           case ELAPSED_HOURS:
           {
              duration /= (60 * 60 * 1000);
              break;
           }
  
           case DAYS:
           {
              double minutesPerDay = getMinutesPerDay();
              if (minutesPerDay != 0)
              {
                 duration /= (minutesPerDay * 60 * 1000);
              }
              else
              {
                 duration = 0;
              }
              break;
           }
  
           case WEEKS:
           {
              double minutesPerWeek = getMinutesPerWeek();
              if (minutesPerWeek != 0)
              {
                 duration /= (minutesPerWeek * 60 * 1000);
              }
              else
              {
                 duration = 0;
              }
              break;
           }
  
           case MONTHS:
           {
              double daysPerMonth = getParentFile().getProjectProperties().getDaysPerMonth().doubleValue();
              double minutesPerDay = getMinutesPerDay();
              if (daysPerMonth != 0 && minutesPerDay != 0)
              {
                 duration /= (daysPerMonth * minutesPerDay * 60 * 1000);
              }
              else
              {
                 duration = 0;
              }
              break;
           }
  
           case ELAPSED_DAYS:
           {
              duration /= (24 * 60 * 60 * 1000);
              break;
           }
  
           case ELAPSED_WEEKS:
           {
              duration /= (7 * 24 * 60 * 60 * 1000);
              break;
           }
  
           case ELAPSED_MONTHS:
           {
              duration /= (30 * 24 * 60 * 60 * 1000);
              break;
           }
  
           default:
           {
              throw new IllegalArgumentException("TimeUnit " + format + " not supported");
           }
        }
  
        return (Duration.getInstance(duration, format));
     }
docs: Utility method used to convert an integer time representation into a
  Duration instance.
  
  @param totalTime integer time representation
  @param format required time format
  @return new Duration instance