This method is called to format a duration.

@param value duration value
@return formatted duration value
191353
private String formatDuration(Object value)
   {
      String result = null;
      if (value instanceof Duration)
      {
         Duration duration = (Duration) value;
         result = m_formats.getDurationDecimalFormat().format(duration.getDuration()) + formatTimeUnit(duration.getUnits());
      }
      return result;
   }
305895
public static final Duration parseDuration(String value)
   {
      return value == null ? null : Duration.getInstance(Double.parseDouble(value), TimeUnit.DAYS);
   }
579319
private String formatRate(Rate value)
   {
      String result = null;
      if (value != null)
      {
         StringBuilder buffer = new StringBuilder(m_formats.getCurrencyFormat().format(value.getAmount()));
         buffer.append("/");
         buffer.append(formatTimeUnit(value.getUnits()));
         result = buffer.toString();
      }
      return (result);
   }
789842
public static final Duration parseDuration(ProjectFile file, TimeUnit defaultUnits, String value)
   {
      Duration result = null;
      XsdDuration xsd = null;

      if (value != null && value.length() != 0)
      {
         try
         {
            xsd = new XsdDuration(value);
         }

         catch (IllegalArgumentException ex)
         {
            // The duration is malformed.
            // MS Project simply ignores values like this.
         }
      }

      if (xsd != null)
      {
         TimeUnit units = TimeUnit.DAYS;

         if (xsd.getSeconds() != 0 || xsd.getMinutes() != 0)
         {
            units = TimeUnit.MINUTES;
         }

         if (xsd.getHours() != 0)
         {
            units = TimeUnit.HOURS;
         }

         if (xsd.getDays() != 0)
         {
            units = TimeUnit.DAYS;
         }

         if (xsd.getMonths() != 0)
         {
            units = TimeUnit.MONTHS;
         }

         if (xsd.getYears() != 0)
         {
            units = TimeUnit.YEARS;
         }

         double duration = 0;

         switch (units)
         {
            case YEARS:
            {
               //
               // Calculate the number of years
               //
               duration += xsd.getYears();
               duration += ((double) xsd.getMonths() / 12);
               duration += ((double) xsd.getDays() / 365);
               duration += ((double) xsd.getHours() / (365 * 24));
               duration += ((double) xsd.getMinutes() / (365 * 24 * 60));
               duration += (xsd.getSeconds() / (365 * 24 * 60 * 60));
               break;
            }

            case ELAPSED_YEARS:
            {
               //
               // Calculate the number of years
               //
               duration += xsd.getYears();
               duration += ((double) xsd.getMonths() / 12);
               duration += ((double) xsd.getDays() / 365);
               duration += ((double) xsd.getHours() / (365 * 24));
               duration += ((double) xsd.getMinutes() / (365 * 24 * 60));
               duration += (xsd.getSeconds() / (365 * 24 * 60 * 60));
               break;
            }

            case MONTHS:
            {
               //
               // Calculate the number of months
               //
               duration += (xsd.getYears() * 12);
               duration += xsd.getMonths();
               duration += ((double) xsd.getDays() / 30);
               duration += ((double) xsd.getHours() / (30 * 24));
               duration += ((double) xsd.getMinutes() / (30 * 24 * 60));
               duration += (xsd.getSeconds() / (30 * 24 * 60 * 60));
               break;
            }

            case ELAPSED_MONTHS:
            {
               //
               // Calculate the number of months
               //
               duration += (xsd.getYears() * 12);
               duration += xsd.getMonths();
               duration += ((double) xsd.getDays() / 30);
               duration += ((double) xsd.getHours() / (30 * 24));
               duration += ((double) xsd.getMinutes() / (30 * 24 * 60));
               duration += (xsd.getSeconds() / (30 * 24 * 60 * 60));
               break;
            }

            case WEEKS:
            {
               //
               // Calculate the number of weeks
               //
               duration += (xsd.getYears() * 52);
               duration += (xsd.getMonths() * 4);
               duration += ((double) xsd.getDays() / 7);
               duration += ((double) xsd.getHours() / (7 * 24));
               duration += ((double) xsd.getMinutes() / (7 * 24 * 60));
               duration += (xsd.getSeconds() / (7 * 24 * 60 * 60));
               break;
            }

            case ELAPSED_WEEKS:
            {
               //
               // Calculate the number of weeks
               //
               duration += (xsd.getYears() * 52);
               duration += (xsd.getMonths() * 4);
               duration += ((double) xsd.getDays() / 7);
               duration += ((double) xsd.getHours() / (7 * 24));
               duration += ((double) xsd.getMinutes() / (7 * 24 * 60));
               duration += (xsd.getSeconds() / (7 * 24 * 60 * 60));
               break;
            }

            case DAYS:
            {
               //
               // Calculate the number of days
               //
               duration += (xsd.getYears() * 365);
               duration += (xsd.getMonths() * 30);
               duration += xsd.getDays();
               duration += ((double) xsd.getHours() / 24);
               duration += ((double) xsd.getMinutes() / (24 * 60));
               duration += (xsd.getSeconds() / (24 * 60 * 60));
               break;
            }

            case ELAPSED_DAYS:
            {
               //
               // Calculate the number of days
               //
               duration += (xsd.getYears() * 365);
               duration += (xsd.getMonths() * 30);
               duration += xsd.getDays();
               duration += ((double) xsd.getHours() / 24);
               duration += ((double) xsd.getMinutes() / (24 * 60));
               duration += (xsd.getSeconds() / (24 * 60 * 60));
               break;
            }

            case HOURS:
            case ELAPSED_HOURS:
            {
               //
               // Calculate the number of hours
               //
               duration += (xsd.getYears() * (365 * 24));
               duration += (xsd.getMonths() * (30 * 24));
               duration += (xsd.getDays() * 24);
               duration += xsd.getHours();
               duration += ((double) xsd.getMinutes() / 60);
               duration += (xsd.getSeconds() / (60 * 60));
               break;
            }

            case MINUTES:
            case ELAPSED_MINUTES:
            {
               //
               // Calculate the number of minutes
               //
               duration += (xsd.getYears() * (365 * 24 * 60));
               duration += (xsd.getMonths() * (30 * 24 * 60));
               duration += (xsd.getDays() * (24 * 60));
               duration += (xsd.getHours() * 60);
               duration += xsd.getMinutes();
               duration += (xsd.getSeconds() / 60);
               break;
            }

            default:
            {
               break;
            }
         }

         //
         // Convert from a duration in hours to a duration
         // expressed in the default duration units
         //
         ProjectProperties properties = file.getProjectProperties();
         if (defaultUnits == null)
         {
            defaultUnits = properties.getDefaultDurationUnits();
         }

         result = Duration.convertUnits(duration, units, defaultUnits, properties);
      }

      return (result);
   }
