選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

75 行
1.6 KiB

  1. <?php
  2. /**
  3. * IXR_Date
  4. *
  5. * @package IXR
  6. * @since 1.5.0
  7. */
  8. class IXR_Date {
  9. var $year;
  10. var $month;
  11. var $day;
  12. var $hour;
  13. var $minute;
  14. var $second;
  15. var $timezone;
  16. /**
  17. * PHP5 constructor.
  18. */
  19. function __construct( $time )
  20. {
  21. // $time can be a PHP timestamp or an ISO one
  22. if (is_numeric($time)) {
  23. $this->parseTimestamp($time);
  24. } else {
  25. $this->parseIso($time);
  26. }
  27. }
  28. /**
  29. * PHP4 constructor.
  30. */
  31. public function IXR_Date( $time ) {
  32. self::__construct( $time );
  33. }
  34. function parseTimestamp($timestamp)
  35. {
  36. $this->year = date('Y', $timestamp);
  37. $this->month = date('m', $timestamp);
  38. $this->day = date('d', $timestamp);
  39. $this->hour = date('H', $timestamp);
  40. $this->minute = date('i', $timestamp);
  41. $this->second = date('s', $timestamp);
  42. $this->timezone = '';
  43. }
  44. function parseIso($iso)
  45. {
  46. $this->year = substr($iso, 0, 4);
  47. $this->month = substr($iso, 4, 2);
  48. $this->day = substr($iso, 6, 2);
  49. $this->hour = substr($iso, 9, 2);
  50. $this->minute = substr($iso, 12, 2);
  51. $this->second = substr($iso, 15, 2);
  52. $this->timezone = substr($iso, 17);
  53. }
  54. function getIso()
  55. {
  56. return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
  57. }
  58. function getXml()
  59. {
  60. return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
  61. }
  62. function getTimestamp()
  63. {
  64. return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
  65. }
  66. }