Segment_Client::formatTime PHP Method

formatTime() private method

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.
private formatTime ( $ts )
    private function formatTime($ts)
    {
        // time()
        if ($ts == null || !$ts) {
            $ts = time();
        }
        if (filter_var($ts, FILTER_VALIDATE_INT) !== false) {
            return date("c", (int) $ts);
        }
        // anything else try to strtotime the date.
        if (filter_var($ts, FILTER_VALIDATE_FLOAT) === false) {
            if (is_string($ts)) {
                return date("c", strtotime($ts));
            } else {
                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);
    }