<commit_before><?php

namespace ProcessWire\GraphQL\Field\Traits;

use Youshido\GraphQL\Config\Field\FieldConfig;
use Youshido\GraphQL\Execution\ResolveInfo;
use Youshido\GraphQL\Field\InputField;
use Youshido\GraphQL\Type\Scalar\StringType;
use ProcessWire\GraphQL\Utils;
use ProcessWire\NullPage;
use ProcessWire\FieldtypeDatetime;

trait DatetimeResolverTrait {

  public function build(FieldConfig $config)
  {
    $config->addArgument(new InputField([
      'name' => 'format',
      'type' => new StringType(),
    ]));
  }

  public function resolve($value, array $args, ResolveInfo $info)
  {
    $fieldName = $this->getName();
    
    if (isset($args['format'])) {
      $format = $args['format'];
      $rawValue = $value->$fieldName;
      if (Utils::fields()->get($fieldName) instanceof FieldtypeDatetime) {
        $rawValue = $value->getUnformatted($fieldName);
      }
      return date($format, $rawValue);
    }
    
    return $value->$fieldName;
  }
}<commit_msg>Add description to FieldtypeDatetime's 'format' argument.<commit_after><?php

namespace ProcessWire\GraphQL\Field\Traits;

use Youshido\GraphQL\Config\Field\FieldConfig;
use Youshido\GraphQL\Execution\ResolveInfo;
use Youshido\GraphQL\Field\InputField;
use Youshido\GraphQL\Type\Scalar\StringType;
use ProcessWire\GraphQL\Utils;
use ProcessWire\NullPage;
use ProcessWire\FieldtypeDatetime;

trait DatetimeResolverTrait {

  public function build(FieldConfig $config)
  {
    $config->addArgument(new InputField([
      'name' => 'format',
      'type' => new StringType(),
      'description' => 'PHP date formatting string. Refer to https://devdocs.io/php/function.date',
    ]));
  }

  public function resolve($value, array $args, ResolveInfo $info)
  {
    $fieldName = $this->getName();
    
    if (isset($args['format'])) {
      $format = $args['format'];
      $rawValue = $value->$fieldName;
      if (Utils::fields()->get($fieldName) instanceof FieldtypeDatetime) {
        $rawValue = $value->getUnformatted($fieldName);
      }
      return date($format, $rawValue);
    }
    
    return $value->$fieldName;
  }
}
{'fraction_non_alphanumeric': 0.14265402843601896, 'fraction_numerical': 0.0, 'mean_word_length': 3.9207459207459205, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6877119', 'n_tokens_mistral': 685, 'n_tokens_neox': 675, 'n_words': 125}