Skip to content

Commit

Permalink
When using DateTimeInmutable the variable is not an int.
Browse files Browse the repository at this point in the history
  • Loading branch information
marioquartz committed Jun 27, 2021
1 parent acdd8c8 commit 39901fd
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions src/TimeBucket.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

declare(strict_types=1);

namespace Marioquartz\MakingSessions;

Expand All @@ -12,86 +13,61 @@ class TimeBucket

/**
* @param int|\DateTimeImmutable $start
*
* @return TimeBucket
*/
public function setStart($start): TimeBucket
{
if ($start instanceof \DateTimeImmutable) {
$this->start=$start->format("U");
if (($start instanceof \DateTimeImmutable) === true) {
$this->start = (int) $start->format('U');
return $this;
}
$this->start=$start;
$this->start = $start;
return $this;
}

/**
* @param int|\DateTimeImmutable $end
*
* @return TimeBucket
*/
public function setEnd($end): TimeBucket
{
if ($end instanceof \DateTimeImmutable) {
$this->end=$end->format("U");
$end = (int) $end->format('U');
}
if ($end<$this->start) {
$end=$this->start;
if ($end < $this->start) {
$end = $this->start;
}
$this->end=$end;
$this->duration=$this->end-$this->start;
$this->end = $end;
$this->duration = $this->end - $this->start;
return $this;
}

/**
* @param int $duration
*
* @return TimeBucket
*/
public function setDuration(int $duration): TimeBucket
{
$this->duration = $duration;
$this->setEnd($this->start + $duration);
return $this;
}

/**
* @param string $type
*
* @return TimeBucket
*/
public function setType(string $type): TimeBucket
{
$this->type = $type;
return $this;
}

/**
* @return int
*/
public function getStart(): int
{
return $this->start;
}

/**
* @return int
*/
public function getEnd(): int
{
return $this->end;
}

/**
* @return int
*/
public function getDuration(): int
{
return $this->duration;
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
Expand Down

0 comments on commit 39901fd

Please sign in to comment.