PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Zend/Media/Id3/DateFrame.php

http://php-reader.googlecode.com/
PHP | 109 lines | 44 code | 7 blank | 58 comment | 4 complexity | 6ceea30470ee9a6421297758151fe74b MD5 | raw file
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the new BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 * It is also available through the world-wide-web at this URL:
 10 * http://framework.zend.com/license/new-bsd
 11 * If you did not receive a copy of the license and are unable to
 12 * obtain it through the world-wide-web, please send an email
 13 * to license@zend.com so we can send you a copy immediately.
 14 *
 15 * @category   Zend
 16 * @package    Zend_Media
 17 * @subpackage ID3
 18 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) 
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: DateFrame.php 273 2012-08-21 17:22:52Z svollbehr $
 21 */
 22
 23/**#@+ @ignore */
 24require_once 'Zend/Media/Id3/TextFrame.php';
 25/**#@-*/
 26
 27/**
 28 * A base class for all the text frames representing a date or parts of it.
 29 *
 30 * @category   Zend
 31 * @package    Zend_Media
 32 * @subpackage ID3
 33 * @author     Sven Vollbehr <sven@vollbehr.eu>
 34 * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com) 
 35 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 36 * @version    $Id: DateFrame.php 273 2012-08-21 17:22:52Z svollbehr $
 37 */
 38abstract class Zend_Media_Id3_DateFrame
 39    extends Zend_Media_Id3_TextFrame
 40{
 41    private $_format;
 42
 43    /**
 44     * Constructs the class with given parameters and parses object related
 45     * data.
 46     *
 47     * @param Zend_Io_Reader $reader The reader object.
 48     * @param Array $options The options array.
 49     * @param string $format Rule for formatting output. If null the default
 50     *  ISO 8601 date format is used.
 51     */
 52    public function __construct
 53        ($reader = null, &$options = array(), $format = null)
 54    {
 55        parent::__construct($reader, $options);
 56        $this->_format = $format;
 57
 58        if ($this->_reader === null) {
 59            return;
 60        }
 61    }
 62
 63    /**
 64     * Returns the date.
 65     *
 66     * @return Zend_Date
 67     */
 68    public function getDate()
 69    {
 70        require_once 'Zend/Date.php';
 71        $date = new Zend_Date(0);
 72        $date->setTimezone('UTC');
 73        $date->set
 74            ($this->getText(),
 75             $this->_format ? $this->_format : Zend_Date::ISO_8601);
 76        return $date;
 77    }
 78
 79    /**
 80     * Sets the date. If called with null value the current time is entered.
 81     *
 82     * @param Zend_Date $date The date.
 83     */
 84    public function setDate($date = null)
 85    {
 86        require_once 'Zend/Date.php';
 87        if ($date === null) {
 88            $date = Zend_Date::now();
 89        }
 90        $date->setTimezone('UTC');
 91        $this->setText($date->toString(Zend_Date::ISO_8601));
 92    }
 93
 94    /**
 95     * Writes the frame raw data without the header.
 96     *
 97     * @param Zend_Io_Writer $writer The writer object.
 98     * @return void
 99     */
100    protected function _writeData($writer)
101    {
102        if ($this->getOption('version', 4) >= 4) {
103            parent::_writeData($writer);
104        } else {
105            $this->setEncoding(Zend_Media_Id3_Encoding::ISO88591);
106            parent::_writeData($writer);
107        }
108    }
109}