dmBridge PHP API
DMDateTime.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00026 class DMDateTime extends DateTime {
00027 
00028    private $string_representation; // for the benefit of __sleep() & __wakeup()
00029 
00030 
00035    public function __construct($datetime_str=null) {
00036       parent::__construct($datetime_str);
00037    }
00038 
00046    public function __toString() {
00047       return $this->format('Y-m-d @ h:i:s A');
00048    }
00049 
00056    public function __sleep() {
00057       $this->string_representation = $this->format('c');
00058       return array('string_representation');
00059    }
00060 
00067    public function __wakeup() {
00068       $this->__construct($this->string_representation);
00069    }
00070 
00075    public function asISO8601() {
00076       return $this->format('c');
00077    }
00078 
00083    public function asMySQLDateTime() {
00084       return $this->format('Y-m-d h:i:s');
00085    }
00086 
00092    public function asRFC822() {
00093       return $this->format('r');
00094    }
00095 
00101    public function asRFC3339() {
00102       $date = $this->format('Y-m-d\TH:i:s');
00103       $p = array();
00104       if (preg_match('/^([\-+])(\d{2})(\d{2})$/', $this->format('O'), $p)) {
00105          $date .= $p[1] . $p[2] . ':' . $p[3];
00106       }
00107       else $date .= 'Z';
00108       return $date;
00109    }
00110 
00115    public function asUnixTimestamp() {
00116       return $this->format('U');
00117    }
00118 
00123    public function equals($obj) {
00124       if (!$obj instanceof DMObject) {
00125          return false;
00126       }
00127       return ($this->asUnixTimestamp() == $obj->asUnixTimestamp());
00128    }
00129 
00130 }
 All Data Structures Functions Variables