cvs: pear /Date Date.php package.xml
| From: | Baba Buehler | Date: | Mon, 13 May 2002 01:53:21 +0000 |
| Subject: | cvs: pear /Date Date.php package.xml | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3791@lists.php.net to get a copy of this message | ||
baba Sun May 12 21:53:21 2002 EDT
Modified files:
/pear/Date Date.php package.xml
Log:
updated constructor to be smarter, accepting various date formats for initialization
added copy() method, to copy values from another Date object
updated version to 1.1
Index: pear/Date/Date.php
diff -u pear/Date/Date.php:1.1 pear/Date/Date.php:1.2
--- pear/Date/Date.php:1.1 Sat May 11 09:04:50 2002
+++ pear/Date/Date.php Sun May 12 21:53:20 2002
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: Date.php,v 1.1 2002/05/11 13:04:50 baba Exp $
+// $Id: Date.php,v 1.2 2002/05/13 01:53:20 baba Exp $
//
// Date Class
//
@@ -47,7 +47,7 @@
* @author Baba Buehler <baba@babaz.com>
* @package Date
* @access public
- * @version 1.0
+ * @version 1.1
*/
class Date
{
@@ -91,16 +91,28 @@
/**
* Constructor
*
- * Creates a new Date Object
+ * Creates a new Date Object
* initialized to the current date/time in the
- * system default time zone by default.
- *
+ * system default time zone by default. A date optionally
+ * passed in may be in the ISO, TIMESTAMP or UNIXTIME format,
+ * or another Date object.
+ *
* @access public
+ * @param mixed $date optional - date/time to initialize
* @return object Date the new Date object
*/
- function Date() {
- $this->setDate(date("Y-m-d H:i:s"));
+ function Date($date = 0) {
$this->tz = Date_TimeZone::getDefault();
+ if(is_object($date) && (get_class($date) == 'date'))
+ $this->copy($date);
+ elseif(preg_match('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/',$date))
+ $this->setDate($date);
+ elseif(preg_match('/\d{14}/',$date))
+ $this->setDate($date,DATE_FORMAT_TIMESTAMP);
+ elseif(is_int($date))
+ $this->setDate($date,DATE_FORMAT_UNIXTIME);
+ else
+ $this->setDate(date("Y-m-d H:i:s"));
}
/**
@@ -155,6 +167,25 @@
}
}
+ /**
+ * Copy values from another Date object
+ *
+ * Makes this Date a copy of another Date object.
+ *
+ * @access public
+ * @param object Date $date Date to copy from
+ */
+ function copy($date)
+ {
+ $this->year = $date->year;
+ $this->month = $date->month;
+ $this->day = $date->month;
+ $this->hour = $date->hour;
+ $this->minute = $date->minute;
+ $this->second = $date->second;
+ $this->tz = $date->tz;
+ }
+
/**
* Date pretty printing, similar to strftime()
*
Index: pear/Date/package.xml
diff -u pear/Date/package.xml:1.1 pear/Date/package.xml:1.2
--- pear/Date/package.xml:1.1 Sat May 11 09:04:50 2002
+++ pear/Date/package.xml Sun May 12 21:53:20 2002
@@ -19,10 +19,10 @@
</maintainer>
</maintainers>
<release>
- <version>1.0</version>
+ <version>1.1</version>
<state>stable</state>
<date>2002-05-11</date>
- <notes>First packaged release.</notes>
+ <notes>Made constructor smarter accepting various date formats for initialization. Added
copy() method.</notes>
<filelist>
<file role="php" baseinstalldir="/">Date.php</file>
<dir name="Date">