Get the attributes that should be converted to dates.

@return array
168810
public function getDates()
    {
        return $this->cache(__FUNCTION__, function () {
            $casts = $this->getCasts();

            $dates = [];

            foreach ($casts as $key => $cast) {
                if ($cast == 'datetime') {
                    $dates[] = $key;
                }
            }

            return $dates;
        });
    }
1312959
public function getAttributeRules()
    {
        $result = [];
        $attributes = $this->getAttributesFromSchema();
        $casts = $this->getCasts();
        $casts_back = $this->getAttributesFromSchema('cast-back', true);
        $rules = $this->getAttributesFromSchema('rules', true);

        // Build full rule for each attribute.
        foreach ($attributes as $key) {
            $result[$key] = [];
        }

        // If any casts back are configured, replace the value found in casts.
        // Handy if we read integer values as datetime, but save back as an integer.
        $casts = array_merge($casts, $casts_back);

        // Build full rule for each attribute.
        foreach ($casts as $key => $cast_type) {
            $cast_validator = $this->parseCastToValidator($cast_type);

            if (!empty($cast_validator)) {
                $result[$key][] = $cast_validator;
            }

            if ($this->exists) {
                $result[$key][] = 'sometimes';
            }
        }

        // Assign specified rules.
        foreach ($rules as $key => $rule) {
            $result[$key][] = $rule;
        }

        unset($result[$this->getKeyName()]);

        foreach ($result as $key => $rules) {
            $result[$key] = implode('|', $rules);
        }

        return $result;
    }
947928
public function attributes()
    {
        $def = $this->definition();
        $attrs = array_keys( $def["fields"] );
        if ( isset( $def["function_attributes"] ) )
            $attrs = array_unique( array_merge( $attrs, array_keys( $def["function_attributes"] ) ) );
        if ( isset( $def["functions"] ) )
            $attrs = array_unique( array_merge( $attrs, array_keys( $def["functions"] ) ) );
        return $attrs;
    }
1341287
public function getAllAttributes()
    {
        if ($this->node->hasAttributes()) {
            $attributes = [];
            foreach ($this->node->attributes as $attr) {
                $attributes[$attr->name] = $attr->value;
            }

            return $attributes;
        }

        return null;
    }
985286
protected function getAttributeFrom()
    {
        $attribute = array_get($this->formFieldData->options(), 'from', $this->formFieldData->source());

        if ( ! $attribute) {
            throw new UnexpectedValueException("DateRangeStrategy must have 'date_from' option set");
        }

        return $attribute;
    }
1076171
public function convertDateFields()
    {
        $grid_field = $this->getGridField();
        $config = $grid_field->getConfig();
        $db = Config::inst()->get($grid_field->getModelClass(), "db");
        $dates = self::config()->date_fields;
        $fields = $this->findDateFields();

        // First setup columns
        foreach ($config->getComponents() as $component) {
            $class = get_class($component);
            $is_header = ($component instanceof GridFieldSortableHeader);
            $is_columns = ClassInfo::classImplements(
                $class,
                GridField_ColumnProvider::class
            );

            // If we are working with a set of data columns, look for
            // date/datetime columns
            if ($is_columns && method_exists($component, "getDisplayFields")) {
                $display_fields = $component->getDisplayFields($grid_field);
                foreach ($fields as $field) {
                    $display_fields = $this->changeKeys(
                        $field["Sort"],
                        $field["Column"],
                        $display_fields
                    );
                }
                $component->setDisplayFields($display_fields);
            }

            // If we are working with sortable headers, look for
            // date/datetime columns
            if ($is_header && count($component->getFieldSorting()) == 0) {
                $sort_fields = [];
                foreach ($fields as $field) {
                    $sort_fields[$field["Column"]] = $field["Sort"];
                }
                $component->setFieldSorting($sort_fields);
            }
        }

        $this->setGridField($grid_field);

        return $this;
    }
