CoreFiles by mySites.guru
SchemaorgPrepareDateTrait.php53 lines, 1,138 bytes, from Joomla_5.4.2-Stable-Full_Package.zip
Raw History Compare with 5.4.1
md5
9dede4e1fc0b208a2c7ba2e4d28e3880
sha1
f1beb3b57594737bfd96f77eee96d8ca4ab0ce86
sha256
c31feff9ac2d3d8823c76ea5e91b32d7bff7e4a805caf916e4dee2347f78eb8c
<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Schemaorg;

use Joomla\CMS\Factory;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Prepare dates to be valid for JSON-LD output
 *
 * @since  5.0.0
 */
trait SchemaorgPrepareDateTrait
{
    /**
     * Prepare date
     *
     * @param   string|array $date
     *
     * @return  string|array
     *
     * @since   5.0.0
     */
    protected function prepareDate($date)
    {
        if (\is_array($date)) {
            // We don't handle references, they should be ok
            if (\count($date) === 1 && isset($date['@id'])) {
                return $date;
            }

            $newDates = [];

            foreach ($date as $d) {
                $newDates[] = $this->prepareDate($d);
            }

            return $newDates;
        }

        return Factory::getDate($date)->setTime(0, 0)->format(\DateTime::ATOM);
    }
}

The same content is in 69 releases, Joomla 5.3.4-rc1 to 6.2.1-rc1. See them all, or every version of this file.