Skip to content

Commit

Permalink
Update timestamp of locationprovider
Browse files Browse the repository at this point in the history
This adds the possibility to support timestamps with and without milliseconds as well as textual datetime descriptions.
This is needed as different clients use different formats and with this they don't need different parameters.
For example Osmand uses timestamps with milliseconds and GPSLogger uses textual datetime descriptions.
Before Osmand was not working like it was said here:
owncloud-archive#3 (comment)
  • Loading branch information
DJaeger committed Jun 5, 2015
1 parent 07caa61 commit e0d077b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions controller/locationcontroller.php
Expand Up @@ -44,7 +44,15 @@ public function update() {
$params = array('user' => $this -> userId);
$location['lat'] = $this->params('lat');
$location['lng'] = $this->params('lon');
$location['timestamp'] = strtotime($this->params('timestamp'));
if(((string)(float)$this->params('timestamp') === $this->params('timestamp'))) {
if(strtotime(date('d-m-Y H:i:s',$this->params('timestamp'))) === (int)$this->params('timestamp')) {
$location['timestamp'] = (int)$this->params('timestamp');
} elseif(strtotime(date('d-m-Y H:i:s',$this->params('timestamp')/1000)) === (int)floor($this->params('timestamp')/1000)) {
$location['timestamp'] = (int)floor($this->params('timestamp')/1000);
}
} else {
$location['timestamp'] = strtotime($this->params('timestamp'));
}
$location['hdop'] = $this->params('hdop');
$location['altitude'] = $this->params('altitude');
$location['speed'] = $this->params('speed');
Expand All @@ -65,15 +73,15 @@ public function addDevice(){
$hash = uniqid();
$deviceId = $this->locationManager->addDevice($deviceName,$hash,$this->userId);
$response = array('id'=> $deviceId,'hash'=>$hash);
return new JSONResponse($response);
return new JSONResponse($response);
}

/**
* @NoAdminRequired
*/
public function loadDevices(){
$response = $this->locationManager->loadAll($this->userId);
return new JSONResponse($response);
return new JSONResponse($response);
}
/**
* @NoAdminRequired
Expand All @@ -88,15 +96,15 @@ public function loadLocations(){
foreach($deviceIds as $device){
$response[$device] = $this->locationManager->loadHistory($device,$from,$till,$limit);
}
return new JSONResponse($response);
return new JSONResponse($response);
}
/**
* @NoAdminRequired
*/
public function removeDevice(){
$deviceId = $this->params('deviceId');
$response = $this->locationManager->remove($deviceId,$this->userId);
return new JSONResponse($response);
return new JSONResponse($response);
}

}

0 comments on commit e0d077b

Please sign in to comment.