/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. /**#@+ @ignore */
  23. require_once 'Zend/Media/Id3/TextFrame.php';
  24. /**#@-*/
  25. /**
  26. * A base class for all the text frames representing a date or parts of it.
  27. *
  28. * @category Zend
  29. * @package Zend_Media
  30. * @subpackage ID3
  31. * @author Sven Vollbehr <sven@vollbehr.eu>
  32. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @version $Id: DateFrame.php 273 2012-08-21 17:22:52Z svollbehr $
  35. */
  36. abstract class Zend_Media_Id3_DateFrame
  37. extends Zend_Media_Id3_TextFrame
  38. {
  39. private $_format;
  40. /**
  41. * Constructs the class with given parameters and parses object related
  42. * data.
  43. *
  44. * @param Zend_Io_Reader $reader The reader object.
  45. * @param Array $options The options array.
  46. * @param string $format Rule for formatting output. If null the default
  47. * ISO 8601 date format is used.
  48. */
  49. public function __construct
  50. ($reader = null, &$options = array(), $format = null)
  51. {
  52. parent::__construct($reader, $options);
  53. $this->_format = $format;
  54. if ($this->_reader === null) {
  55. return;
  56. }
  57. }
  58. /**
  59. * Returns the date.
  60. *
  61. * @return Zend_Date
  62. */
  63. public function getDate()
  64. {
  65. require_once 'Zend/Date.php';
  66. $date = new Zend_Date(0);
  67. $date->setTimezone('UTC');
  68. $date->set
  69. ($this->getText(),
  70. $this->_format ? $this->_format : Zend_Date::ISO_8601);
  71. return $date;
  72. }
  73. /**
  74. * Sets the date. If called with null value the current time is entered.
  75. *
  76. * @param Zend_Date $date The date.
  77. */
  78. public function setDate($date = null)
  79. {
  80. require_once 'Zend/Date.php';
  81. if ($date === null) {
  82. $date = Zend_Date::now();
  83. }
  84. $date->setTimezone('UTC');
  85. $this->setText($date->toString(Zend_Date::ISO_8601));
  86. }
  87. /**
  88. * Writes the frame raw data without the header.
  89. *
  90. * @param Zend_Io_Writer $writer The writer object.
  91. * @return void
  92. */
  93. protected function _writeData($writer)
  94. {
  95. if ($this->getOption('version', 4) >= 4) {
  96. parent::_writeData($writer);
  97. } else {
  98. $this->setEncoding(Zend_Media_Id3_Encoding::ISO88591);
  99. parent::_writeData($writer);
  100. }
  101. }
  102. }