Skip to content

Commit 2af8965

Browse files
author
Bertrand Dunogier
committed
Fixed a bug in date handling
1 parent b3c4476 commit 2af8965

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

GraphQL/Resolver/DateResolver.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66

77
class DateResolver
88
{
9-
public function resolveDateToFormat(string $format, DateTime $date = null)
9+
public function resolveDateToFormat($date, $args)
1010
{
11-
if ($date === null) {
12-
return $date;
11+
if (!$date instanceof DateTime) {
12+
return null;
13+
}
14+
15+
if (isset($args['pattern'])) {
16+
return $date->format($args['pattern']);
17+
}
18+
19+
if (isset($args['constant'])) {
20+
return $date->format($args['constant']);
1321
}
14-
return $date->format($format);
1522
}
1623
}

Resources/config/graphql/Base.types.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ DateTime:
2525
description: "Date formatted with a date() format"
2626
resolve: "@=resolver('DateTimeFormat', [value, args])"
2727
args:
28-
format:
28+
pattern:
2929
type: "String"
30-
description: "A format compatible with date()"
30+
description: "A pattern compatible with date()"
3131
constant:
3232
type: DateFormatConstant
3333
timestamp:

0 commit comments

Comments
 (0)