<commit_before><?php

class Octopus_Model_Field_Datetime extends Octopus_Model_Field {

    private $format = 'Y-m-d H:i:s';

    public function __construct($field, $modelClass, $options) {
        parent::__construct($field, $modelClass, $options);

        if ($field == 'created') {
            $this->defaultOptions = array(
                'onCreate' => '_setNow',
            );
        } else if ($field == 'updated') {
            $this->defaultOptions = array(
                'onSave' => '_setNow',
            );
        }
    }

    public function migrate($schema, $table) {
        $table->newDateTime($this->getFieldName());
    }

   public function save($model, $sqlQuery) {

       $value = $this->accessValue($model, true);

       if (is_string($value)) {
           $value = strtotime($value);
       }

       $value = date('Y-m-d H:i:s', $value);

       $sqlQuery->set($this->getFieldName(), $value);
    }

    function _setNow() {
        return date($this->format, time());
    }
}

?><commit_msg>- Model_Field_Datetime now properly formats dates it sends to mysql in restrict()<commit_after><?php

class Octopus_Model_Field_Datetime extends Octopus_Model_Field {

    private $format = 'Y-m-d H:i:s';

    public function __construct($field, $modelClass, $options) {

        parent::__construct($field, $modelClass, $options);

        if ($field == 'created') {
            $this->defaultOptions = array(
                'onCreate' => '_setNow',
            );
        } else if ($field == 'updated') {
            $this->defaultOptions = array(
                'onSave' => '_setNow',
            );
        }
    }

    public function migrate($schema, $table) {
        $table->newDateTime($this->getFieldName());
    }

    public function restrict($expression, $operator, $value, &$s, &$params, $model) {
        $value = self::formatDate($value);
        return parent::restrict($expression, $operator, $value, $s, $params, $model);
    }

    public function save($model, $sqlQuery) {

        $value = $this->accessValue($model, true);
        $value = self::formatDate($value);

        $sqlQuery->set($this->getFieldName(), $value);
    }

    private static function formatDate($value) {

        if ($value === '' || $value === null) {
            return '';
        }

        if (!is_numeric($value)) {
            $value = strtotime($value);
        }

        return date('Y-m-d H:i:s', $value);
    }

    function _setNow() {
        return date($this->format, time());
    }
}
?>
{'fraction_non_alphanumeric': 0.16416139240506328, 'fraction_numerical': 0.0, 'mean_word_length': 2.280155642023346, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '6258964', 'n_tokens_mistral': 774, 'n_tokens_neox': 738, 'n_words': 157}