Fix MetricPoint changes

This commit is contained in:
James Brooks 2018-06-28 12:01:22 +01:00 committed by James Brooks
parent db627f6e86
commit 3e5dc6a3f9
2 changed files with 13 additions and 3 deletions

View File

@ -14,9 +14,17 @@ namespace CachetHQ\Cachet\Models;
use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Presenters\MetricPointPresenter;
use Carbon\Carbon;
use DateTime;
use Illuminate\Database\Eloquent\Model;
use McCool\LaravelAutoPresenter\HasPresenter;
/**
* This is the metric point model class.
*
* @author James Brooks <james@alt-three.com>
* @author Joseph Cohen <joe@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class MetricPoint extends Model implements HasPresenter
{
use ValidatingTrait;
@ -102,7 +110,9 @@ class MetricPoint extends Model implements HasPresenter
return;
}
$createdAt = Carbon::parse($createdAt);
if (!$createdAt instanceof DateTime) {
$createdAt = Carbon::parse($createdAt);
}
$timestamp = $createdAt->format('U');
$timestamp = 30 * round($timestamp / 30);

View File

@ -69,7 +69,7 @@ class MetricPointTest extends AbstractApiTestCase
$this->beUser();
$metric = factory(Metric::class)->create();
$timestamp = 1434369116;
$timestamp = strtotime('now');
$metricPoint = factory(MetricPoint::class)->make([
'metric_id' => $metric->id,
]);
@ -81,7 +81,7 @@ class MetricPointTest extends AbstractApiTestCase
$response->assertStatus(200);
$response->assertJsonFragment([
'value' => $metricPoint->value,
'created_at' => date('Y-m-d H:i:00', 1434369116),
'created_at' => date('Y-m-d H:i:s', $timestamp),
]);
}