Forgot to put the name in the header.
[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 * Global timezone offset for the application; used when there is no usertimezone
46 * @var int
47 */
48 var $globaltz = 0;
49
50 /**
51 * User timezone offset
52 * @var int
53 */
54 var $usertz = 0;
55
56 /**
57 * Server's timezone offset
58 * @var int
59 */
60 var $servertz = 0;
61
62 /**
63 * Total offset timezone
64 * @var int
65 * @see fetch_offset()
66 */
67 var $offsettz = 0;
68
69 /**
70 * Offset in seconds
71 * @var int
72 */
73 var $offset = 0;
74
75 /**
76 * Constructor: sets the server's timezone
77 */
78 function Date_Formatter()
79 {
80 $this->servertz = date('Z', TIMENOW) / 3600;
81 }
82
83 /**
84 * Computes the total offset, taking into account all
85 * the various options
86 */
87 function fetch_offset()
88 {
89 $this->offsettz = $this->servertz - $this->usertz;
90 $this->offset = $this->offsettz * 3600;
91 }
92
93 /**
94 * Formats a UNIX timestamp to a certain date format in the proper time zone
95 *
96 * @param string Format of the date (same as PHP's date() function)
97 * @param int UNIX timestamp to format
98 * @param bool Adjust the date to the user's language?
99 *
100 * @return string Formatted date
101 */
102 function format($format, $timestamp = TIMENOW, $adjust = true)
103 {
104 if ($adjust)
105 {
106 $timestamp -= $this->offset;
107 }
108
109 return date($format, $timestamp);
110 }
111 }
112
113 /*=====================================================================*\
114 || ###################################################################
115 || # $HeadURL$
116 || # $Id$
117 || ###################################################################
118 \*=====================================================================*/
119 ?>