Commit 3c57ee43 authored by Jacob Priddy's avatar Jacob Priddy 👌
Browse files

Merge branch '79-duration-from-ms-to-seconds' into 'master'

Resolve "Duration from ms to seconds."

Closes #79

See merge request !63
parents 9bfebb8f 99e147c7
Pipeline #10467 passed with stages
in 2 minutes and 51 seconds
......@@ -24,8 +24,8 @@ class CreateSchedulesTable extends Migration
$table->text('rset');
$table->timestamp('start');
$table->timestamp('end')->nullable();
// duration in ms
$table->unsignedBigInteger('duration_ms');
// duration in seconds
$table->unsignedBigInteger('duration');
$table->string('description');
$table->timestamps();
$table->foreign('group_id')->references('id')->on('groups');
......
......@@ -106,7 +106,7 @@ class Schedule
}
/**
* Currently this duration is in milliseconds
* Currently this duration is in seconds
*
* @return int
*/
......
......@@ -29,7 +29,7 @@ class DatabaseDoorScheduleRepository implements DoorScheduleRepository
{
$type = Schedule::TYPE_OPEN_MODE;
$query = <<<QUERY
select S.id, S.group_id, S.type, S.rset, S.start, S.end, S.duration_ms, S.description, S.created_at, S.updated_at
select S.id, S.group_id, S.type, S.rset, S.start, S.end, S.duration, S.description, S.created_at, S.updated_at
FROM schedules as S
INNER JOIN door_group AS DG ON DG.group_id = S.group_id AND DG.door_id = :DOOR_ID
WHERE S.type = :TYPE AND ((CURRENT_DATE BETWEEN S.start AND S.end) OR (CURRENT_DATE > S.start AND S.end IS NULL))
......@@ -46,7 +46,7 @@ QUERY;
$schedule->group_id,
$schedule->type,
$schedule->rset,
$schedule->duration_ms,
$schedule->duration,
$schedule->description,
$this->castToCarbon($schedule->start),
$this->castToCarbon($schedule->end),
......@@ -62,7 +62,7 @@ QUERY;
public function getSchedulesForDoorBetween(string $doorId, Carbon $begin, Carbon $end, int $type = Schedule::TYPE_OPEN_MODE): array
{
$query = <<<QUERY
select S.id, S.group_id, S.type, S.rset, S.start, S.end, S.duration_ms, S.description, S.created_at, S.updated_at
select S.id, S.group_id, S.type, S.rset, S.start, S.end, S.duration, S.description, S.created_at, S.updated_at
FROM schedules as S
INNER JOIN door_group AS DG ON DG.group_id = S.group_id AND DG.door_id = :DOOR_ID
WHERE S.type = :TYPE AND (((:BEGIN, :END) OVERLAPS (s.start, S.end))
......@@ -82,7 +82,7 @@ QUERY;
$schedule->group_id,
$schedule->type,
$schedule->rset,
$schedule->duration_ms,
$schedule->duration,
$schedule->description,
$this->castToCarbon($schedule->start),
$this->castToCarbon($schedule->end),
......
......@@ -60,8 +60,8 @@ class PhpRruleRecurrenceSet implements RecurrenceSetRepository
/**
* @inheritDoc
*/
public function occurrenceHappeningAtDate(Carbon $date, int $durationMs): bool
public function occurrenceHappeningAtDate(Carbon $date, int $duration): bool
{
return count($this->occurrencesBetween($date->clone()->subRealMilliseconds($durationMs), $date)) > 0;
return count($this->occurrencesBetween($date->clone()->subRealSeconds($duration), $date)) > 0;
}
}
......@@ -37,11 +37,11 @@ interface RecurrenceSetRepository
public function occurrencesBetween(Carbon $start, Carbon $end): array;
/**
* Determines if an instance is happening at the given date given the duration in milliseconds
* Determines if an instance is happening at the given date given the duration in seconds
*
* @param \Carbon\Carbon $date
* @param int $durationMs
* @param int $duration
* @return bool
*/
public function occurrenceHappeningAtDate(Carbon $date, int $durationMs): bool;
public function occurrenceHappeningAtDate(Carbon $date, int $duration): bool;
}
......@@ -25,7 +25,7 @@ class DatabaseSchedulesRepository implements SchedulesRepository
$schedule->getAttribute('group_id'),
$schedule->getAttribute('type'),
$schedule->getAttribute('rset'),
$schedule->getAttribute('duration_ms'),
$schedule->getAttribute('duration'),
$schedule->getAttribute('description'),
$schedule->getAttribute('start'),
$schedule->getAttribute('end'),
......@@ -38,7 +38,7 @@ class DatabaseSchedulesRepository implements SchedulesRepository
{
$dbSchedule->setAttribute('type', $schedule->getType());
$dbSchedule->setAttribute('rset', $schedule->getRset());
$dbSchedule->setAttribute('duration_ms', $schedule->getDuration());
$dbSchedule->setAttribute('duration', $schedule->getDuration());
$dbSchedule->setAttribute('description', $schedule->getDescription());
$dbSchedule->setAttribute('start', $schedule->getStart());
$dbSchedule->setAttribute('end', $schedule->getEnd());
......
......@@ -17,7 +17,7 @@ class LocalSchedulesRepository extends InMemorySchedulesRepository
Schedule::TYPE_USER_ACCESS,
// Allowed for a minute, not allowed for the next minute
'RRULE:FREQ=SECONDLY;INTERVAL=10',
1000 * 60,
60,
'Engineering lab user access schedule, every other minute for a minute',
Carbon::now()
));
......@@ -28,7 +28,7 @@ class LocalSchedulesRepository extends InMemorySchedulesRepository
Schedule::TYPE_OPEN_MODE,
// Open mode for 10 mintes, not open mode for 10 minutes
'RRULE:FREQ=MINUTELY;INTERVAL=20',
1000 * 60 * 10,
60 * 10,
'Computer science lab open mode schedule, every 20 minutes for 10 minutes',
Carbon::now()
));
......
......@@ -47,6 +47,6 @@ class OpenEvent
*/
public function cmp(OpenEvent $other): int
{
return $other->getBegin()->diffInRealMilliseconds($this->getBegin(), false);
return $other->getBegin()->diffInRealSeconds($this->getBegin(), false);
}
}
......@@ -93,7 +93,7 @@ class StatusResponse implements StatusResponseUseCase
}
foreach ($this->rset->occurrencesBetween($begin, $end) as $eventStart) {
$eventEnd = $eventStart->clone()->addRealMilliseconds($schedule->getDuration());
$eventEnd = $eventStart->clone()->addRealSeconds($schedule->getDuration());
$override = $this->overrides->activeOverrideForDoorBetween($doorId, $eventStart, $eventEnd);
if ($override && $override->hasTypeOf(Override::TYPE_LOCKED)) {
// If the beginning of the schedule overlaps with the override
......
......@@ -58,7 +58,7 @@ class ScheduleCreate implements ScheduleCreateUseCase
$this->rset->parse($attributes['rset']);
$end = $this->rset->endDate();
if ($end) {
$end->addRealMilliseconds($attributes['duration']);
$end->addRealSeconds($attributes['duration']);
}
$schedule = new Schedule(
0,
......
......@@ -66,7 +66,7 @@ class ScheduleUpdate implements ScheduleUpdateUseCase
$this->rset->parse($rset);
$end = $this->rset->endDate();
if ($end) {
$end->addRealMilliseconds($duration);
$end->addRealSeconds($duration);
}
$schedule = new Schedule(
0,
......
......@@ -11,7 +11,7 @@ interface ScheduleUpdateUseCase
* Accepted Attributes
* - type: int or string (0 = open mode schedule, 1 = access time schedule)
* - rset: string (valid as defined by rfc 5321)
* - duration: int or string (number of ms for the event to last)
* - duration: int or string (number of seconds for the event to last)
* - description: string (user specified description)
* - group_id: int or string (group id to attach the schedule to)
*
......
......@@ -58,7 +58,7 @@ class RecurrenceSetStub implements RecurrenceSetRepository
/**
* @inheritDoc
*/
public function occurrenceHappeningAtDate(Carbon $date, int $durationMs): bool
public function occurrenceHappeningAtDate(Carbon $date, int $duration): bool
{
return $this->occurrenceHappeningAtDate;
}
......
......@@ -73,7 +73,7 @@ RSET;
1,
Schedule::TYPE_OPEN_MODE,
$t,
1000 * 60,
60,
'',
$date
));
......
......@@ -115,7 +115,7 @@ RSET;
$this->assertTrue(
// Duration of 10 seconds
$this->setRepository->occurrenceHappeningAtDate($this->begin->clone()->addMinutes(2)->addSeconds(10), 10 * 1000)
$this->setRepository->occurrenceHappeningAtDate($this->begin->clone()->addMinutes(2)->addSeconds(10), 10)
);
}
......@@ -134,7 +134,7 @@ RSET;
$this->assertFalse(
// Duration just short of 10 seconds
$this->setRepository->occurrenceHappeningAtDate($this->begin->clone()->addMinutes(2)->addSeconds(10), 10 * 1000 - 1)
$this->setRepository->occurrenceHappeningAtDate($this->begin->clone()->addMinutes(2)->addSeconds(10), 9)
);
}
}
......@@ -115,7 +115,7 @@ class StatusResponseTest extends TestCase
));
$this->handleTest('1', Carbon::now(), Carbon::now()->addMinutes(10));
$this->assertEquals($this->rset->occurrences[0]->clone()->addRealMilliseconds(1234), $this->response->getEvents()[0]->getEnd());
$this->assertEquals($this->rset->occurrences[0]->clone()->addRealSeconds(1234), $this->response->getEvents()[0]->getEnd());
}
/**
......@@ -143,7 +143,7 @@ class StatusResponseTest extends TestCase
Schedule::TYPE_OPEN_MODE,
'',
// 20 minutes
1000 * 60 * 20,
60 * 20,
'desc',
Carbon::now()->addSeconds(10)
));
......@@ -154,7 +154,7 @@ class StatusResponseTest extends TestCase
$this->assertEquals($this->rset->occurrences[0], $this->response->getEvents()[0]->getBegin());
$this->assertEquals($o->getStart(), $this->response->getEvents()[0]->getEnd());
$this->assertEquals($o->getEnd(), $this->response->getEvents()[1]->getBegin());
$this->assertEquals($this->rset->occurrences[0]->addRealMilliseconds(1000 * 60 * 20), $this->response->getEvents()[1]->getEnd());
$this->assertEquals($this->rset->occurrences[0]->addRealSeconds(60 * 20), $this->response->getEvents()[1]->getEnd());
}
/**
......@@ -182,7 +182,7 @@ class StatusResponseTest extends TestCase
Schedule::TYPE_OPEN_MODE,
'',
// 20 minutes
1000 * 60 * 20,
60 * 20,
'desc',
Carbon::now()->addSeconds(10)
));
......@@ -218,7 +218,7 @@ class StatusResponseTest extends TestCase
Schedule::TYPE_OPEN_MODE,
'',
// 20 minutes
1000 * 60 * 20,
60 * 20,
'desc',
Carbon::now()->addSeconds(10)
));
......@@ -255,7 +255,7 @@ class StatusResponseTest extends TestCase
Schedule::TYPE_OPEN_MODE,
'',
// 10 minutes
1000 * 60 * 10,
60 * 10,
'desc',
Carbon::now()->addSeconds(10)
));
......@@ -294,7 +294,7 @@ class StatusResponseTest extends TestCase
Schedule::TYPE_OPEN_MODE,
'',
// 10 minutes
1000 * 60 * 10,
60 * 10,
'desc',
Carbon::now()->addSeconds(10)
));
......@@ -304,6 +304,6 @@ class StatusResponseTest extends TestCase
$this->assertCount(1, $this->response->getEvents());
$event = $this->response->getEvents()[0];
$this->assertEquals($o->getEnd(), $event->getBegin());
$this->assertEquals($start->addRealMilliseconds(1000 * 60 * 10), $event->getEnd());
$this->assertEquals($start->addRealSeconds(60 * 10), $event->getEnd());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment