/
GameDateParam.php
48 lines (41 loc) · 1.16 KB
/
GameDateParam.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php declare(strict_types = 1);
namespace JasonRoman\NbaApi\Params\Data;
class GameDateParam extends AbstractDataParam
{
// format for dates is YYYYMMDD
const FORMAT = '/^\d{4}-\d{2}-\d{2}$/';
const DATE_FORMAT = 'Ymd';
/**
* Take a \DateTime value and convert it to the string date format that the API expects.
*
* @param \DateTime|string $dateTime
* @return string
*/
public static function getStringValue($dateTime): string
{
// do not return anything if no value was specified
if (!$dateTime) {
return '';
}
// until a mixed type is supported for type-hints, check the value here
if (!$dateTime instanceof \DateTime) {
return (new \DateTime($dateTime))->format(static::DATE_FORMAT);
}
return $dateTime->format(static::DATE_FORMAT);
}
/**
* {@inheritdoc}
* @return \DateTime
*/
public static function getDefaultValue(): \DateTime
{
return new \DateTime();
}
/**
* {@inheritdoc}
*/
public static function getExampleValue()
{
return new \DateTime('2017-02-01');
}
}