ICanBoogie/HTTP v2.4.0
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • Exception
    • HTTP
      • Dispatcher
      • Headers
      • Request

Classes

  • CacheControl
  • ContentDisposition
  • ContentType
  • Date
  • Header
  • HeaderParameter
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 
<?php

/*
 * This file is part of the ICanBoogie package.
 *
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ICanBoogie\HTTP\Headers;

use ICanBoogie\DateTime;

/**
 * A date time object that renders into a string formatted for HTTP header fields.
 *
 * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
 */
class Date extends DateTime
{
    static public function from($source, $timezone=null)
    {
        if ($source === null)
        {
            return static::none();
        }

        return parent::from($source, $timezone);
    }

    /**
     * Constructor.
     *
     * @param string|int|\DateTime $time If time is provided as a numeric value it is used as
     * "@{$time}" and the time zone is set to UTC.
     * @param \DateTimeZone|string $timezone A {@link \DateTimeZone} object representing the desired
     * time zone. If the time zone is empty `utc` is used instead.
     */
    public function __construct($time='now', $timezone=null)
    {
        if ($time instanceof \DateTime)
        {
            $time = $time->getTimestamp();
        }

        if (is_numeric($time))
        {
            $time = '@' . $time;
            $timezone = null;
        }

        parent::__construct($time, $timezone ?: 'utc');
    }

    /**
     * Formats the instance according to the RFC 1123.
     */
    public function __toString()
    {
        return $this->is_empty ? '' : $this->utc->as_rfc1123;
    }
}
ICanBoogie/HTTP v2.4.0 API documentation generated by ApiGen