private function formatTime($ts) {
    // time()
    if (null == $ts || !$ts) {
      $ts = time();
    }
    if (false !== filter_var($ts, FILTER_VALIDATE_INT)) {
      return date("c", (int) $ts);
    }

    // anything else try to strtotime the date.
    if (false === filter_var($ts, FILTER_VALIDATE_FLOAT)) {
      if (is_string($ts)) {
        return date("c", strtotime($ts));
      }
  
      return date("c");
    }

    // fix for floatval casting in send.php
    $parts = explode(".", (string)$ts);
    if (!isset($parts[1])) {
      return date("c", (int)$parts[0]);
    }

    // microtime(true)
    $sec = (int)$parts[0];
    $usec = (int)$parts[1];
    $fmt = sprintf("Y-m-d\\TH:i:s%sP", $usec);

    return date($fmt, (int)$sec);
  }