Added sent_subfolders plugin, tweaked config stuff, other stuff.
[squirrelmail.git] / functions / date.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * date.php
5 *
6 * Copyright (c) 1999-2001 The SquirrelMail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Takes a date and parses it into a usable format. The form that a
10 * date SHOULD arrive in is:
11 * <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT)
12 * (as specified in RFC 822) -- 'Tue' is optional
13 *
14 * $Id$
15 */
16
0e4ae91a 17require_once( '../functions/constants.php' );
35586184 18
19// corrects a time stamp to be the local time
20function getGMTSeconds($stamp, $gmt) {
0e4ae91a 21 global $invert_time;
22 if (($gmt == 'Pacific') || ($gmt == 'PST')) {
23 $gmt = '-0800';
24 } else if (($gmt == 'EDT')) {
25 $gmt = '-0400';
26 } else if (($gmt == 'Eastern') || ($gmt == 'EST') || ($gmt == 'CDT')) {
27 $gmt = '-0500';
28 } else if (($gmt == 'Central') || ($gmt == 'CST') || ($gmt == 'MDT')) {
29 $gmt = '-0600';
30 } else if (($gmt == 'Mountain') || ($gmt == 'MST') || ($gmt == 'PDT')) {
31 $gmt = '-0700';
32 } else if ($gmt == 'BST') {
33 $gmt = '+0100';
34 } else if ($gmt == 'EET') {
35 $gmt = '+0200';
36 } else if ($gmt == 'GMT') {
37 $gmt = '+0000';
38 } else if ($gmt == 'HKT') {
39 $gmt = '+0800';
40 } else if ($gmt == 'IST') {
41 $gmt = '+0200';
42 } else if ($gmt == 'JST') {
43 $gmt = '+0900';
44 } else if ($gmt == 'KST') {
45 $gmt = "+0900";
46 } else if ($gmt == 'MET') {
47 $gmt = '+0100';
48 } else if ($gmt == 'MET DST' || $gmt == 'METDST') {
49 $gmt = '+0200';
50 }
51
52 if (substr($gmt, 0, 1) == '-') {
53 $neg = true;
54 $gmt = substr($gmt, 1, strlen($gmt));
55 } else if (substr($gmt, 0, 1) == '+') {
56 $neg = false;
57 $gmt = substr($gmt, 1, strlen($gmt));
58 } else {
59 $neg = false;
60 }
61
62 $gmt = substr($gmt, 0, 2);
63 $gmt = $gmt * 3600;
64 if ($neg == true) {
65 $gmt = "-$gmt";
66 } else {
67 $gmt = "+$gmt";
68 }
69
70 /** now find what the server is at **/
71 $current = date('Z', time());
72 if ($invert_time) {
73 $current = - $current;
74 }
75 $stamp = (int)$stamp - (int)$gmt + (int)$current;
76
77 return $stamp;
78}
0f1835f3 79
0e4ae91a 80/**
81 Switch system has been intentionaly choosed for the
82 internationalization of month and day names. The reason
83 is to make sure that _("") strings will go into the
84 main po.
85**/
0f1835f3 86
0e4ae91a 87function getDayName( $day_number ) {
0f1835f3 88
0e4ae91a 89 switch( $day_number ) {
90 case 0:
91 $ret = _("Sunday");
92 break;
93 case 1:
94 $ret = _("Monday");
95 break;
96 case 2:
97 $ret = _("Tuesday");
98 break;
99 case 3:
100 $ret = _("Wednesday");
101 break;
102 case 4:
103 $ret = _("Thursday");
104 break;
105 case 5:
106 $ret = _("Friday");
107 break;
108 case 6:
109 $ret = _("Saturday");
110 break;
111 default:
112 $ret = '';
113 }
114 return( $ret );
115}
d59837cf 116
0e4ae91a 117function getMonthName( $month_number ) {
118 switch( $month_number ) {
119 case '01':
120 $ret = _("January");
121 break;
122 case '02':
123 $ret = _("February");
124 break;
125 case '03':
126 $ret = _("March");
127 break;
128 case '04':
129 $ret = _("April");
130 break;
131 case '05':
132 $ret = _("May");
133 break;
134 case '06':
135 $ret = _("June");
136 break;
137 case '07':
138 $ret = _("July");
139 break;
140 case '08':
141 $ret = _("August");
142 break;
143 case '09':
144 $ret = _("September");
145 break;
146 case '10':
147 $ret = _("October");
148 break;
149 case '11':
150 $ret = _("November");
151 break;
152 case '12':
153 $ret = _("December");
154 break;
155 default:
156 $ret = '';
157 }
158 return( $ret );
159}
d59837cf 160
0e4ae91a 161function date_intl( $date_format, $stamp ) {
d59837cf 162
0e4ae91a 163 $ret = str_replace( 'D', '$1', $date_format );
164 $ret = str_replace( 'F', '$2', $ret );
165 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
166 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
167 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
168 $ret = str_replace( '$3', '', $ret );
169
170 return( $ret );
171}
d59837cf 172
0e4ae91a 173function getLongDateString( $stamp ) {
d59837cf 174
0e4ae91a 175 global $hour_format;
176
177 if ( $hour_format == SMPREF_TIME_12HR ) {
178 $date_format = _("D, F j, Y g:i a");
179 } else {
180 $date_format = _("D, F j, Y G:i");
181 }
182
183 return( date_intl( $date_format, $stamp ) );
0f1835f3 184
0e4ae91a 185}
d205a7bf 186
0e4ae91a 187function getDateString( $stamp ) {
d68a3926 188
0e4ae91a 189 global $invert_time, $hour_format;
190
191 $now = time();
192
193 $dateZ = date('Z', $now );
194 if ($invert_time) {
195 $dateZ = - $dateZ;
196 }
197 $midnight = $now - ($now % 86400) - $dateZ;
198
199 if ($midnight < $stamp) {
200 /* Today */
201 if ( $hour_format == SMPREF_TIME_12HR ) {
202 $date_format = _("g:i a");
203 } else {
204 $date_format = _("G:i");
205 }
206 } else if ($midnight - 518400 < $stamp) {
207 /* This week */
208 if ( $hour_format == SMPREF_TIME_12HR ) {
209 $date_format = _("D, g:i a");
210 } else {
211 $date_format = _("D, G:i");
212 }
213 } else {
214 /* before this week */
215 $date_format = _("M j, Y");
216 }
217
218 return( date_intl( $date_format, $stamp ) );
219}
0f1835f3 220
0e4ae91a 221function getTimeStamp($dateParts) {
222 /** $dateParts[0] == <day of week> Mon, Tue, Wed
223 ** $dateParts[1] == <day of month> 23
224 ** $dateParts[2] == <month> Jan, Feb, Mar
225 ** $dateParts[3] == <year> 1999
226 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
227 ** $dateParts[5] == <from GMT> +0100
228 ** $dateParts[6] == <zone> (EDT)
229 **
230 ** NOTE: In RFC 822, it states that <day of week> is optional.
231 ** In that case, dateParts[0] would be the <day of month>
232 ** and everything would be bumped up one.
233 **/
234
235 /*
236 * Simply check to see if the first element in the dateParts
237 * array is an integer or not.
238 * Since the day of week is optional, this check is needed.
239 *
240 * The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
241 * $dateParts[0], $tmp) to find if the first element was the
242 * day of week or day of month. This is an expensive call
243 * (processing time) to have inside a loop. Doing it this way
244 * saves quite a bit of time for large mailboxes.
245 *
246 * It is also quicker to call explode only once rather than
247 * the 3 times it was getting called by calling the functions
248 * getHour, getMinute, and getSecond.
249 */
3302d0d4 250
0e4ae91a 251 if (! isset($dateParts[1])) {
252 $dateParts[1] = '';
253 }
254 if (! isset($dateParts[2])) {
255 $dateParts[2] = '';
256 }
257 if (! isset($dateParts[3])) {
258 $dateParts[3] = '';
259 }
260 if (! isset($dateParts[4])) {
261 $dateParts[4] = '';
262 }
263 if (! isset($dateParts[5])) {
264 $dateParts[5] = '';
265 }
266 if (intval(trim($dateParts[0])) > 0) {
267 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
268 $dateParts[2] . ' ' . $dateParts[3];
269 return getGMTSeconds(strtotime($string), $dateParts[4]);
270 }
271 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
272 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
273 if (isset($dateParts[5])) {
274 return getGMTSeconds(strtotime($string), $dateParts[5]);
275 } else {
276 return getGMTSeconds(strtotime($string), '');
277 }
278}
5e90d34a 279
0e4ae91a 280/* I use this function for profiling. Should never be called in
281 actual versions of squirrelmail released to public. */
d205a7bf 282/*
5e90d34a 283 function getmicrotime() {
284 $mtime = microtime();
b9bfd165 285 $mtime = explode(' ',$mtime);
5e90d34a 286 $mtime = $mtime[1] + $mtime[0];
287 return ($mtime);
9774bdef 288 }
d205a7bf 289*/
35586184 290?>