59177427 |
1 | <?php |
3302d0d4 |
2 | /** |
a09387f4 |
3 | ** date.php |
3302d0d4 |
4 | ** |
5 | ** Takes a date and parses it into a usable format. The form that a |
6 | ** date SHOULD arrive in is: |
5b10f02a |
7 | ** <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT) |
b9bfd165 |
8 | ** (as specified in RFC 822) -- 'Tue' is optional |
3302d0d4 |
9 | ** |
245a6892 |
10 | ** $Id$ |
3302d0d4 |
11 | **/ |
12 | |
f435778e |
13 | if (defined ('date_php')) |
14 | return; |
15 | define ('date_php', true); |
16 | |
0f1835f3 |
17 | // corrects a time stamp to be the local time |
18 | function getGMTSeconds($stamp, $gmt) { |
2ed6f907 |
19 | global $invert_time; |
b9bfd165 |
20 | if (($gmt == 'Pacific') || ($gmt == 'PST')) |
21 | $gmt = '-0800'; |
22 | else if (($gmt == 'EDT')) |
23 | $gmt = '-0400'; |
24 | else if (($gmt == 'Eastern') || ($gmt == 'EST') || ($gmt == 'CDT')) |
25 | $gmt = '-0500'; |
26 | else if (($gmt == 'Central') || ($gmt == 'CST') || ($gmt == 'MDT')) |
27 | $gmt = '-0600'; |
28 | else if (($gmt == 'Mountain') || ($gmt == 'MST') || ($gmt == 'PDT')) |
29 | $gmt = '-0700'; |
30 | else if ($gmt == 'BST') |
31 | $gmt = '+0100'; |
32 | else if ($gmt == 'EET') |
33 | $gmt = '+0200'; |
34 | else if ($gmt == 'GMT') |
35 | $gmt = '+0000'; |
36 | else if ($gmt == 'HKT') |
37 | $gmt = '+0800'; |
38 | else if ($gmt == 'IST') |
39 | $gmt = '+0200'; |
40 | else if ($gmt == 'JST') |
41 | $gmt = '+0900'; |
f435778e |
42 | else if ($gmt == 'KST') |
43 | $gmt = "+0900"; |
b9bfd165 |
44 | else if ($gmt == 'MET') |
45 | $gmt = '+0100'; |
46 | else if ($gmt == 'MET DST' || $gmt == 'METDST') |
47 | $gmt = '+0200'; |
47654bfb |
48 | |
b9bfd165 |
49 | if (substr($gmt, 0, 1) == '-') { |
0f1835f3 |
50 | $neg = true; |
51 | $gmt = substr($gmt, 1, strlen($gmt)); |
b9bfd165 |
52 | } else if (substr($gmt, 0, 1) == '+') { |
0f1835f3 |
53 | $neg = false; |
54 | $gmt = substr($gmt, 1, strlen($gmt)); |
55 | } else |
56 | $neg = false; |
57 | |
58 | $gmt = substr($gmt, 0, 2); |
59 | $gmt = $gmt * 3600; |
60 | if ($neg == true) |
61 | $gmt = "-$gmt"; |
62 | else |
63 | $gmt = "+$gmt"; |
64 | |
65 | /** now find what the server is at **/ |
b9bfd165 |
66 | $current = date('Z', time()); |
d47b2518 |
67 | if ($invert_time) |
68 | $current = - $current; |
0f1835f3 |
69 | $stamp = (int)$stamp - (int)$gmt + (int)$current; |
70 | |
71 | return $stamp; |
72 | } |
73 | |
0f1835f3 |
74 | function getLongDateString($stamp) { |
b9bfd165 |
75 | return date('D, F j, Y g:i a', $stamp); |
0f1835f3 |
76 | } |
77 | |
78 | function getDateString($stamp) { |
2ed6f907 |
79 | global $invert_time; |
d68a3926 |
80 | $now = time(); |
b9bfd165 |
81 | $dateZ = date('Z', $now); |
d47b2518 |
82 | if ($invert_time) |
83 | $dateZ = - $dateZ; |
c57a3b1a |
84 | $midnight = $now - ($now % 86400) - $dateZ; |
d68a3926 |
85 | |
86 | if ($midnight < $stamp) { |
87 | // Today |
b9bfd165 |
88 | return date('g:i a', $stamp); |
069b4374 |
89 | } else if ($midnight - (60 * 60 * 24 * 6) < $stamp) { |
d68a3926 |
90 | // This week |
b9bfd165 |
91 | return date('D, g:i a', $stamp); |
d68a3926 |
92 | } else { |
93 | // before this week |
b9bfd165 |
94 | return date('M j, Y', $stamp); |
d68a3926 |
95 | } |
0f1835f3 |
96 | } |
97 | |
98 | function getTimeStamp($dateParts) { |
3302d0d4 |
99 | /** $dateParts[0] == <day of week> Mon, Tue, Wed |
100 | ** $dateParts[1] == <day of month> 23 |
101 | ** $dateParts[2] == <month> Jan, Feb, Mar |
102 | ** $dateParts[3] == <year> 1999 |
103 | ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS) |
104 | ** $dateParts[5] == <from GMT> +0100 |
105 | ** $dateParts[6] == <zone> (EDT) |
106 | ** |
107 | ** NOTE: In RFC 822, it states that <day of week> is optional. |
108 | ** In that case, dateParts[0] would be the <day of month> |
109 | ** and everything would be bumped up one. |
110 | **/ |
111 | |
d068c0ec |
112 | // Simply check to see if the first element in the dateParts |
113 | // array is an integer or not. |
5e90d34a |
114 | // Since the day of week is optional, this check is needed. |
115 | // |
b9bfd165 |
116 | // The old code used eregi('mon|tue|wed|thu|fri|sat|sun', |
d068c0ec |
117 | // $dateParts[0], $tmp) to find if the first element was the |
118 | // day of week or day of month. This is an expensive call |
119 | // (processing time) to have inside a loop. Doing it this way |
120 | // saves quite a bit of time for large mailboxes. |
5e90d34a |
121 | // |
d068c0ec |
122 | // It is also quicker to call explode only once rather than |
123 | // the 3 times it was getting called by calling the functions |
124 | // getHour, getMinute, and getSecond. |
5e90d34a |
125 | // |
126 | if (intval(trim($dateParts[0])) > 0) { |
b9bfd165 |
127 | $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' . |
128 | $dateParts[2] . ' ' . $dateParts[3]; |
fde32e3f |
129 | return getGMTSeconds(strtotime($string), $dateParts[4]); |
5b10f02a |
130 | } |
b9bfd165 |
131 | $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' . |
132 | $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4]; |
283db905 |
133 | if (isset($dateParts[5])) |
134 | return getGMTSeconds(strtotime($string), $dateParts[5]); |
135 | else |
b9bfd165 |
136 | return getGMTSeconds(strtotime($string), ''); |
5e90d34a |
137 | } |
138 | |
d068c0ec |
139 | // I use this function for profiling. Should never be called in |
140 | // actual versions of squirrelmail released to public. |
5e90d34a |
141 | function getmicrotime() { |
142 | $mtime = microtime(); |
b9bfd165 |
143 | $mtime = explode(' ',$mtime); |
5e90d34a |
144 | $mtime = $mtime[1] + $mtime[0]; |
145 | return ($mtime); |
9774bdef |
146 | } |
3302d0d4 |
147 | ?> |