cvs: pear /Date Date.php
| From: | Baba Buehler | Date: | Wed, 14 Aug 2002 06:39:26 +0000 |
| Subject: | cvs: pear /Date Date.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-5731@lists.php.net to get a copy of this message | ||
baba Wed Aug 14 02:39:26 2002 EDT
Modified files:
/pear/Date Date.php
Log:
more fixes by Nathan Fredrickson <nathan@silverorange.com>
corrected convertTZ() by adding abs() where necessary
added setTZbyID() convenience method
added %O and %o options to format() for ISO 8601 dates
%o outputs the raw timezone offset expressed as +/-HH:MM
%O outputs the dst-corrected timezone offset expressed as +/-HH:MM
Index: pear/Date/Date.php
diff -u pear/Date/Date.php:1.5 pear/Date/Date.php:1.6
--- pear/Date/Date.php:1.5 Wed Aug 14 01:43:10 2002
+++ pear/Date/Date.php Wed Aug 14 02:39:25 2002
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: Date.php,v 1.5 2002/08/14 05:43:10 baba Exp $
+// $Id: Date.php,v 1.6 2002/08/14 06:39:25 baba Exp $
//
// Date Class
//
@@ -214,6 +214,8 @@
* <code>%m </code> month as decimal number (range 01 to 12) <br>
* <code>%M </code> minute as a decimal number (00 to 59) <br>
* <code>%n </code> newline character (\n) <br>
+ * <code>%O </code> dst-corrected timezone offset expressed as
"+/-HH:MM" <br>
+ * <code>%o </code> raw timezone offset expressed as "+/-HH:MM"
<br>
* <code>%p </code> either 'am' or 'pm' depending on the
time <br>
* <code>%P </code> either 'AM' or 'PM' depending on the
time <br>
* <code>%r </code> time in am/pm notation, same as "%I:%M:%S %p"
<br>
@@ -287,6 +289,22 @@
case "n":
$output .= "\n";
break;
+ case "O":
+ $offms = $this->tz->getOffset($this);
+ $direction = $offms >= 0 ? "+" : "-";
+ $offmins = abs($offms) / 1000 / 60;
+ $hours = $offmins / 60;
+ $minutes = $offmins % 60;
+ $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
+ break;
+ case "o":
+ $offms = $this->tz->getRawOffset($this);
+ $direction = $offms >= 0 ? "+" : "-";
+ $offmins = abs($offms) / 1000 / 60;
+ $hours = $offmins / 60;
+ $minutes = $offmins % 60;
+ $output .= sprintf("%s%02d:%02d", $direction, $hours, $minutes);
+ break;
case "p":
$output .= $this->hour >= 12 ? "pm" : "am";
break;
@@ -438,7 +456,7 @@
{
// convert to UTC
if($this->tz->getOffset($this) > 0) {
- $this->subtractSeconds(intval($this->tz->getOffset($this) / 1000));
+ $this->subtractSeconds(intval(abs($this->tz->getOffset($this)) / 1000));
} else {
$this->addSeconds(intval(abs($this->tz->getOffset($this)) / 1000));
}
@@ -446,11 +464,32 @@
if($tz->getOffset($this) > 0) {
$this->addSeconds(intval(abs($tz->getOffset($this)) / 1000));
} else {
- $this->subtractSeconds(intval($tz->getOffset($this) / 1000));
+ $this->subtractSeconds(intval(abs($tz->getOffset($this)) / 1000));
}
$this->tz = $tz;
}
+ /**
+ * Converts this date to a new time zone, given a valid time zone ID
+ *
+ * Converts this date to a new time zone, given a valid time zone ID
+ * WARNING: This may not work correctly if your system does not allow
+ * putenv() or if localtime() does not work in your environment. See
+ * Date::TimeZone::inDaylightTime() for more information.
+ *
+ * @access public
+ * @param string id a time zone id
+ */
+ function convertTZbyID($id)
+ {
+ if(Date_TimeZone::isValidID($id)) {
+ $tz = new Date_TimeZone($id);
+ } else {
+ $tz = Date_TimeZone::getDefault();
+ }
+ $this->convertTZ($tz);
+ }
+
/**
* Adds a given number of seconds to the date
*