From 8e10b1c0ad00a360a386c240154b94e1113716f9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 26 Nov 2006 01:07:43 +0000 Subject: [PATCH] - Finished updating the date module - Adding the ISSO/Date unit test --- UnitTest/AllTests.php | 1 + UnitTest/DateTest.php | 35 +++++++++++ date.php | 139 ++++++++++++++++-------------------------- 3 files changed, 88 insertions(+), 87 deletions(-) create mode 100644 UnitTest/DateTest.php diff --git a/UnitTest/AllTests.php b/UnitTest/AllTests.php index 1bfc54e..9ee24ec 100644 --- a/UnitTest/AllTests.php +++ b/UnitTest/AllTests.php @@ -10,6 +10,7 @@ $test = new GroupTest('All Tests'); $test->addTestFile('RegisterTest.php'); $test->addTestFile('FunctionsTest.php'); +$test->addTestFile('DateTest.php'); // run $test->run(new CustomHtmlReporter); diff --git a/UnitTest/DateTest.php b/UnitTest/DateTest.php new file mode 100644 index 0000000..1ac3777 --- /dev/null +++ b/UnitTest/DateTest.php @@ -0,0 +1,35 @@ +fixture = BSRegister::LoadModule('Date'); + } + + public function testGmtTimes() + { + $this->fixture->setUserTimeZone(0); + + $this->assertEqual(gmdate('r', TIMENOW), $this->fixture->format('r', TIMENOW)); + } + + public function testGmtMinus8() + { + $this->fixture->setUserTimeZone(-8); + $this->assertEqual(date('r', TIMENOW), $this->fixture->format('r', TIMENOW)); + } +} + +?> \ No newline at end of file diff --git a/date.php b/date.php index 27e4cf6..0288f9f 100644 --- a/date.php +++ b/date.php @@ -20,8 +20,7 @@ \*=====================================================================*/ /** -* Date formatting system -* date.php +* Date formatting system (Date.php) * * @package ISSO */ @@ -34,9 +33,9 @@ define('TIMENOW', time()); /** * Date Formatting System * -* This framework handles the complexities of date and time formatting -* by taking variables like global timezone and user timezone, then -* adjusting timestamps accordingly. +* This framework wraps date and time functions into one neat little +* package that takes care of modifying timestamps to meet the right +* time zone * * @author Blue Static * @copyright Copyright ©2002 - [#]year[#], Blue Static @@ -44,7 +43,7 @@ define('TIMENOW', time()); * @package ISSO * */ -class Date +class BSDate { /** * Framework registry object @@ -54,19 +53,19 @@ class Date /** * User timezone offset - * @var integer + * @var float */ - public $usertz = 0; + private $usertz = 0; /** - * Server's timezone offset; this is set using fetch_offset() - * @var integer + * The server's timezone offset + * @var float */ - private $servertz = 0; + private $servertz; /** * Total offset timezone; this is set using fetch_offset() - * @var integer + * @var float */ private $offsettz = 0; @@ -75,59 +74,26 @@ class Date * @var integer */ private $offset = 0; - - /** - * Fields array that is used in this module - * @var array - */ - private $fields = array( - 'usertz' => array(REQ_NO, null, false) - ); - + // ################################################################### /** * Constructor: sets the server's timezone */ - public function __construct(&$registry) + public function __construct() { - $this->registry =& $registry; - $this->servertz = date('Z', TIMENOW) / 3600; } // ################################################################### /** - * Sets an ISSO field - * - * @param string Field name - * @param mixed Value of the field - */ - public function set($name, $value) - { - $this->registry->do_set($name, $value, 'date'); - } - - // ################################################################### - /** - * Gets an ISSO field - * - * @param string Field name + * Sets the user time zone and then calculates the total offset * - * @return mixed Value of the field - */ - public function get($fieldname) - { - return $this->registry->do_get($fieldname, 'date'); - } - - // ################################################################### - /** - * Computes the total offset, taking into account all the various - * options + * @param float User time zone */ - public function fetch_offset() + public function setUserTimeZone($usertz) { - $this->offsettz = $this->servertz - $this->usertz; + $this->usertz = $usertz; + $this->offsettz = $this->usertz - $this->servertz; $this->offset = $this->offsettz * 3600; } @@ -146,52 +112,51 @@ class Date { if ($adjust) { - $timestamp -= $this->offset; + $timestamp += $this->offset; } - - return date($format, $timestamp); + return gmdate($format, $timestamp); } // ################################################################### /** - * Fetches an array of timezones for a