737862
public function attributesToArray()
    {
        $attributes = $this->attributes;

        // If an attribute is a date, we will cast it to a string after converting it
        // to a DateTime / Carbon instance. This is so we will get some consistent
        // formatting while accessing attributes vs. arraying / JSONing a object.
        foreach ($this->getDates() as $key) {
            if (! isset($attributes[$key])) {
                continue;
            }

            $attributes[$key] = $this->serializeDate(
                $this->asDateTime($attributes[$key])
            );
        }

        $mutatedAttributes = $this->getMutatedAttributes();

        // We want to spin through all the mutated attributes for this object and call
        // the mutator for the attribute. We cache off every mutated attributes so
        // we don't have to constantly check on attributes that actually change.
        foreach ($mutatedAttributes as $key) {
            if (! array_key_exists($key, $attributes)) {
                continue;
            }

            $attributes[$key] = $this->mutateAttributeForArray(
                $key, $attributes[$key]
            );
        }

        // Next we will handle any casts that have been setup for this object and cast
        // the values to their appropriate type. If the attribute has a mutator we
        // will not perform the cast on those attributes to avoid any confusion.
        foreach ($this->getCasts() as $key => $value) {
            if (! array_key_exists($key, $attributes) ||
                in_array($key, $mutatedAttributes)) {
                continue;
            }

            $attributes[$key] = $this->castAttribute(
                $key, $attributes[$key]
            );

            if ($attributes[$key] && ($value === 'date' || $value === 'datetime')) {
                $attributes[$key] = $this->serializeDate($attributes[$key]);
            }
        }

        return $attributes;
    }
673358
public function attributes()
    {
        return [
            $this->attributePrefix.'address' => (int) $this->address,
            $this->attributePrefix.'title'   => (int) $this->title,
        ];
    }
1257051
public function getAttributes()
    {
        return [
            Attributes\IdAttribute::make(),
            AmethystAttributes\CountryAttribute::make()
                ->setRequired(true),
            AmethystAttributes\ZipCodeAttribute::make()
                ->setRequired(true),
            Attributes\TextAttribute::make('street')
                ->setRequired(true),
            Attributes\TextAttribute::make('province')
                ->setRequired(true),
            Attributes\TextAttribute::make('city')
                ->setRequired(true),
            Attributes\CreatedAtAttribute::make(),
            Attributes\UpdatedAtAttribute::make(),
            Attributes\DeletedAtAttribute::make(),
        ];
    }
75271
protected function getCommonDefaults()
    {
        return [
            'widget' => 'single_text',
            'datepicker_use_button' => true,
            'dp_pick_time' => true,
            'dp_pick_date' => true,
            'dp_use_current' => true,
            'dp_min_date' => '1/1/1900',
            'dp_max_date' => null,
            'dp_show_today' => true,
            'dp_language' => $this->locale,
            'dp_default_date' => '',
            'dp_disabled_dates' => [],
            'dp_enabled_dates' => [],
            'dp_icons' => [
                'time' => 'fa fa-clock-o',
                'date' => 'fa fa-calendar',
                'up' => 'fa fa-chevron-up',
                'down' => 'fa fa-chevron-down',
            ],
            'dp_use_strict' => false,
            'dp_side_by_side' => false,
            'dp_days_of_week_disabled' => [],
            'dp_collapse' => true,
            'dp_calendar_weeks' => false,
            'dp_view_mode' => 'days',
            'dp_min_view_mode' => 'days',
        ];
    }
706612
public function getHumansTimeAttribute()
    {
        $date = $this->created_at;
        $now = $date->now();

        return $date->diffForHumans($now, true);
    }
780855
public function getAttributes()
    {
        return [
            Attributes\IdAttribute::make(),
            Attributes\TextAttribute::make('number')
                ->setUnique(true),
            Attributes\BelongsToAttribute::make('sender_id')
                ->setRelationName('sender')
                ->setRelationManager(LegalEntityManager::class)
                ->setRequired(true),
            Attributes\BelongsToAttribute::make('recipient_id')
                ->setRelationName('recipient')
                ->setRelationManager(LegalEntityManager::class)
                ->setRequired(true),
            AmethystAttributes\TaxonomyAttribute::make('type_id', Config::get('amethyst.invoice.taxonomies.0.name'))
                ->setRelationName('type'),
            AmethystAttributes\CountryAttribute::make('country')
                ->setRequired(true),
            AmethystAttributes\Invoice\CurrencyAttribute::make('currency')
                ->setRequired(true),
            AmethystAttributes\Invoice\LocaleAttribute::make('locale')
                ->setRequired(true),
            Attributes\BelongsToAttribute::make('tax_id')
                ->setRelationName('tax')
                ->setRelationManager(TaxManager::class),
            Attributes\DateTimeAttribute::make('issued_at'),
            Attributes\DateTimeAttribute::make('expires_at'),
            Attributes\CreatedAtAttribute::make(),
            Attributes\UpdatedAtAttribute::make(),
            Attributes\DeletedAtAttribute::make(),
        ];
    }
