1<?php 2/** 3 * Description of IJR_Date 4 * 5 * @author Andreas Gohr <andi@splitbrain.org> 6 * @author Magnus Wolf <mwolf2706@googlemail.com> 7 */ 8class IJR_Date { 9 var $year; 10 var $month; 11 var $day; 12 var $hour; 13 var $minute; 14 var $second; 15 function IJR_Date($time) { 16 // $time can be a PHP timestamp or an ISO one 17 if (is_numeric($time)) { 18 $this->parseTimestamp($time); 19 } else { 20 $this->parseIso($time); 21 } 22 } 23 function parseTimestamp($timestamp) { 24 $this->year = gmdate('Y', $timestamp); 25 $this->month = gmdate('m', $timestamp); 26 $this->day = gmdate('d', $timestamp); 27 $this->hour = gmdate('H', $timestamp); 28 $this->minute = gmdate('i', $timestamp); 29 $this->second = gmdate('s', $timestamp); 30 } 31 function parseIso($iso) { 32 $this->year = substr($iso, 0, 4); 33 $this->month = substr($iso, 5, 2); 34 $this->day = substr($iso, 8, 2); 35 $this->hour = substr($iso, 11, 2); 36 $this->minute = substr($iso, 14, 2); 37 $this->second = substr($iso, 17, 2); 38 } 39 function getIso() { 40 return $this->year.'-'.$this->month.'-'.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second; 41 } 42 function getXml() { 43 return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; 44 } 45 function getTimestamp() { 46 return gmmktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); 47 } 48} 49?> 50