- Finished updating the date module
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 26 Nov 2006 01:07:43 +0000 (01:07 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 26 Nov 2006 01:07:43 +0000 (01:07 +0000)
- Adding the ISSO/Date unit test

UnitTest/AllTests.php
UnitTest/DateTest.php [new file with mode: 0644]
date.php

index 1bfc54e8b931d23bbe0c38e838852dc1fe036bfe..9ee24ece586fed6c4a1056157d8c5a1f3d6d5c7d 100644 (file)
@@ -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 (file)
index 0000000..1ac3777
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+/**
+* DateTest
+*
+* @author              Blue Static
+* @copyright   Copyright (c)2002 - [#]year[#], Blue Static
+* @version             $Revision$
+* @package             ISSO Tests
+*
+*/
+class DateTest extends UnitTestCase
+{
+       private $fixture;
+       
+       public function setUp()
+       {
+               $this->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
index 27e4cf61c39d787eed934d7b7e1fd3236203881a..0288f9fca4a37a289fe9b339beb212088dff5170 100644 (file)
--- 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 <select> list
+       * Fetches an array of timezone names indexed by their offset
        *
        * @return       array   List of timezones
        */
-       public function fetch_timezone_list()
+       public static function FetchTimeZoneList()
        {
                $opt = array();
                
-               $opt['-12']             = $this->registry->modules['localize']->string('(GMT - 12:00) Enitwetok, Kwajalien');
-               $opt['-11']             = $this->registry->modules['localize']->string('(GMT - 11:00) Midway Island, Samoa');
-               $opt['-10']             = $this->registry->modules['localize']->string('(GMT - 10:00) Hawaii');
-               $opt['-9']              = $this->registry->modules['localize']->string('(GMT - 9:00) Alaska');
-               $opt['-8']              = $this->registry->modules['localize']->string('(GMT - 8:00) Pacific Time (US &amp; Canada)');
-               $opt['-7']              = $this->registry->modules['localize']->string('(GMT - 7:00) Mountain Time (US &amp; Canada)');
-               $opt['-6']              = $this->registry->modules['localize']->string('(GMT - 6:00) Central Time (US &amp; Canada)');
-               $opt['-5']              = $this->registry->modules['localize']->string('(GMT - 5:00) Eastern Time (US &amp; Canada)');
-               $opt['-4']              = $this->registry->modules['localize']->string('(GMT - 4:00) Atlantic Time (Canada)');
-               $opt['-3.5']    = $this->registry->modules['localize']->string('(GMT - 3:30) Newfoundland');
-               $opt['-3']              = $this->registry->modules['localize']->string('(GMT - 3:00)  Brazil, Buenos Aires, Georgetown');
-               $opt['-2']              = $this->registry->modules['localize']->string('(GMT - 2:00) Mid-Atlantic, St. Helena');
-               $opt['-1']              = $this->registry->modules['localize']->string('(GMT - 1:00) Azores, Cape Verde Islands');
-               $opt['0']               = $this->registry->modules['localize']->string('(GMT) London, Dublin, Casablanca');
-               $opt['1']               = $this->registry->modules['localize']->string('(GMT + 1:00) Berlin, Madrid, Paris');
-               $opt['2']               = $this->registry->modules['localize']->string('(GMT + 2:00) Kaliningrad, South Africa, Warsaws');
-               $opt['3']               = $this->registry->modules['localize']->string('(GMT + 3:00) Baghdad, Moscow, Nairobi');
-               $opt['3.5']             = $this->registry->modules['localize']->string('(GMT + 3:30) Tehran');
-               $opt['4']               = $this->registry->modules['localize']->string('(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat');
-               $opt['4.5']             = $this->registry->modules['localize']->string('(GMT + 4:30) Kabul');
-               $opt['5']               = $this->registry->modules['localize']->string('(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent');
-               $opt['5.5']             = $this->registry->modules['localize']->string('(GMT + 5:30) Calcutta, Madras, New Delhi');
-               $opt['6']               = $this->registry->modules['localize']->string('(GMT + 6:00) Almaty, Colomba, Dhakra');
-               $opt['7']               = $this->registry->modules['localize']->string('(GMT + 7:00) Bangkok, Hanoi, Jakarta');
-               $opt['8']               = $this->registry->modules['localize']->string('(GMT + 8:00) Beijing, Hong Kong, Singapore');
-               $opt['9']               = $this->registry->modules['localize']->string('(GMT + 9:00) Seoul, Tokyo, Yakutsk');
-               $opt['9.5']             = $this->registry->modules['localize']->string('(GMT + 9:30) Adelaide, Darwin');
-               $opt['10']              = $this->registry->modules['localize']->string('(GMT + 10:00) Guam, Papua New Guinea, Sydney');
-               $opt['11']              = $this->registry->modules['localize']->string('(GMT + 11:00) Magadan, New Caledonia, Solomon Islands');
-               $opt['12']              = $this->registry->modules['localize']->string('(GMT + 12:00) Auckland, Wellington, Fiji');
+               $opt['-12']             = _('(GMT - 12:00) Enitwetok, Kwajalien');
+               $opt['-11']             = _('(GMT - 11:00) Midway Island, Samoa');
+               $opt['-10']             = _('(GMT - 10:00) Hawaii');
+               $opt['-9']              = _('(GMT - 9:00) Alaska');
+               $opt['-8']              = _('(GMT - 8:00) Pacific Time (US &amp; Canada)');
+               $opt['-7']              = _('(GMT - 7:00) Mountain Time (US &amp; Canada)');
+               $opt['-6']              = _('(GMT - 6:00) Central Time (US &amp; Canada)');
+               $opt['-5']              = _('(GMT - 5:00) Eastern Time (US &amp; Canada)');
+               $opt['-4']              = _('(GMT - 4:00) Atlantic Time (Canada)');
+               $opt['-3.5']    = _('(GMT - 3:30) Newfoundland');
+               $opt['-3']              = _('(GMT - 3:00)  Brazil, Buenos Aires, Georgetown');
+               $opt['-2']              = _('(GMT - 2:00) Mid-Atlantic, St. Helena');
+               $opt['-1']              = _('(GMT - 1:00) Azores, Cape Verde Islands');
+               $opt['0']               = _('(GMT) London, Dublin, Casablanca');
+               $opt['1']               = _('(GMT + 1:00) Berlin, Madrid, Paris');
+               $opt['2']               = _('(GMT + 2:00) Kaliningrad, South Africa, Warsaws');
+               $opt['3']               = _('(GMT + 3:00) Baghdad, Moscow, Nairobi');
+               $opt['3.5']             = _('(GMT + 3:30) Tehran');
+               $opt['4']               = _('(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat');
+               $opt['4.5']             = _('(GMT + 4:30) Kabul');
+               $opt['5']               = _('(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent');
+               $opt['5.5']             = _('(GMT + 5:30) Calcutta, Madras, New Delhi');
+               $opt['6']               = _('(GMT + 6:00) Almaty, Colomba, Dhakra');
+               $opt['7']               = _('(GMT + 7:00) Bangkok, Hanoi, Jakarta');
+               $opt['8']               = _('(GMT + 8:00) Beijing, Hong Kong, Singapore');
+               $opt['9']               = _('(GMT + 9:00) Seoul, Tokyo, Yakutsk');
+               $opt['9.5']             = _('(GMT + 9:30) Adelaide, Darwin');
+               $opt['10']              = _('(GMT + 10:00) Guam, Papua New Guinea, Sydney');
+               $opt['11']              = _('(GMT + 11:00) Magadan, New Caledonia, Solomon Islands');
+               $opt['12']              = _('(GMT + 12:00) Auckland, Wellington, Fiji');
                
                return $opt;
        }