public static function D2tf($ndp, $days, &$sign, array &$ihmsf) {
    $nrs;
    $n;
    $rs;
    $rm;
    $rh;
    $a;
    $w;
    $ah;
    $am;
    $as;
    $af;

    /* Handle sign. */
    $sign = $days >= 0.0 ? '+' : '-';

    /* Interval in seconds. */
    $a = DAYSEC * abs($days);

    /* Pre-round if resolution coarser than 1s (then pretend ndp=1). */
    if ($ndp < 0) {
      $nrs = 1;
      for ($n = 1; $n <= -$ndp; $n++) {
        $nrs *= ($n == 2 || $n == 4) ? 6 : 10;
      }
      $rs = (double)$nrs;
      $w  = $a / $rs;
      $a  = $rs * intval($w);
    }

    /* Express the unit of each field in resolution units. */
    $nrs = 1;
    for ($n = 1; $n <= $ndp; $n++) {
      $nrs *= 10;
    }
    $rs = (double)$nrs;
    $rm = $rs * 60.0;
    $rh = $rm * 60.0;

    /* Round the interval and express in resolution units. */
    $a = round($rs * $a);

    /* Break into fields. */
    $ah = $a / $rh;
    $ah = intval($ah);
    $a -= $ah * $rh;
    $am = $a / $rm;
    $am = intval($am);
    $a -= $am * $rm;
    $as = $a / $rs;
    $as = intval($as);
    $af = $a - $as * $rs;

    /* Return results. */
    $ihmsf[0] = (int)$ah;
    $ihmsf[1] = (int)$am;
    $ihmsf[2] = (int)$as;
    $ihmsf[3] = (int)$af;

    return;
  }