Removed the $globaltz option.
[isso.git] / date.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 /**
14 * Date formatting system
15 * date.php
16 *
17 * @package ISSO
18 */
19
20 $OBJECT = 'Date Formatting System';
21 $CLASS = 'Date_Formatter';
22 $OBJ = 'datef';
23
24 /**
25 * Defined constant time
26 */
27 define('TIMENOW', time());
28
29 /**
30 * Date Formatting System
31 *
32 * This framework handles the complexities of date and time formatting
33 * by taking variables like global timezone and user timezone, then
34 * adjusting timestamps accordingly.
35 *
36 * @author Iris Studios, Inc.
37 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
38 * @version $Revision$
39 * @package ISSO
40 *
41 */
42 class Date_Formatter
43 {
44 /**
45 * User timezone offset
46 * @var int
47 */
48 var $usertz = 0;
49
50 /**
51 * Server's timezone offset
52 * @var int
53 */
54 var $servertz = 0;
55
56 /**
57 * Total offset timezone
58 * @var int
59 * @see fetch_offset()
60 */
61 var $offsettz = 0;
62
63 /**
64 * Offset in seconds
65 * @var int
66 */
67 var $offset = 0;
68
69 /**
70 * Constructor: sets the server's timezone
71 */
72 function Date_Formatter()
73 {
74 $this->servertz = date('Z', TIMENOW) / 3600;
75 }
76
77 /**
78 * Computes the total offset, taking into account all
79 * the various options
80 */
81 function fetch_offset()
82 {
83 $this->offsettz = $this->servertz - $this->usertz;
84 $this->offset = $this->offsettz * 3600;
85 }
86
87 /**
88 * Formats a UNIX timestamp to a certain date format in the proper time zone
89 *
90 * @param string Format of the date (same as PHP's date() function)
91 * @param int UNIX timestamp to format
92 * @param bool Adjust the date to the user's language?
93 *
94 * @return string Formatted date
95 */
96 function format($format, $timestamp = TIMENOW, $adjust = true)
97 {
98 if ($adjust)
99 {
100 $timestamp -= $this->offset;
101 }
102
103 return date($format, $timestamp);
104 }
105 }
106
107 /*=====================================================================*\
108 || ###################################################################
109 || # $HeadURL$
110 || # $Id$
111 || ###################################################################
112 \*=====================================================================*/
113 ?>