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