Added attachments support when sending mail (alfa quality).
[squirrelmail.git] / functions / date.php
CommitLineData
3302d0d4 1<?
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
aceb0d5c 12 function getMinutes($hour) {
13 $date = $hour;
14
15 if (($hour == 0) || ($hour == "00"))
16 $date = "00";
17 else if (($hour == 1) || ($hour == "01"))
18 $date = "01";
19 else if (($hour == 2) || ($hour == "02"))
20 $date = "02";
21 else if (($hour == 3) || ($hour == "03"))
22 $date = "03";
23 else if (($hour == 4) || ($hour == "04"))
24 $date = "04";
25 else if (($hour == 5) || ($hour == "05"))
26 $date = "05";
27 else if (($hour == 6) || ($hour == "06"))
28 $date = "06";
29 else if (($hour == 7) || ($hour == "07"))
30 $date = "07";
31 else if (($hour == 8) || ($hour == "08"))
32 $date = "08";
33 else if (($hour == 9) || ($hour == "09"))
34 $date = "09";
35
36 return $date;
37 }
38
0f1835f3 39 // corrects a time stamp to be the local time
40 function getGMTSeconds($stamp, $gmt) {
ddd32bad 41 if (($gmt == "Pacific") || ($gmt == "PST") || ($gmt == "PDT"))
42 $gmt = "-0800";
43 if (($gmt == "Eastern") || ($gmt == "EST") || ($gmt == "EDT"))
44 $gmt = "-0500";
45 if (($gmt == "Central") || ($gmt == "CST") || ($gmt == "CDT"))
46 $gmt = "-0600";
47 if (($gmt == "Mountain") || ($gmt == "MST") || ($gmt == "MDT"))
48 $gmt = "-0700";
49
0f1835f3 50 if (substr($gmt, 0, 1) == "-") {
51 $neg = true;
52 $gmt = substr($gmt, 1, strlen($gmt));
53 } else if (substr($gmt, 0, 1) == "+") {
54 $neg = false;
55 $gmt = substr($gmt, 1, strlen($gmt));
56 } else
57 $neg = false;
58
59 $gmt = substr($gmt, 0, 2);
60 $gmt = $gmt * 3600;
61 if ($neg == true)
62 $gmt = "-$gmt";
63 else
64 $gmt = "+$gmt";
65
66 /** now find what the server is at **/
67 $current = date("Z", time());
68
69 $stamp = (int)$stamp - (int)$gmt + (int)$current;
70
71 return $stamp;
72 }
73
3302d0d4 74 function getHour($hour) {
75 $time = explode(":", $hour);
76 return $time[0];
77 }
78
79 function getMinute($min) {
80 $time = explode(":", $min);
81 return $time[1];
82 }
83
84 function getSecond($sec) {
85 $time = explode(":", $sec);
86 return $time[2];
87 }
88
89 function getMonthNum($month) {
90 if (eregi("jan|january", $month, $tmp))
91 $date = "01";
92 else if (eregi("feb|february|febuary", $month, $tmp))
93 $date = "02";
94 else if (eregi("mar|march", $month, $tmp))
95 $date = "03";
96 else if (eregi("apr|april", $month, $tmp))
97 $date = "04";
98 else if (eregi("may", $month, $tmp))
99 $date = "05";
100 else if (eregi("jun|june", $month, $tmp))
101 $date = "06";
102 else if (eregi("jul|july", $month, $tmp))
103 $date = "07";
104 else if (eregi("aug|august", $month, $tmp))
105 $date = "08";
106 else if (eregi("sep|sept|september", $month, $tmp))
107 $date = "09";
108 else if (eregi("oct|october", $month, $tmp))
109 $date = "10";
110 else if (eregi("nov|november", $month, $tmp))
111 $date = "11";
112 else if (eregi("dec|december", $month, $tmp))
113 $date = "12";
114
115 return $date;
116 }
117
118 function getDayOfWeek($day) {
119 $date = "{WEEKDAY}";
120
121 if (eregi("(mon|monday)", $day, $tmp))
122 $date = "Mon";
123 else if (eregi("(tue|tuesday)", $day, $tmp))
124 $date = "Tue";
125 else if (eregi("(wed|wednesday)", $day, $tmp))
126 $date = "Wed";
127 else if (eregi("(thurs|thu|thursday)", $day, $tmp))
128 $date = "Thu";
129 else if (eregi("(fri|friday)", $day, $tmp))
130 $date = "Fri";
131 else if (eregi("(sat|saturday)", $day, $tmp))
132 $date = "Sat";
133 else if (eregi("(sun|sunday)", $day, $tmp))
134 $date = "Sun";
135
136 return $date;
137 }
138
139 function getDayOfMonth($day) {
140 return ereg_replace("^0", "", $day); /* remove a preceeding 0 */
141 }
142
143 function getMonth($month) {
144 $date = "{MONTH}";
145 if (eregi("jan|january", $month, $tmp))
146 $date = "Jan";
147 else if (eregi("feb|february|febuary", $month, $tmp))
148 $date = "Feb";
149 else if (eregi("mar|march", $month, $tmp))
150 $date = "Mar";
151 else if (eregi("apr|april", $month, $tmp))
152 $date = "Apr";
153 else if (eregi("may", $month, $tmp))
154 $date = "May";
155 else if (eregi("jun|june", $month, $tmp))
156 $date = "Jun";
157 else if (eregi("jul|july", $month, $tmp))
158 $date = "Jul";
159 else if (eregi("aug|august", $month, $tmp))
160 $date = "Aug";
161 else if (eregi("sep|sept|september", $month, $tmp))
162 $date = "Sep";
163 else if (eregi("oct|october", $month, $tmp))
164 $date = "Oct";
165 else if (eregi("nov|november", $month, $tmp))
166 $date = "Nov";
167 else if (eregi("dec|december", $month, $tmp))
168 $date = "Dec";
169
170 return $date;
171 }
172
173 function getYear($year) {
174 return $year;
175 }
176
0f1835f3 177 function getLongDateString($stamp) {
178 return date("D, F j, Y g:i a", $stamp);
179 }
180
181 function getDateString($stamp) {
182 return date("M j, Y", $stamp);
183 }
184
185 function getTimeStamp($dateParts) {
3302d0d4 186 /** $dateParts[0] == <day of week> Mon, Tue, Wed
187 ** $dateParts[1] == <day of month> 23
188 ** $dateParts[2] == <month> Jan, Feb, Mar
189 ** $dateParts[3] == <year> 1999
190 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
191 ** $dateParts[5] == <from GMT> +0100
192 ** $dateParts[6] == <zone> (EDT)
193 **
194 ** NOTE: In RFC 822, it states that <day of week> is optional.
195 ** In that case, dateParts[0] would be the <day of month>
196 ** and everything would be bumped up one.
197 **/
198
5b10f02a 199 if (eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp)) {
0e919368 200 $d[0] = getHour(trim($dateParts[4]));
201 $d[1] = getMinute(trim($dateParts[4]));
202 $d[2] = getSecond(trim($dateParts[4]));
203 $d[3] = getMonthNum(trim($dateParts[2]));
204 $d[4] = getDayOfMonth(trim($dateParts[1]));
205 $d[5] = getYear(trim($dateParts[3]));
0f1835f3 206 return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[5]);
5b10f02a 207 }
0e919368 208 $d[0] = getHour(trim($dateParts[3]));
209 $d[1] = getMinute(trim($dateParts[3]));
210 $d[2] = getSecond(trim($dateParts[3]));
211 $d[3] = getMonthNum(trim($dateParts[1]));
212 $d[4] = getDayOfMonth(trim($dateParts[0]));
213 $d[5] = getYear(trim($dateParts[2]));
0f1835f3 214 return getGMTSeconds(mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]), $dateParts[4]);
9774bdef 215 }
3302d0d4 216?>