Added "CC" to read_body.php, and rewrote the code to handle getting TO and CC
[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
12 function getHour($hour) {
13 $time = explode(":", $hour);
14 return $time[0];
15 }
16
17 function getMinute($min) {
18 $time = explode(":", $min);
19 return $time[1];
20 }
21
22 function getSecond($sec) {
23 $time = explode(":", $sec);
24 return $time[2];
25 }
26
27 function getMonthNum($month) {
28 if (eregi("jan|january", $month, $tmp))
29 $date = "01";
30 else if (eregi("feb|february|febuary", $month, $tmp))
31 $date = "02";
32 else if (eregi("mar|march", $month, $tmp))
33 $date = "03";
34 else if (eregi("apr|april", $month, $tmp))
35 $date = "04";
36 else if (eregi("may", $month, $tmp))
37 $date = "05";
38 else if (eregi("jun|june", $month, $tmp))
39 $date = "06";
40 else if (eregi("jul|july", $month, $tmp))
41 $date = "07";
42 else if (eregi("aug|august", $month, $tmp))
43 $date = "08";
44 else if (eregi("sep|sept|september", $month, $tmp))
45 $date = "09";
46 else if (eregi("oct|october", $month, $tmp))
47 $date = "10";
48 else if (eregi("nov|november", $month, $tmp))
49 $date = "11";
50 else if (eregi("dec|december", $month, $tmp))
51 $date = "12";
52
53 return $date;
54 }
55
56 function getDayOfWeek($day) {
57 $date = "{WEEKDAY}";
58
59 if (eregi("(mon|monday)", $day, $tmp))
60 $date = "Mon";
61 else if (eregi("(tue|tuesday)", $day, $tmp))
62 $date = "Tue";
63 else if (eregi("(wed|wednesday)", $day, $tmp))
64 $date = "Wed";
65 else if (eregi("(thurs|thu|thursday)", $day, $tmp))
66 $date = "Thu";
67 else if (eregi("(fri|friday)", $day, $tmp))
68 $date = "Fri";
69 else if (eregi("(sat|saturday)", $day, $tmp))
70 $date = "Sat";
71 else if (eregi("(sun|sunday)", $day, $tmp))
72 $date = "Sun";
73
74 return $date;
75 }
76
77 function getDayOfMonth($day) {
78 return ereg_replace("^0", "", $day); /* remove a preceeding 0 */
79 }
80
81 function getMonth($month) {
82 $date = "{MONTH}";
83 if (eregi("jan|january", $month, $tmp))
84 $date = "Jan";
85 else if (eregi("feb|february|febuary", $month, $tmp))
86 $date = "Feb";
87 else if (eregi("mar|march", $month, $tmp))
88 $date = "Mar";
89 else if (eregi("apr|april", $month, $tmp))
90 $date = "Apr";
91 else if (eregi("may", $month, $tmp))
92 $date = "May";
93 else if (eregi("jun|june", $month, $tmp))
94 $date = "Jun";
95 else if (eregi("jul|july", $month, $tmp))
96 $date = "Jul";
97 else if (eregi("aug|august", $month, $tmp))
98 $date = "Aug";
99 else if (eregi("sep|sept|september", $month, $tmp))
100 $date = "Sep";
101 else if (eregi("oct|october", $month, $tmp))
102 $date = "Oct";
103 else if (eregi("nov|november", $month, $tmp))
104 $date = "Nov";
105 else if (eregi("dec|december", $month, $tmp))
106 $date = "Dec";
107
108 return $date;
109 }
110
111 function getYear($year) {
112 return $year;
113 }
114
115 function getDateString($dateParts) {
116 /** $dateParts[0] == <day of week> Mon, Tue, Wed
117 ** $dateParts[1] == <day of month> 23
118 ** $dateParts[2] == <month> Jan, Feb, Mar
119 ** $dateParts[3] == <year> 1999
120 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
121 ** $dateParts[5] == <from GMT> +0100
122 ** $dateParts[6] == <zone> (EDT)
123 **
124 ** NOTE: In RFC 822, it states that <day of week> is optional.
125 ** In that case, dateParts[0] would be the <day of month>
126 ** and everything would be bumped up one.
127 **/
128
129 /* if the first part is a day */
0e919368 130 if (eregi("mon|tue|wed|thu|fri|sat|sun", trim($dateParts[0]), $tmp)) {
131 $dateParts[0] = getDayOfWeek(trim($dateParts[0]));
132 $dateParts[1] = getDayOfMonth(trim($dateParts[1]));
133 $dateParts[2] = getMonth(trim($dateParts[2]));
134 $dateParts[3] = getYear(trim($dateParts[3]));
3302d0d4 135 return "$dateParts[2] $dateParts[1], $dateParts[3]";
136 }
0e919368 137 $dateParts[0] = getDayOfMonth(trim($dateParts[0]));
138 $dateParts[1] = getMonth(trim($dateParts[1]));
139 $dateParts[2] = getYear(trim($dateParts[2]));
3302d0d4 140 return "$dateParts[1] $dateParts[0], $dateParts[2]";
141 }
142
143 function getTimeStamp($dateParts) {
5b10f02a 144 if (eregi("mon|tue|wed|thu|fri|sat|sun", $dateParts[0], $tmp)) {
0e919368 145 $d[0] = getHour(trim($dateParts[4]));
146 $d[1] = getMinute(trim($dateParts[4]));
147 $d[2] = getSecond(trim($dateParts[4]));
148 $d[3] = getMonthNum(trim($dateParts[2]));
149 $d[4] = getDayOfMonth(trim($dateParts[1]));
150 $d[5] = getYear(trim($dateParts[3]));
3302d0d4 151 return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
5b10f02a 152 }
0e919368 153 $d[0] = getHour(trim($dateParts[3]));
154 $d[1] = getMinute(trim($dateParts[3]));
155 $d[2] = getSecond(trim($dateParts[3]));
156 $d[3] = getMonthNum(trim($dateParts[1]));
157 $d[4] = getDayOfMonth(trim($dateParts[0]));
158 $d[5] = getYear(trim($dateParts[2]));
5b10f02a 159 return mktime($d[0], $d[1], $d[2], $d[3], $d[4], $d[5]);
3302d0d4 160 }
9774bdef 161
162 function getLongDateString($dateParts) {
163 if (eregi("mon|tue|wed|thu|fri|sat|sun", trim($dateParts[0]), $tmp)) {
164 $date[0] = getDayOfMonth(trim($dateParts[1]));
165 $date[1] = getMonth(trim($dateParts[2]));
166 $date[2] = getYear(trim($dateParts[3]));
167 $date[3] = getHour(trim($dateParts[4]));
168 $date[4] = getMinute(trim($dateParts[4]));
169 } else {
170 $date[0] = getDayOfMonth(trim($dateParts[0]));
171 $date[1] = getMonth(trim($dateParts[1]));
172 $date[2] = getYear(trim($dateParts[2]));
173 $date[3] = getHour(trim($dateParts[3]));
174 $date[4] = getMinute(trim($dateParts[4]));
175 }
176
177 if ($date[3] >= 12) {
178 $date[5] = "p.m.";
179 if ($date[3] >= 13)
180 $date[3] = $date[3] - 12;
181 } else {
182 $date[5] = "a.m.";
183 if ($date[3] < 1)
184 $date[3] = 12;
185 }
186
187 return "$date[1] $date[0], $date[2]&nbsp;&nbsp;&nbsp;$date[3]:$date[4] $date[5]";
188 }
3302d0d4 189?>