Skip to content

Commit

Permalink
Add support time format
Browse files Browse the repository at this point in the history
  • Loading branch information
jingu committed Aug 16, 2024
1 parent 1a4ea08 commit cc9d9e3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ public function getFormattedValue($schema)
// Date representation, without time.
case 'date':
return DateTime::dateTime()->format('Y-m-d');
// Internet email address, see RFC 5322, section 3.4.1.
// Time representation.
case 'time':
return DateTime::dateTime()->format('H:i:s');
case 'email':
return $this->getInternetFakerInstance()->safeEmail();
// Internet host name, see RFC 1034, section 3.1.
Expand Down
1 change: 1 addition & 0 deletions tests/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function getFormats()
return [
['date-time'],
['date'],
['time'],
['email'],
['hostname'],
['ipv4'],
Expand Down
6 changes: 6 additions & 0 deletions tests/fixture/format.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"type": "object",
"required": [
"date-time",
"date",
"time",
"email",
"hostname",
"ipv4",
Expand All @@ -17,6 +19,10 @@
"type": "string",
"format": "date"
},
"time": {
"type": "string",
"format": "time"
},
"email": {
"type": "string",
"format": "email"
Expand Down
5 changes: 5 additions & 0 deletions tests/fixture/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"typeAndPattern",
"typeAndFormat(date-time)",
"typeAndFormat(date)",
"typeAndFormat(time)",
"typeAndFormat(email)",
"typeAndFormat(hostname)",
"typeAndFormat(ipv4)",
Expand Down Expand Up @@ -48,6 +49,10 @@
"type": "string",
"format": "date"
},
"typeAndFormat(time)": {
"type": "string",
"format": "time"
},
"typeAndFormat(email)": {
"type": "string",
"format": "email"
Expand Down

0 comments on commit cc9d9e3

Please sign in to comment.