Skip to content

Commit

Permalink
add iso helper
Browse files Browse the repository at this point in the history
  • Loading branch information
SethSharp committed Jul 28, 2024
1 parent 3c032e7 commit 96a4c91
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"require": {
"php": "^8.2",
"guzzlehttp/guzzle": "^7.8"
"guzzlehttp/guzzle": "^7.8",
"nesbot/carbon": "^3.7"
},
"require-dev": {
"phpunit/phpunit": "^10.0"
Expand Down
24 changes: 20 additions & 4 deletions src/OddsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SethSharp\OddsApi;

use Carbon\Carbon;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use SethSharp\OddsApi\Enums\SportsEnum;
Expand Down Expand Up @@ -193,9 +194,13 @@ public function dateFormat(string $dateFormat): self
* @param string $time
* @return $this
*/
public function commenceTimeFrom(string $time): self
public function commenceTimeFrom(string $time, ?bool $isIsoFormat = false): self
{
$this->params['commenceTimeFrom'] = $time;
if ($isIsoFormat) {
$this->params['commenceTimeFrom'] = $time;
} else {
$this->params['commenceTimeFrom'] = $this->convertStringToIso($time);
}

return $this;
}
Expand All @@ -206,9 +211,13 @@ public function commenceTimeFrom(string $time): self
* @param string $time
* @return $this
*/
public function commenceTimeTo(string $time): self
public function commenceTimeTo(string $time, ?bool $isIsoFormat = false): self
{
$this->params['commenceTimeTo'] = $time;
if ($isIsoFormat) {
$this->params['commenceTimeTo'] = $time;
} else {
$this->params['commenceTimeTo'] = $this->convertStringToIso($time);
}

return $this;
}
Expand All @@ -225,4 +234,11 @@ public function addParams(array $params): self

return $this;
}

public function convertStringToIso(string $date): string
{
$date = Carbon::parse($date);

return $date->toIso8601String();
}
}

0 comments on commit 96a4c91

Please sign in to comment.