776394
public CellFormatResult format(final String formatPattern, final String value) {
        return format(formatPattern, value, Locale.getDefault());
    }
489038
public static MeterValue valueOf(String value) {
        if (isNumber(value)) {
            return new MeterValue(Long.parseLong(value));
        }
        return new MeterValue(durationConverter.convert(value));
    }
1248339
public static String formatDate(long value) {
        synchronized (HttpDateFormat.class) {
            Date dateValue = new Date(value);
            return FORMAT.format(dateValue);
        }
    }
776751
public static Duration formattedStringToDuration(final String formattedDuration) {
        if (formattedDuration == null) {
            return null;
        }

        final TemporalAccessor ta = DateTimeFormatter.ofPattern(DURATION_FORMAT).parse(formattedDuration.trim());
        return Duration.between(LocalTime.MIDNIGHT, LocalTime.from(ta));
    }
1158877
@UserFunction( "apoc.temporal.formatDuration" )
    @Description( "apoc.temporal.formatDuration(input, format) | Format a Duration" )
    public String formatDuration(
            @Name("input") Object input,
            @Name("format") String format
    ) {
        try {
            LocalDateTime midnight = LocalDateTime.of(0, 1, 1, 0, 0, 0, 0);
            LocalDateTime newDuration = midnight.plus( (DurationValue) input );

            DateTimeFormatter formatter = getOrCreate(format);

            return newDuration.format(formatter);
        } catch (Exception e){
        throw new RuntimeException("Available formats are:\n" +
                String.join("\n", getTypes()) +
                "\nSee also: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/mapping-date-format.html#built-in-date-formats " +
                "and https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html");
        }
    }
