Example #1
0
function test_findDateTime()
{
    appendTestMessage(NEW_LINE_LOG . " >> Tests find date-time in csv lines..." . NEW_LINE_LOG);
    appendTestMessage("tIme=2013-03-25T15:27:04Z");
    $ret = findDateTime("tIme=2013-03-25T15:27:04Z");
    $expected = "2013-03-25T15:27:04Z";
    if ($ret == $expected) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("xytIme=2013-03-25T15:27:04Z;xy");
    $ret = findDateTime("xytIme=2013-03-25T15:27:04Z;xy");
    if ($ret == $expected) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("xy;tIme=2013-03-25T15:27:04Z;xy;xy");
    $ret = findDateTime("xy;tIme=2013-03-25T15:27:04Z;xy;xy");
    if ($ret == $expected) {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    appendTestMessage("xy;nothing=2013-03-25T15:27:04Z;xy;xy");
    $ret = findDateTime("xy;nothing=2013-03-25T15:27:04Z;xy;xy");
    if ($ret == '') {
        appendTestMessage("- ok");
    } else {
        appendTestMessage("- failed");
        return false;
    }
    return true;
}
Example #2
0
/**
 * Get a single track for a user
 *
 * @param type $user
 * @param type $date '2012-03-03' (optional) Takes today if ommited
 * @param type $lastSentTrackPointTime a dateTime (optional). Retrurns only way points after that time.
 * @return string track as CSV
 */
function getTrack($user, $date, $lastSentTrackPointTime)
{
    if (isNullOrEmptyString($date)) {
        // $date = date("Y-m-d");
        $date = getDateForTimezoneOffset($user, '', true);
        logMessage("Missing parameter date. Take the track from today: {$date}");
    }
    $trackFile = USER_DIR . DIRECTORY_SEPARATOR . $user . DIRECTORY_SEPARATOR . $date . '.csv';
    if (!is_file($trackFile)) {
        logMessage("No track file {$trackFile} for user: "******"No line number given. Return whole track.");
        return $positionCSVlines;
    }
    $lastSentTime = strtotime($lastSentTrackPointTime);
    $resultBuffer = '';
    $lines = explode(PHP_EOL, $positionCSVlines);
    $count = count($lines);
    for ($i = 0; $i < $count; $i++) {
        // Compare the time
        // lat=47.50457163540115;lon=11.071390274487026;bearing=171.61432;speed=0.7065948;altitude=1067.652498529502;accuracy=6.0;time=2013-03-03T15:48:47.484
        $line = trim($lines[$i]);
        $timeStampStringInLine = findDateTime($line);
        if (!isNullOrEmptyString($timeStampStringInLine)) {
            $timeStampInLine = strtotime($timeStampStringInLine);
            if ($timeStampInLine <= $lastSentTime) {
                continue;
            }
        }
        if ($resultBuffer != '') {
            $resultBuffer .= PHP_EOL;
        }
        $resultBuffer .= $line;
    }
    return $resultBuffer;
}