HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-rss-aggregator/v4/src/Entities/Properties/TimestampProperty.php
<?php

namespace RebelCode\Wpra\Core\Entities\Properties;

use RebelCode\Entities\Api\EntityInterface;
use RebelCode\Entities\Api\PropertyInterface;
use RebelCode\Entities\Properties\AbstractDecoratorProperty;

/**
 * A decorator property that translates a datetime string property into a timestamp when reading and writes timestamps
 * as date time strings.
 *
 * @since 4.16
 */
class TimestampProperty extends AbstractDecoratorProperty
{
    /**
     * @since 4.16
     *
     * @var string
     */
    protected $format;

    /**
     * Constructor.
     *
     * @since 4.16
     *
     * @param PropertyInterface $property The property instance to decorate.
     * @param string            $format   The datetime format to use when writing to the data store.
     */
    public function __construct(PropertyInterface $property, $format)
    {
        parent::__construct($property);

        $this->format = $format;
    }

    /**
     * @inheritdoc
     *
     * @since 4.16
     */
    protected function getter(EntityInterface $entity, $prev)
    {
        return strtotime($prev);
    }

    /**
     * @inheritdoc
     *
     * @since 4.16
     */
    protected function setter(EntityInterface $entity, $value)
    {
        return gmdate($this->format, $value);
    }
}