lib/Segment/Client.php
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);
  }
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);
  }
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 ) ; }
Formats a timestamp by making sure it is set
and converting it to iso8601.

The timestamp can be time in seconds `time()` or `microseconds(true)`.
any other input is considered an error and the method will return a new date.

Note: php's date() "u" format (for microseconds) has a bug in it
it always shows `.000` for microseconds since `date()` only accepts
ints, so we have to construct the date ourselves if microtime is passed.

@param  ts $timestamp - time in seconds (time())
Formats a timestamp by making sure it is set and converting it to iso8601 .