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