323876
function (value) {
        /// <summary>Formats a DateTime or DateTimeOffset value a string.</summary>
        /// <param name="value" type="Date" mayBeNull="false">Value to format.</param>
        /// <returns type="String">Formatted text.</returns>
        /// <remarks>If the value is already as string it's returned as-is.</remarks>

        if (typeof value === "string") {
            return value;
        }

        var hasOffset = isDateTimeOffset(value);
        var offset = getCanonicalTimezone(value.__offset);
        if (hasOffset && offset !== "Z") {
            // We're about to change the value, so make a copy.
            value = new Date(value.valueOf());

            var timezone = parseTimezone(offset);
            var hours = value.getUTCHours() + (timezone.d * timezone.h);
            var minutes = value.getMinutes() + (timezone.d * timezone.m);

            value.setUTCHours(hours, minutes);
        } else if (!hasOffset) {
            // Don't suffix a 'Z' for Edm.DateTime values.
            offset = "";
        }

        var year = value.getUTCFullYear();
        var month = value.getUTCMonth() + 1;
        var sign = "";
        if (year <= 0) {
            year = -(year - 1);
            sign = "-";
        }

        var ms = formatMilliseconds(value.getUTCMilliseconds(), value.__ns);

        return sign +
            formatNumberWidth(year, 4) + "-" +
            formatNumberWidth(month, 2) + "-" +
            formatNumberWidth(value.getUTCDate(), 2) + "T" +
            formatNumberWidth(value.getUTCHours(), 2) + ":" +
            formatNumberWidth(value.getUTCMinutes(), 2) + ":" +
            formatNumberWidth(value.getUTCSeconds(), 2) +
            ms + offset;
    }
102280
@Override
    public String tagValue(String value) {
        String formattedValue = StringEscapeUtils.escapeJson(delegate.tagValue(value));
        return StringUtils.truncate(formattedValue, TAG_VALUE_MAX_LENGTH);
    }
593211
@Override
  public DurationFormatterFactory setLocale(String localeName) {
    if (!localeName.equals(this.localeName)) {
      this.localeName = localeName;
      if (builder != null) {
          builder = builder.withLocale(localeName);
      }
      if (formatter != null) {
          formatter = formatter.withLocale(localeName);
      }
      reset();
    }
    return this;
  }
745302
public <N extends Number> CellFormatResult format(final String formatPattern, final N value) {
        return format(formatPattern, value, Locale.getDefault());
    }
870523
public static final Duration parseDuration(String value)
   {
      Duration result = null;
      if (value != null)
      {
         int split = value.indexOf(' ');
         if (split != -1)
         {
            double durationValue = Double.parseDouble(value.substring(0, split));
            TimeUnit durationUnits = parseTimeUnits(value.substring(split + 1));

            result = Duration.getInstance(durationValue, durationUnits);

         }
      }
      return result;
   }
150836
public static String formatDurationOnSecond(@NotNull Date startDate, @NotNull Date endDate) {
		return DurationFormatUtils.formatDuration(endDate.getTime() - startDate.getTime(), "HH:mm:ss");
	}
1107771
def duration=(value)
      new_duration = value.to_s.split(":").reverse
      s, m = new_duration
      self[:duration] = (s.to_i + (m.to_i*60))
    end
161134
public static ZonedDateTime convertToZonedDateTime(final String value) {
        val dt = DateTimeUtils.zonedDateTimeOf(value);
        if (dt != null) {
            return dt;
        }
        val lt = DateTimeUtils.localDateTimeOf(value);
        return DateTimeUtils.zonedDateTimeOf(lt.atZone(ZoneOffset.UTC));
    }