5 ** Takes a date and parses it into a usable format. The form that a
6 ** date SHOULD arrive in is:
7 ** <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT)
8 ** (as specified in RFC 822) -- "Tue" is optional
12 function getMinutes($hour) {
15 if (($hour == 0) ||
($hour == "00"))
17 else if (($hour == 1) ||
($hour == "01"))
19 else if (($hour == 2) ||
($hour == "02"))
21 else if (($hour == 3) ||
($hour == "03"))
23 else if (($hour == 4) ||
($hour == "04"))
25 else if (($hour == 5) ||
($hour == "05"))
27 else if (($hour == 6) ||
($hour == "06"))
29 else if (($hour == 7) ||
($hour == "07"))
31 else if (($hour == 8) ||
($hour == "08"))
33 else if (($hour == 9) ||
($hour == "09"))
39 // corrects a time stamp to be the local time
40 function getGMTSeconds($stamp, $gmt) {
41 if (substr($gmt, 0, 1) == "-") {
43 $gmt = substr($gmt, 1, strlen($gmt));
44 } else if (substr($gmt, 0, 1) == "+") {
46 $gmt = substr($gmt, 1, strlen($gmt));
50 $gmt = substr($gmt, 0, 2);
57 /** now find what the server is at **/
58 $current = date("Z", time());
60 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
65 function getHour($hour) {
66 $time = explode(":", $hour);
70 function getMinute($min) {
71 $time = explode(":", $min);
75 function getSecond($sec) {
76 $time = explode(":", $sec);
80 function getMonthNum($month) {
81 if (eregi("jan|january", $month, $tmp))
83 else if (eregi("feb|february|febuary", $month, $tmp))
85 else if (eregi("mar|march", $month, $tmp))
87 else if (eregi("apr|april", $month, $tmp))
89 else if (eregi("may", $month, $tmp))
91 else if (eregi("jun|june", $month, $tmp))
93 else if (eregi("jul|july", $month, $tmp))
95 else if (eregi("aug|august", $month, $tmp))
97 else if (eregi("sep|sept|september", $month, $tmp))
99 else if (eregi("oct|october", $month, $tmp))
101 else if (eregi("nov|november", $month, $tmp))
103 else if (eregi("dec|december", $month, $tmp))
109 function getDayOfWeek($day) {
112 if (eregi("(mon|monday)", $day, $tmp))
114 else if (eregi("(tue|tuesday)", $day, $tmp))
116 else if (eregi("(wed|wednesday)", $day, $tmp))
118 else if (eregi("(thurs|thu|thursday)", $day, $tmp))
120 else if (eregi("(fri|friday)", $day, $tmp))
122 else if (eregi("(sat|saturday)", $day, $tmp))
124 else if (eregi("(sun|sunday)", $day, $tmp))
130 function getDayOfMonth($day) {
131 return ereg_replace("^0", "", $day); /* remove a preceeding 0 */
134 function getMonth($month) {
136 if (eregi("jan|january", $month, $tmp))
138 else if (eregi("feb|february|febuary", $month, $tmp))
140 else if (eregi("mar|march", $month, $tmp))
142 else if (eregi("apr|april", $month, $tmp))
144 else if (eregi("may", $month, $tmp))
146 else if (eregi("jun|june", $month, $tmp))
148 else if (eregi("jul|july", $month, $tmp))
150 else if (eregi("aug|august", $month, $tmp))
152 else if (eregi("sep|sept|september", $month, $tmp))
154 else if (eregi("oct|october", $month, $tmp))
156 else if (eregi("nov|november", $month, $tmp))
158 else if (eregi("dec|december", $month, $tmp))
164 function getYear($year) {
168 function getLongDateString($stamp) {
169 return date("D, F j, Y g:i a", $stamp);
172 function getDateString($stamp) {
173 return date("M j, Y", $stamp);
176 function getTimeStamp($dateParts) {
177 /** $dateParts[0] == <day of week> Mon, Tue, Wed
178 ** $dateParts[1] == <day of month> 23
179 ** $dateParts[2] == <month> Jan, Feb, Mar
180 ** $dateParts[3] == <year> 1999
181 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
182 ** $dateParts[5] == <from GMT> +0100
183 ** $dateParts[6] == <zone> (EDT)
185 ** NOTE: In RFC 822, it states that <day of week> is optional.
186 ** In that case, dateParts[0] would be the <day of month>
187 ** and everything would be bumped up one.
190 if (eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp)) {
191 $d[0] = getHour(trim($dateParts[4]));
192 $d[1] = getMinute(trim($dateParts[4]));
193 $d[2] = getSecond(trim($dateParts[4]));
194 $d[3] = getMonthNum(trim($dateParts[2]));
195 $d[4] = getDayOfMonth(trim($dateParts[1]));
196 $d[5] = getYear(trim($dateParts[3]));
197 return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[5]);
199 $d[0] = getHour(trim($dateParts[3]));
200 $d[1] = getMinute(trim($dateParts[3]));
201 $d[2] = getSecond(trim($dateParts[3]));
202 $d[3] = getMonthNum(trim($dateParts[1]));
203 $d[4] = getDayOfMonth(trim($dateParts[0]));
204 $d[5] = getYear(trim($dateParts[2]));
205 return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[4]);