<commit_before><?php namespace Anomaly\DatetimeFieldType;

use Anomaly\Streams\Platform\Addon\FieldType\FieldTypeModifier;
use Carbon\Carbon;
use Illuminate\Contracts\Config\Repository;

/**
 * Class DatetimeFieldTypeModifier
 *
 * @link          http://pyrocms.com/
 * @author        PyroCMS, Inc. <<EMAIL>>
 * @author        <NAME> <<EMAIL>>
 * @package       Anomaly\DatetimeFieldType
 */
class DatetimeFieldTypeModifier extends FieldTypeModifier
{

    /**
     * The datetime field type.
     * This is for IDE hinting.
     *
     * @var DatetimeFieldType
     */
    protected $fieldType;

    /**
     * The config repository.
     *
     * @var Repository
     */
    protected $config;

    /**
     * Create a new DatetimeFieldTypeModifier instance.
     *
     * @param Repository        $config
     * @param DatetimeFieldType $fieldType
     */
    public function __construct(Repository $config, DatetimeFieldType $fieldType)
    {
        $this->config    = $config;
        $this->fieldType = $fieldType;
    }

    /**
     * Modify the value.
     *
     * @param $value
     * @return int
     */
    public function modify($value)
    {
        if (!$value = $this->toCarbon($value, array_get($this->fieldType->getConfig(), 'timezone'))) {
            return null;
        }

        if ($this->fieldType->config('mode') !== 'date') {
            $value->setTimezone('UTC');
        }

        return $value;
    }

    /**
     * Restore the value.
     *
     * @param $value
     * @return Carbon
     */
    public function restore($value)
    {
        if (!$value = $this->toCarbon($value, 'UTC')) {
            return null;
        }

        if ($this->fieldType->config('mode') !== 'date') {
            $value->setTimezone(array_get($this->fieldType->getConfig(), 'timezone'));<commit_msg>Fix issue where database servers might not be in UTC.. so let configuration handle it.<commit_after><?php namespace Anomaly\DatetimeFieldType;

use Anomaly\Streams\Platform\Addon\FieldType\FieldTypeModifier;
use Carbon\Carbon;
use Illuminate\Contracts\Config\Repository;

/**
 * Class DatetimeFieldTypeModifier
 *
 * @link          http://pyrocms.com/
 * @author        PyroCMS, Inc. <<EMAIL>>
 * @author        <NAME> <<EMAIL>>
 * @package       Anomaly\DatetimeFieldType
 */
class DatetimeFieldTypeModifier extends FieldTypeModifier
{

    /**
     * The datetime field type.
     * This is for IDE hinting.
     *
     * @var DatetimeFieldType
     */
    protected $fieldType;

    /**
     * The config repository.
     *
     * @var Repository
     */
    protected $config;

    /**
     * Create a new DatetimeFieldTypeModifier instance.
     *
     * @param Repository        $config
     * @param DatetimeFieldType $fieldType
     */
    public function __construct(Repository $config, DatetimeFieldType $fieldType)
    {
        $this->config    = $config;
        $this->fieldType = $fieldType;
    }

    /**
     * Modify the value.
     *
     * @param $value
     * @return int
     */
    public function modify($value)
    {
        if (!$value = $this->toCarbon($value, array_get($this->fieldType->getConfig(), 'timezone'))) {
            return null;
        }

        if ($this->fieldType->config('mode') !== 'date') {
            $value->setTimezone($this->config->get('streams::datetime.database_timezone'));
        }

        return $value;
    }

    /**
     * Restore the value.
     *
     * @param $value
     * @return Carbon
     */
    public function restore($value)
    {
        if (!$value = $this->toCarbon($value, $this->config->get('streams::datetime.database_timezone'))) {
            return null;
        }

        if ($this->fieldType->config('mode') !== 'date') {
            $value->setTimezone(array_get($this->fieldType->getConfig(), 'timezone'));
{'fraction_non_alphanumeric': 0.13911448781765784, 'fraction_numerical': 0.0, 'mean_word_length': 2.2355932203389832, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 45, 'https://': 0, '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': '4131532', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1134, 'n_words': 235}