135748
public function getAllDateFormat()
    {
        $aFormats = static::FORMAT_DATE;
        $oNow     = Factory::factory('DateTime');
        foreach ($aFormats as &$aFormat) {
            $aFormat          = (object) $aFormat;
            $aFormat->example = $oNow->format($aFormat->format);
        }
        return $aFormats;
    }
65842
protected function prepareAttributes()
    {

        // prepare the date format for the created at/updated at dates
        $createdAt = $this->getValue(ColumnKeys::CREATED_AT, date('Y-m-d H:i:s'), array($this, 'formatDate'));
        $updatedAt = $this->getValue(ColumnKeys::UPDATED_AT, date('Y-m-d H:i:s'), array($this, 'formatDate'));

        // load the product's attribute set ID
        $attributeSet = $this->getAttributeSetByAttributeSetName($this->getValue(ColumnKeys::ATTRIBUTE_SET_CODE));
        $attributeSetId = $attributeSet[MemberNames::ATTRIBUTE_SET_ID];
        $this->setAttributeSet($attributeSet);

        // initialize parent ID (the parent array entry)
        $parentId = $this->categoryIds[sizeof($this->categoryIds) - 1];

        // initialize the level
        $level = sizeof($this->categoryIds);

        // load the position, if available
        $position = $this->getValue(ColumnKeys::POSITION, 0);

        // return the prepared product
        return $this->initializeEntity(
            array(
                MemberNames::CREATED_AT       => $createdAt,
                MemberNames::UPDATED_AT       => $updatedAt,
                MemberNames::ATTRIBUTE_SET_ID => $attributeSetId,
                MemberNames::PATH             => '',
                MemberNames::PARENT_ID        => $parentId,
                MemberNames::POSITION         => $position,
                MemberNames::LEVEL            => $level,
                MemberNames::CHILDREN_COUNT   => 0
            )
        );
    }
443362
public function getFieldsMessagesDataAttributes()
    {
        $result = [];
        $formConfiguration = $this->getFormObject()->getConfiguration();
        $formResult = $this->getFormObject()->getFormResult();

        foreach ($formResult->getSubResults() as $fieldName => $fieldResult) {
            if (true === $formConfiguration->hasField($fieldName)
                && false === $formResult->fieldIsDeactivated($formConfiguration->getField($fieldName))
            ) {
                $result += $this->getFieldErrorMessages($fieldName, $fieldResult);
                $result += $this->getFieldWarningMessages($fieldName, $fieldResult);
                $result += $this->getFieldNoticeMessages($fieldName, $fieldResult);
            }
        }

        return $result;
    }
53910
public function attributesToArray()
    {
        $attributes = $this->getArrayableAttributes();

        foreach ($this->getDates() as $key) {
            if (! isset($attributes[$key])) {
                continue;
            }

            $attributes[$key] = (string) $this->asDateTime($attributes[$key]);
        }

        foreach ($this->getMutatedAttributes() as $key) {
            if (! array_key_exists($key, $attributes)) {
                continue;
            }

            $attributes[$key] = $this->mutateAttributeForArray($key, $attributes[$key]);
        }

        foreach ($this->getArrayableAppends() as $key) {
            $attributes[$key] = $this->mutateAttributeForArray($key, null);
        }

        return $attributes;
    }
1102857
protected function getDeletedEventAttributes(): array
    {
        $old = [];

        foreach ($this->attributes as $attribute => $value) {
            if ($this->isAttributeAuditable($attribute)) {
                $old[$attribute] = $value;
            }
        }

        return [
            $old,
            [],
        ];
    }