Skip to content

Commit 2cabf62

Browse files
authored
Merge pull request #5 from BJX3Y/add-time-type
[feat]add time type
2 parents fea823a + 80ac426 commit 2cabf62

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

src/TypeParser.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use rethink\typedphp\types\StringType;
1414
use rethink\typedphp\types\SumType;
1515
use rethink\typedphp\types\TimestampType;
16+
use rethink\typedphp\types\TimeType;
1617
use rethink\typedphp\types\Type;
1718
use phpDocumentor\Reflection\DocBlockFactory;
1819

@@ -45,6 +46,7 @@ public function __construct($mode)
4546
$this->registerBuiltinType(BinaryType::class);
4647
$this->registerBuiltinType(TimestampType::class);
4748
$this->registerBuiltinType(DateType::class);
49+
$this->registerBuiltinType(TimeType::class);
4850
}
4951

5052
public function registerBuiltinType(string $typeClass)

src/types/TimeType.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace rethink\typedphp\types;
4+
5+
/**
6+
* Class TimeType
7+
*
8+
* @package rethink\typedphp\types
9+
*/
10+
class TimeType implements PrimitiveType
11+
{
12+
public static function name()
13+
{
14+
return 'time';
15+
}
16+
17+
public static function toArray()
18+
{
19+
return [
20+
'type' => 'string',
21+
'pattern' => '^\d{2}:\d{2}:\d{2}$',
22+
];
23+
}
24+
}

tests/TypeTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public function typeToArrayCases()
100100
'format' => 'date',
101101
'pattern' => '^\d{4}-\d{2}-\d{2}$'
102102
],
103+
'time' => [
104+
'type' => 'string',
105+
'pattern' => '^\d{2}:\d{2}:\d{2}$'
106+
],
103107
],
104108
'required' => ['id', 'file'],
105109
],
@@ -117,6 +121,10 @@ public function typeToArrayCases()
117121
'nullable' => true,
118122
'pattern' => '^\d{4}-\d{2}-\d{2}$',
119123
],
124+
'time' => [
125+
'type' => 'string',
126+
'pattern' => '^\d{2}:\d{2}:\d{2}$'
127+
],
120128
],
121129
'required' => ['id', 'file'],
122130
],
@@ -238,6 +246,10 @@ public function typeToArrayCases()
238246
'format' => 'date',
239247
'pattern' => '^\d{4}-\d{2}-\d{2}$'
240248
],
249+
'time' => [
250+
'type' => 'string',
251+
'pattern' => '^\d{2}:\d{2}:\d{2}$'
252+
],
241253
],
242254
'required' => ['id', 'file'],
243255

@@ -280,6 +292,10 @@ public function typeToArrayCases()
280292
'nullable' => true,
281293
'pattern' => '^\d{4}-\d{2}-\d{2}$',
282294
],
295+
'time' => [
296+
'type' => 'string',
297+
'pattern' => '^\d{2}:\d{2}:\d{2}$'
298+
],
283299
],
284300
'required' => ['id', 'file'],
285301

@@ -326,6 +342,10 @@ public function typeToArrayCases()
326342
'format' => 'date',
327343
'pattern' => '^\d{4}-\d{2}-\d{2}$',
328344
],
345+
'time' => [
346+
'type' => 'string',
347+
'pattern' => '^\d{2}:\d{2}:\d{2}$'
348+
],
329349
],
330350
'required' => ['id', 'file'],
331351

@@ -375,6 +395,10 @@ public function typeToArrayCases()
375395
'nullable' => true,
376396
'pattern' => '^\d{4}-\d{2}-\d{2}$',
377397
],
398+
'time' => [
399+
'type' => 'string',
400+
'pattern' => '^\d{2}:\d{2}:\d{2}$'
401+
],
378402
],
379403
'required' => ['id', 'file'],
380404

@@ -481,6 +505,10 @@ public function typeToArrayCases()
481505
'format' => 'date',
482506
'pattern' => '^\d{4}-\d{2}-\d{2}$'
483507
],
508+
'time' => [
509+
'type' => 'string',
510+
'pattern' => '^\d{2}:\d{2}:\d{2}$'
511+
],
484512
],
485513
'required' => ['id', 'file'],
486514
],
@@ -513,6 +541,10 @@ public function typeToArrayCases()
513541
'nullable' => true,
514542
'pattern' => '^\d{4}-\d{2}-\d{2}$',
515543
],
544+
'time' => [
545+
'type' => 'string',
546+
'pattern' => '^\d{2}:\d{2}:\d{2}$'
547+
],
516548
],
517549
'required' => ['id', 'file'],
518550
],
@@ -776,6 +808,7 @@ class Product001Type extends ProductType
776808
public static $file = '!binary';
777809
public static $nullable_field = 'string?';
778810
public static $date = 'date?';
811+
public static $time = 'time';
779812
}
780813

781814
/**

0 commit comments

Comments
 (0)